Draw stories: the brush section lookup as a method; Two artboards reports a board-name click

This commit is contained in:
aiongg
2026-11-12 14:32:49 +00:00
parent 118c58c606
commit 4bbb40a2b4
2 changed files with 14 additions and 7 deletions
+8 -4
View File
@@ -64,12 +64,16 @@ fn two_artboards(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let stage = craft_ui::testing::stage(ui);
let bounds = items.iter().fold(items[0].rect, |bounds, item| bounds.union(item.rect));
let view = craft_ui::testing::canvas_story::story_view(stage, ui.pixels_per_point(), bounds.center(), 100.0);
Canvas::new("Document").view(view).show_at(ui, stage, |ui, body| {
let shown = Canvas::new("Document").view(view).show_at(ui, stage, |ui, body| {
craft_ui::testing::canvas_story::show_document(ui, body.rect, &craft_ui::testing::canvas_story::StoryDocument::STANDARD);
let _ = Pasteboard::new("Pasteboard", &pages).show_at(ui, body.rect);
ArtboardOverlay::new("Artboards", items, selected).show_at(ui, body.rect)
let named = Pasteboard::new("Pasteboard", &pages).show_at(ui, body.rect).name_clicked.is_some();
let _ = ArtboardOverlay::new("Artboards", items, selected).show_at(ui, body.rect);
named
});
StoryOutput::default()
// A board's name is a button: its click is a click of the story.
let mut output = StoryOutput::default();
output.clicked = shown.inner.unwrap_or_default();
output
}
/// The bar for one board, whose size the story keeps: a preset, Make Portrait or Landscape, or W and H resize it.
+6 -3
View File
@@ -135,18 +135,21 @@ impl Brush {
Brush { sections: sections(on), shown: DYNAMICS, jitter: ControlRow::new(Control::PenPressure), scatter: ControlRow::new(Control::Fade) }
}
fn section(&mut self, key: u8) -> Option<&mut BrushSection<u8>> {
self.sections.iter_mut().find(|section| section.key == key)
}
/// Applies a list event as the app applies it to its brush settings.
fn apply(&mut self, event: BrushSectionEvent<u8>) {
let section = |brush: &mut Brush, key: u8| brush.sections.iter_mut().find(|section| section.key == key);
match event {
BrushSectionEvent::Select(key) => self.shown = key,
BrushSectionEvent::Enable { key, on } | BrushSectionEvent::Switch { key, on } => {
if let Some(section) = section(self, key) {
if let Some(section) = self.section(key) {
section.enabled = Some(on);
}
}
BrushSectionEvent::Lock { key, on } => {
if let Some(section) = section(self, key) {
if let Some(section) = self.section(key) {
section.locked = Some(on);
}
}