diff --git a/crates/ui-egui/src/ribbon/draw.rs b/crates/ui-egui/src/ribbon/draw.rs index 6a2e096bb..6fb5d9651 100644 --- a/crates/ui-egui/src/ribbon/draw.rs +++ b/crates/ui-egui/src/ribbon/draw.rs @@ -1,53 +1,55 @@ -use super::{Icon, SlideApp, Ui, big_button, big_button_ex, group, json, run}; +use super::{Icon, SlideApp, states}; +use craft::menu::ribbon::{RibbonGroup, RibbonRow}; +use craft::ui::buttons::{Arrangement, Button, ToggleButton}; +use craft::ui::contract::{Props as _, Show as _, TooltipSpec}; +use deckcraft_engine::ToolKind; +use serde_json::json; -// ---------- Draw ---------- - -// P3(ribbon-w7): rb.A4 -pub(super) fn draw_base(app: &mut SlideApp, ui: &mut Ui) { - use deckcraft_engine::ToolKind; - let cur = app.session.tool.kind.clone(); - group(ui, |ui| { - let sel = matches!(cur, ToolKind::Select); - if big_button_ex(ui, Icon::LassoSelect, "Select", true, false, sel).0.clicked() { - app.session.set_tool(ToolKind::Select); - } - let er = matches!(&cur, ToolKind::Ink { mode, .. } if mode == "eraser"); - if big_button_ex(ui, Icon::Eraser, "Eraser", true, false, er).0.clicked() { - app.session.set_tool(ToolKind::Ink { mode: "eraser".into(), color: deckcraft_color::Rgba::BLACK, width: 2.0 }); +/// Opens the drawing tools and ink conversion groups. +pub(crate) fn draw(app: &mut SlideApp, row: &mut RibbonRow<'_>) { + row.group(RibbonGroup::new("tools", "Tools", Icon::LassoSelect.id().into()), |ui| { + for (icon, label, kind) in [ + (Icon::LassoSelect, "Select", ToolKind::Select), + (Icon::Eraser, "Eraser", ToolKind::Ink { mode: "eraser".into(), color: deckcraft_color::Rgba::BLACK, width: 2.0 }), + ] { + ToggleButton::command(states::tool_ref(&kind, false)).label(label).icon(icon.id()).arrangement(Arrangement::Stacked).show(ui); } }); - group(ui, |ui| { - let pens: [(Icon, &str, &str, deckcraft_color::Rgba, f64); 5] = [ + row.group(RibbonGroup::new("pens", "Pens", Icon::Pen.id().into()), |ui| { + for (icon, label, mode, color, width) in [ (Icon::Pen, "Black Pen", "pen", deckcraft_color::Rgba::rgb(20, 20, 20), 1.5), (Icon::Pen, "Red Pen", "pen", deckcraft_color::Rgba::rgb(0xD8, 0x3F, 0x3F), 1.5), (Icon::Pen, "Blue Pen", "pen", deckcraft_color::Rgba::rgb(0x2E, 0x6F, 0xD8), 1.5), (Icon::Pencil, "Pencil", "pen", deckcraft_color::Rgba::rgb(90, 90, 90), 1.0), (Icon::HighlighterPen, "Highlighter", "highlighter", deckcraft_color::Rgba::rgb(255, 230, 0), 10.0), - ]; - for (icon, label, mode, color, width) in pens { - let on = matches!(&cur, ToolKind::Ink { mode: m, color: c, .. } if m == mode && *c == color); - if big_button_ex(ui, icon, label, true, false, on).0.clicked() { - app.session.set_tool(ToolKind::Ink { mode: mode.into(), color, width }); - } + ] { + let kind = ToolKind::Ink { mode: mode.into(), color, width }; + ToggleButton::command(states::tool_ref(&kind, false)).label(label).icon(icon.id()).arrangement(Arrangement::Stacked).show(ui); } }); - group(ui, |ui| { + row.group(RibbonGroup::new("convert", "Convert", Icon::InkToShape.id().into()), |ui| { let has_ink = app.session.doc().is_ok_and(|d| d.shapes().iter().any(|s| matches!(s.kind, deckcraft_model::ShapeKind::Ink { .. }))); - let r = big_button(ui, Icon::InkToShape, "Ink to\nShape", has_ink); - if r.on_hover_text("Ink to Shape: turn drawn lines, rectangles, ovals and triangles into shapes").clicked() { - app.session.set_tool(ToolKind::Select); - run(app, "draw.inkToShape", json!({})); + if Button::new("Ink to Shape") + .icon(Icon::InkToShape.id()) + .arrangement(Arrangement::Stacked) + .enabled(has_ink) + .tooltip(TooltipSpec::new("Ink to Shape: turn drawn lines, rectangles, ovals and triangles into shapes")) + .show(ui) + .clicked() + { + let select = states::tool_ref(&ToolKind::Select, false); + let _ = app.run(&select.id, select.params); + let _ = app.run("draw.inkToShape", json!({})); + } + for (icon, label, reason) in + [(Icon::InkToText, "Ink to Text", "Ink to Text (coming soon)"), (Icon::InkToMath, "Ink to Math", "Ink to Math (coming soon)")] + { + Button::new(label) + .icon(icon.id()) + .arrangement(Arrangement::Stacked) + .enabled(false) + .tooltip(TooltipSpec::new(label).disabled_text(reason)) + .show(ui); } - let r = big_button(ui, Icon::InkToText, "Ink to\nText", false); - let _ = r.on_hover_text("Ink to Text (coming soon)"); - let r = big_button(ui, Icon::InkToMath, "Ink to\nMath", false); - let _ = r.on_hover_text("Ink to Math (coming soon)"); }); } - -/// Opens this tab's ribbon groups. -#[allow(dead_code)] // P3(ribbon-w7): rb.A4 -pub(crate) fn draw(app: &mut SlideApp, row: &mut craft::menu::ribbon::RibbonRow<'_>) { - let _ = (app, row); - todo!("rb.A4") -} diff --git a/crates/ui-egui/src/ribbon/drawtable_tests.rs b/crates/ui-egui/src/ribbon/drawtable_tests.rs index 6dd10333e..07821f950 100644 --- a/crates/ui-egui/src/ribbon/drawtable_tests.rs +++ b/crates/ui-egui/src/ribbon/drawtable_tests.rs @@ -33,22 +33,19 @@ fn table(h: &Harness<'_, SlideApp>) -> Option<(deckcraft_model::Table, deckcraft fn draw_a_table_split_it_and_erase_the_border() { let mut s = Session::with_new(); s.execute("slide.new", &json!({"layout": "blank"})).unwrap(); - // P3(ribbon-w7): sh.A2 - let mut app = SlideApp::new_base(s, Services::default()); - app.ui.tab = "Insert".into(); - let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, + let mut h = crate::test_harness::harness_with( + s, + Services::default(), + Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0), + |_| {}, ); + h.state_mut().ui.tab = "Insert".into(); h.run_steps(3); h.get_by_label("Table").click(); h.run_steps(2); h.get_by_label("Draw Table").click(); h.run_steps(2); - let (slide, k) = (h.state().slide_rect.unwrap(), h.state().canvas_scale); + let (slide, k) = (h.state().slide_rect().unwrap(), h.state().canvas_scale()); let at = |x: f32, y: f32| slide.min + egui::vec2(x * k, y * k); drag(&mut h, at(200.0, 100.0), at(600.0, 300.0)); diff --git a/crates/ui-egui/src/ribbon/icons_popup_tests.rs b/crates/ui-egui/src/ribbon/icons_popup_tests.rs deleted file mode 100644 index cd117e1b6..000000000 --- a/crates/ui-egui/src/ribbon/icons_popup_tests.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! Insert > Icons popup (#971): clicking inside it, e.g. in the "Search icons" box, must not close it. -#![allow(clippy::expect_used)] - -use deckcraft_engine::Session; -use egui_kittest::Harness; -use egui_kittest::kittest::Queryable; - -use crate::{Services, SlideApp}; - -#[test] -fn clicking_inside_the_icons_popup_keeps_it_open() { - // P3(ribbon-w7): sh.A2 - let mut app = SlideApp::new_base(Session::with_new(), Services::default()); - app.ui.tab = "Insert".into(); - let mut h = Harness::builder().with_size(egui::vec2(1800.0, 900.0)).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, - ); - h.run_steps(3); - h.get_by_label("Icons").click(); - h.run_steps(3); - // A category heading is plain popup content, like the search box: a click on it is a click inside. - let first = deckcraft_engine::icons::icons().first().expect("the icon gallery is empty"); - h.get_by_label(first.category).click(); - h.run_steps(3); - assert!(h.query_by_label(first.category).is_some(), "the icons popup closed after a click inside it"); -} diff --git a/crates/ui-egui/src/ribbon/inktoshape_tests.rs b/crates/ui-egui/src/ribbon/inktoshape_tests.rs index 8a2c99798..d03abbf17 100644 --- a/crates/ui-egui/src/ribbon/inktoshape_tests.rs +++ b/crates/ui-egui/src/ribbon/inktoshape_tests.rs @@ -14,20 +14,17 @@ fn pen_a_rectangle_then_ink_to_shape() { let _gpu = crate::gpu_lock::gpu_lock(); let mut s = Session::with_new(); s.execute("slide.new", &json!({"layout": "blank"})).unwrap(); - // P3(ribbon-w7): sh.A2 - let mut app = SlideApp::new_base(s, Services::default()); - app.ui.tab = "Draw".into(); - let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state( - |ui, app: &mut SlideApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - app, + let mut h = crate::test_harness::harness_with( + s, + Services::default(), + Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0), + |_| {}, ); + h.state_mut().ui.tab = "Draw".into(); h.run_steps(3); h.get_by_label("Black Pen").click(); h.run_steps(2); - let (slide, k) = (h.state().slide_rect.unwrap(), h.state().canvas_scale); + let (slide, k) = (h.state().slide_rect().unwrap(), h.state().canvas_scale()); let at = |x: f32, y: f32| slide.min + egui::vec2(x * k, y * k); let corners = [(200.0, 150.0), (600.0, 150.0), (600.0, 400.0), (200.0, 400.0), (204.0, 152.0)]; h.hover_at(at(200.0, 150.0)); @@ -56,7 +53,4 @@ fn pen_a_rectangle_then_ink_to_shape() { let x = sh.xfrm.unwrap(); assert!((x.x - 200.0).abs() < 10.0 && (x.w - 400.0).abs() < 15.0 && (x.h - 250.0).abs() < 15.0, "{x:?}"); assert_eq!(st.selection.shapes, vec![sh.id]); - if let Ok(img) = h.render() { - let _ = img.save("/tmp/ink_to_shape.png"); - } } diff --git a/crates/ui-egui/src/ribbon/insert.rs b/crates/ui-egui/src/ribbon/insert.rs index e06bbee69..4cd2853eb 100644 --- a/crates/ui-egui/src/ribbon/insert.rs +++ b/crates/ui-egui/src/ribbon/insert.rs @@ -1,270 +1,262 @@ -use super::galleries::{Fl, kurbo_flatten, shapes_gallery}; -use super::home::layout_menu; +use super::galleries::{Fl, kurbo_flatten, layout_gallery, shapes_gallery}; use super::view::zoom_menu; -use super::{ - Color32, CornerRadius, Icon, Rect, Sense, SlideApp, Stroke, Tokens, Ui, big, big_button, big_button_ex, enabled, group, json, menu_item, pos2, - run, tip, vec2, -}; +use super::{Icon, SlideApp, states}; +use craft::keymap::CommandRef; +use craft::menu::ribbon::{RibbonGroup, RibbonRow}; +use craft::pages::ui::TableSizePicker; +use craft::ui::buttons::{Arrangement, Button, SplitButton, SplitMenu}; +use craft::ui::contract::{Bind, BodyCx, Entry, MemoKey, MemoProps, Props as _, Show as _, ShowContainer as _, TooltipSpec, Trigger}; +use craft::ui::display::Divider; +use craft::ui::menu::{Menu, MenuItem}; +use craft::ui::pickers::{IconPicker, IconPickerGroup, IconPickerGroups, IconPickerItem}; +use craft::ui::popover::Popover; +use craft::ui::primitives::{Glyph, IconSpec}; +use craft::ui::runtime::commands; +use craft::ui::style::UiTokens; +use deckcraft_engine::ToolKind; +use egui::{Color32, Rect, Ui, pos2}; +use serde_json::json; +use std::sync::OnceLock; -/// Photo Album is a split button: the main click starts a new album, the arrow edits one. fn photo_album_button(app: &mut SlideApp, ui: &mut Ui) { - let en = enabled(app, "insert.photoAlbum"); - let (main, arrow) = big_button_ex(ui, Icon::Picture, "Photo\nAlbum", en, true, false); - let _ = main.clone().on_hover_text(tip("insert.photoAlbum", "Photo Album…")); - main.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, en, "Photo Album…")); - if let Some(a) = &arrow { - let _ = a.clone().on_hover_text("Photo Album options"); - a.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, en, "Photo Album options")); - } - if main.clicked() { - run(app, "insert.photoAlbum", json!({})); - } - if let Some(a) = arrow { - egui::Popup::menu(&a).show(|ui| { - menu_item(app, ui, Icon::Picture, "New Photo Album…", "insert.photoAlbum", json!({})); - menu_item(app, ui, Icon::Picture, "Edit Photo Album…", "insert.photoAlbumEdit", json!({})); - }); + let entries = [ + Entry::new("insert.photoAlbum", "New Photo Album…").enabled(commands::resolve(ui.ctx(), "insert.photoAlbum").enabled), + Entry::new("insert.photoAlbumEdit", "Edit Photo Album…").enabled(commands::resolve(ui.ctx(), "insert.photoAlbumEdit").enabled), + ]; + let picked = SplitButton::command("insert.photoAlbum", SplitMenu::Entries(&entries)) + .label("Photo Album") + .icon(Icon::Picture.id()) + .arrangement(Arrangement::Stacked) + .arrow_label("Photo Album options") + .show(ui); + if let Some(id) = picked.chosen { + let _ = app.run(id, json!({})); } } -// ---------- Insert ---------- - -// P3(ribbon-w7): rb.A4 -pub(super) fn insert_base(app: &mut SlideApp, ui: &mut Ui) { - group(ui, |ui| { - let (main, arrow) = big_button_ex(ui, Icon::NewSlide, "New\nSlide", enabled(app, "slide.new"), true, false); - if main.clicked() { - run(app, "slide.new", json!({})); - } - if let Some(a) = arrow { - egui::Popup::menu(&a).width(420.0).show(|ui| layout_menu(app, ui, "slide.new")); - } +/// Opens the groups for inserting slide content. +pub(crate) fn insert(app: &mut SlideApp, row: &mut RibbonRow<'_>) { + row.group(RibbonGroup::new("slides", "Slides", Icon::NewSlide.id().into()), |ui| { + SplitButton::<()>::command("slide.new", SplitMenu::Body(Box::new(|ui, cx| layout_gallery(app, ui, cx, "slide.new")))) + .icon(Icon::NewSlide.id()) + .arrangement(Arrangement::Stacked) + .arrow_label("New Slide options") + .show(ui); }); - group(ui, |ui| { - let r = big_button(ui, Icon::Table, "Table", enabled(app, "insert.table")); - egui::Popup::menu(&r).show(|ui| { - if let Some((rr, cc)) = table_grid_picker(ui) { - run(app, "insert.table", json!({"rows": rr, "cols": cc})); - ui.close(); + row.group(RibbonGroup::new("tables", "Tables", Icon::Table.id().into()), |ui| { + let button = Button::new("Table") + .icon(Icon::Table.id()) + .arrangement(Arrangement::Stacked) + .enabled(commands::resolve(ui.ctx(), "insert.table").enabled) + .show(ui); + Menu::new("Table options").opened_by(&button.response, Trigger::Click).show(ui, |ui, cx| { + if let Some((rows, columns)) = TableSizePicker::new("Insert Table").show(ui).picked { + let _ = app.run("insert.table", json!({"rows": rows, "cols": columns})); + cx.request_close(); } - ui.separator(); - if ui.button("Insert Table…").clicked() { - app.dialog = Some(crate::dialogs::Dialog::new("table")); - ui.close(); - } - if ui.button("Draw Table").clicked() { - app.session.set_tool(deckcraft_engine::ToolKind::Shape { preset: deckcraft_engine::tools::DRAW_TABLE.into() }); - ui.close(); + Divider::horizontal().show(ui); + if MenuItem::new("Insert Table…").show(ui).ran { + app.open_dialog("table", json!({})); + cx.request_close(); } + MenuItem::command(states::tool_ref(&ToolKind::Shape { preset: deckcraft_engine::tools::DRAW_TABLE.into() }, false)) + .label("Draw Table") + .show(ui); }); }); - group(ui, |ui| { - big(app, ui, Icon::Picture, "Pictures", "app.insertPictureDialog", json!({})); + row.group(RibbonGroup::new("pictures", "Images", Icon::Picture.id().into()), |ui| { + Button::command("app.insertPictureDialog").icon(Icon::Picture.id()).arrangement(Arrangement::Stacked).show(ui); photo_album_button(app, ui); - let r = big_button(ui, Icon::Screenshot, "Screenshot", false); - let _ = r.on_hover_text("Screenshot (not available yet)"); + Button::new("Screenshot") + .icon(Icon::Screenshot.id()) + .arrangement(Arrangement::Stacked) + .enabled(false) + .tooltip(TooltipSpec::new("Screenshot").disabled_text("Screenshot (not available yet)")) + .show(ui); }); - group(ui, |ui| { - let r = big_button(ui, Icon::Shapes, "Shapes", enabled(app, "shape.insert")); - egui::Popup::menu(&r).show(|ui| { - // P3(ribbon-w7): rb.A16 - if let Some(p) = craft::ui::contract::ShowContainer::show(craft::ui::layout_components::Stack::new(), ui, |ui, cx| shapes_gallery(ui, cx)) - .inner - .flatten() - { - app.session.set_tool(deckcraft_engine::ToolKind::Shape { preset: p.to_string() }); + row.group(RibbonGroup::new("illustrations", "Illustrations", Icon::Shapes.id().into()), |ui| { + let shapes = Button::new("Shapes") + .icon(Icon::Shapes.id()) + .arrangement(Arrangement::Stacked) + .enabled(commands::resolve(ui.ctx(), "shape.insert").enabled) + .show(ui); + Menu::new("Shapes").opened_by(&shapes.response, Trigger::Click).show(ui, |ui, cx| { + if let Some(preset) = shapes_gallery(ui, cx) { + let tool = states::tool_ref(&ToolKind::Shape { preset: preset.into() }, false); + let _ = app.run(&tool.id, tool.params); + cx.request_close(); } }); - let r = big_button(ui, Icon::Icons, "Icons", enabled(app, "insert.icon")); - egui::Popup::menu(&r).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).width(340.0).show(|ui| icon_library(app, ui)); - big(app, ui, Icon::SmartArt, "Diagram", "app.dialog", json!({"id": "smartart"})); - let r = big_button(ui, Icon::Chart, "Chart", enabled(app, "insert.chart")); - egui::Popup::menu(&r).show(|ui| { - for k in chart_menu_types() { - if k.is_none() { - ui.separator(); - } - if let Some(k) = k - && ui.button(k.label()).clicked() - { - run(app, "insert.chart", json!({"type": format!("{k:?}")})); + let icons = Button::new("Icons") + .icon(Icon::Icons.id()) + .arrangement(Arrangement::Stacked) + .enabled(commands::resolve(ui.ctx(), "insert.icon").enabled) + .show(ui); + Popover::new("Icons", Bind::kept()).overlay(|overlay| overlay.opened_by(&icons.response, Trigger::Click)).show(ui, |ui, cx| { + icons_popup(app, ui, cx); + }); + Button::command(CommandRef::with_params("app.dialog", json!({"id": "smartart"}))) + .label("Diagram") + .icon(Icon::SmartArt.id()) + .arrangement(Arrangement::Stacked) + .show(ui); + let chart = Button::new("Chart") + .icon(Icon::Chart.id()) + .arrangement(Arrangement::Stacked) + .enabled(commands::resolve(ui.ctx(), "insert.chart").enabled) + .show(ui); + let entries: Vec<_> = chart_menu_types() + .into_iter() + .map(|kind| match kind { + Some(kind) => Entry::new(format!("{kind:?}"), kind.label()), + None => Entry::separator(), + }) + .collect(); + if let Some(kind) = Menu::new("Chart types").opened_by(&chart.response, Trigger::Click).pick(ui, &entries).picked { + let _ = app.run("insert.chart", json!({"type": kind})); + } + }); + row.group(RibbonGroup::new("links", "Links", Icon::Link.id().into()), |ui| { + let zoom = Button::new("Zoom") + .icon(Icon::Zoom.id()) + .arrangement(Arrangement::Stacked) + .enabled(commands::resolve(ui.ctx(), "insert.zoom").enabled) + .show(ui); + Popover::new("Zoom destinations", Bind::kept()).overlay(|overlay| overlay.opened_by(&zoom.response, Trigger::Click)).show(ui, |ui, cx| { + zoom_menu(app, ui, cx); + }); + Button::command(CommandRef::with_params("app.dialog", json!({"id": "hyperlink"}))) + .label("Link") + .icon(Icon::Link.id()) + .arrangement(Arrangement::Stacked) + .show(ui); + let action = Button::new("Action") + .icon(Icon::Action.id()) + .arrangement(Arrangement::Stacked) + .enabled(commands::resolve(ui.ctx(), "insert.actionButton").enabled) + .show(ui); + Menu::new("Action options").opened_by(&action.response, Trigger::Click).show(ui, |ui, cx| { + for kind in ["back", "forward", "beginning", "end", "home", "information", "return", "movie", "document", "sound", "help", "custom"] { + MenuItem::command(CommandRef::with_params("insert.actionButton", json!({"kind": kind}))) + .label(format!("Action Button: {kind}")) + .show(ui); + } + Divider::horizontal().show(ui); + let has_selection = app.session.active().is_some_and(|s| !s.selection.shapes.is_empty()); + if MenuItem::new("Action Settings…").enabled(has_selection).show(ui).ran { + app.open_dialog("action", json!({})); + cx.request_close(); + } + }); + }); + row.group(RibbonGroup::new("comments", "Comments", Icon::Comment.id().into()), |ui| { + Button::command(CommandRef::with_params("app.dialog", json!({"id": "comment"}))) + .label("Comment") + .icon(Icon::Comment.id()) + .arrangement(Arrangement::Stacked) + .show(ui); + }); + row.group(RibbonGroup::new("text", "Text", Icon::TextBox.id().into()), |ui| { + Button::command("insert.textBox").icon(Icon::TextBox.id()).arrangement(Arrangement::Stacked).show(ui); + Button::command(CommandRef::with_params("app.dialog", json!({"id": "headerFooter"}))) + .label("Header & Footer") + .icon(Icon::HeaderFooter.id()) + .arrangement(Arrangement::Stacked) + .show(ui); + let decorative = Button::new("Decorative Text") + .icon(Icon::WordArt.id()) + .arrangement(Arrangement::Stacked) + .enabled(commands::resolve(ui.ctx(), "insert.wordArt").enabled) + .show(ui); + Menu::new("Decorative Text styles").opened_by(&decorative.response, Trigger::Click).show(ui, |ui, _| { + for style in 0..6 { + MenuItem::command(CommandRef::with_params("insert.wordArt", json!({"style": style}))) + .label(format!("Decorative Text style {}", style + 1)) + .show(ui); + } + }); + Button::command("insert.dateTime").icon(Icon::DateTime.id()).arrangement(Arrangement::Stacked).show(ui); + Button::command("insert.slideNumber").icon(Icon::SlideNumber.id()).arrangement(Arrangement::Stacked).show(ui); + }); + row.group(RibbonGroup::new("symbols", "Symbols", Icon::Symbol.id().into()), |ui| { + for (id, icon, label) in [("equation", Icon::Equation, "Equation"), ("symbol", Icon::Symbol, "Symbol")] { + Button::command(CommandRef::with_params("app.dialog", json!({"id": id}))) + .label(label) + .icon(icon.id()) + .arrangement(Arrangement::Stacked) + .show(ui); + } + }); + row.group(RibbonGroup::new("media", "Media", Icon::Video.id().into()), |ui| { + Button::command("app.insertVideoDialog").icon(Icon::Video.id()).arrangement(Arrangement::Stacked).show(ui); + Button::command("app.insertAudioDialog").icon(Icon::Audio.id()).arrangement(Arrangement::Stacked).show(ui); + }); +} + +fn icons_popup(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) { + static GLYPHS: OnceLock> = OnceLock::new(); + let glyphs = GLYPHS.get_or_init(|| deckcraft_engine::icons::icons().iter().map(|icon| IconGlyph { name: icon.name }).collect()); + let mut groups: Vec> = Vec::new(); + for (icon, glyph) in deckcraft_engine::icons::icons().iter().zip(glyphs) { + let at = match groups.iter().position(|group| group.name == icon.category) { + Some(at) => at, + None => { + groups.push(IconPickerGroup::new(icon.category, Vec::new())); + groups.len() - 1 + } + }; + groups[at].items.push(IconPickerItem::new(icon.name, icon.label).keywords(vec![icon.label.to_lowercase()]).icon(IconSpec::glyph(glyph))); + } + if let Some(name) = + IconPicker::new("Icons", Bind::given(None), &groups).group_display(IconPickerGroups::Headings).empty("No icons match.").show(ui).picked + { + let _ = app.run("insert.icon", json!({"name": name})); + cx.request_close(); + } +} + +struct IconGlyph { + name: &'static str, +} + +impl MemoProps for IconGlyph { + fn key(&self, key: &mut MemoKey) { + key.feed_hash(&self.name); + } +} + +impl Glyph for IconGlyph { + fn paint(&self, painter: &egui::Painter, _tokens: &UiTokens, rect: Rect, color: Color32, _mirrored: bool) { + let Some(icon) = deckcraft_engine::icons::find(self.name) else { return }; + let Some(outline) = deckcraft_engine::icons::outline(self.name) else { return }; + let mut path = outline.clone(); + let view = deckcraft_engine::icons::VIEW; + path.apply_affine(deckcraft_geom::Affine::scale_non_uniform(rect.width().max(1.0) as f64 / view, rect.height().max(1.0) as f64 / view)); + let width = (rect.width() * icon.stroke as f32 / view as f32).clamp(1.0, 3.5); + let stroke_path = |points: Vec, closed: bool| { + if points.len() > 1 { + if !closed { + painter.circle_filled(points[0], width / 2.0, color); + painter.circle_filled(points[points.len() - 1], width / 2.0, color); } + painter.add(egui::Shape::Path(egui::epaint::PathShape { + points, + closed, + fill: Color32::TRANSPARENT, + stroke: egui::epaint::PathStroke::new(width, color), + })); } + }; + let mut points = Vec::new(); + kurbo_flatten(&path, |element| match element { + Fl::Move(x, y) => { + stroke_path(std::mem::take(&mut points), false); + points.push(pos2(rect.min.x + x as f32, rect.min.y + y as f32)); + } + Fl::Line(x, y) => points.push(pos2(rect.min.x + x as f32, rect.min.y + y as f32)), + Fl::Close => stroke_path(std::mem::take(&mut points), true), }); - }); - group(ui, |ui| { - let r = big_button(ui, Icon::Zoom, "Zoom", enabled(app, "insert.zoom")); - egui::Popup::menu(&r).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).width(300.0).show(|ui| zoom_menu(app, ui)); - big(app, ui, Icon::Link, "Link", "app.dialog", json!({"id": "hyperlink"})); - let r = big_button(ui, Icon::Action, "Action", enabled(app, "insert.actionButton")); - egui::Popup::menu(&r).show(|ui| { - for k in ["back", "forward", "beginning", "end", "home", "information", "return", "movie", "document", "sound", "help", "custom"] { - if ui.button(format!("Action Button: {k}")).clicked() { - run(app, "insert.actionButton", json!({"kind": k})); - } - } - ui.separator(); - let has_sel = app.session.active().is_some_and(|s| !s.selection.shapes.is_empty()); - if ui.add_enabled(has_sel, egui::Button::new("Action Settings…")).clicked() { - app.dialog = Some(crate::dialogs::Dialog::new("action")); - } - }); - }); - group(ui, |ui| { - big(app, ui, Icon::Comment, "Comment", "app.dialog", json!({"id": "comment"})); - }); - group(ui, |ui| { - big(app, ui, Icon::TextBox, "Text\nBox", "insert.textBox", json!({})); - big(app, ui, Icon::HeaderFooter, "Header &\nFooter", "app.dialog", json!({"id": "headerFooter"})); - let r = big_button(ui, Icon::WordArt, "Decorative Text", enabled(app, "insert.wordArt")); - egui::Popup::menu(&r).show(|ui| { - for i in 0..6 { - if ui.button(format!("Decorative Text style {}", i + 1)).clicked() { - run(app, "insert.wordArt", json!({"style": i})); - } - } - }); - big(app, ui, Icon::DateTime, "Date &\nTime", "insert.dateTime", json!({})); - big(app, ui, Icon::SlideNumber, "Slide\nNumber", "insert.slideNumber", json!({})); - }); - group(ui, |ui| { - big(app, ui, Icon::Equation, "Equation", "app.dialog", json!({"id": "equation"})); - big(app, ui, Icon::Symbol, "Symbol", "app.dialog", json!({"id": "symbol"})); - }); - group(ui, |ui| { - big(app, ui, Icon::Video, "Video", "app.insertVideoDialog", json!({})); - big(app, ui, Icon::Audio, "Audio", "app.insertAudioDialog", json!({})); - }); -} - -/// Hover-to-size table grid. Returns (rows, cols) when clicked. -pub fn table_grid_picker(ui: &mut Ui) -> Option<(usize, usize)> { - let t = Tokens::get(ui.ctx()); - let id = ui.scope_id().with("tgrid"); - let mut hover: (usize, usize) = ui.data_mut(|d| d.get_temp(id).unwrap_or((0, 0))); - let cell = 16.0; - let label = if hover.0 > 0 { format!("{}x{} Table", hover.1, hover.0) } else { "Insert Table".into() }; - ui.label(label); - let (rect, resp) = ui.allocate_exact_size(vec2(10.0 * (cell + 2.0), 8.0 * (cell + 2.0)), Sense::click()); - if let Some(p) = resp.hover_pos() { - let c = ((p.x - rect.min.x) / (cell + 2.0)).floor() as usize + 1; - let r = ((p.y - rect.min.y) / (cell + 2.0)).floor() as usize + 1; - hover = (r.min(8), c.min(10)); - } - for r in 0..8 { - for c in 0..10 { - let cr = Rect::from_min_size(rect.min + vec2(c as f32 * (cell + 2.0), r as f32 * (cell + 2.0)), vec2(cell, cell)); - let on = r < hover.0 && c < hover.1; - ui.painter().rect( - cr, - CornerRadius::ZERO, - if on { t.accent.gamma_multiply(0.3) } else { t.card }, - Stroke::new(1.0, if on { t.accent } else { t.border }), - egui::StrokeKind::Inside, - ); - } - } - ui.data_mut(|d| d.insert_temp(id, hover)); - if resp.clicked() && hover.0 > 0 { Some(hover) } else { None } -} - -fn render_icon_categories(app: &mut SlideApp, ui: &mut Ui, icons: &[deckcraft_engine::icons::Icon], color: Color32, hover: Color32) { - let mut cats: Vec<&str> = Vec::new(); - for icon in icons { - if !cats.contains(&icon.category) { - cats.push(icon.category); - } - } - for cat in cats { - ui.label(egui::RichText::new(cat).small().strong()); - ui.horizontal_wrapped(|ui| { - for icon in icons.iter().filter(|i| i.category == cat) { - icon_cell(app, ui, icon, color, hover); - } - }); - } -} - -fn render_filtered_icons(app: &mut SlideApp, ui: &mut Ui, icons: &[deckcraft_engine::icons::Icon], q: &str, color: Color32, hover: Color32) { - let mut n = 0; - ui.horizontal_wrapped(|ui| { - for icon in icons { - if icon.name.contains(q) || icon.label.to_lowercase().contains(q) { - icon_cell(app, ui, icon, color, hover); - n += 1; - } - } - }); - if n == 0 { - ui.label("No icons match."); - } -} - -/// Lucide stroke icons (Insert › Icons). Search filters the gallery; a click inserts the outline. -fn icon_library(app: &mut SlideApp, ui: &mut Ui) { - let t = Tokens::get(ui.ctx()); - let (color, hover) = (t.text, t.hover); - let id = ui.scope_id().with("icon-query"); - let mut query = ui.data_mut(|d| d.get_temp::(id).unwrap_or_default()); - ui.add(egui::TextEdit::singleline(&mut query).hint_text("Search icons").desired_width(ui.available_width())); - let q = query.trim().to_lowercase(); - ui.data_mut(|d| d.insert_temp(id, query)); - let icons = deckcraft_engine::icons::icons(); - egui::ScrollArea::vertical().id_salt("icon-scroll").max_height(420.0).show(ui, |ui| { - if q.is_empty() { - render_icon_categories(app, ui, icons, color, hover); - } else { - render_filtered_icons(app, ui, icons, &q, color, hover); - } - }); -} - -fn icon_cell(app: &mut SlideApp, ui: &mut Ui, icon: &deckcraft_engine::icons::Icon, color: Color32, hover: Color32) { - let (r, resp) = ui.allocate_exact_size(vec2(36.0, 36.0), Sense::click()); - if resp.hovered() { - ui.painter().rect_filled(r, CornerRadius::same(4), hover); - } - paint_icon(ui.painter(), r.shrink(6.0), icon, color); - if resp.on_hover_text(icon.label).clicked() { - let _ = app.run("insert.icon", json!({"name": icon.name})); - ui.close(); - } -} - -/// Stroke a Lucide outline into a gallery cell. The line is the design stroke scaled to the cell. -fn paint_icon(p: &egui::Painter, r: Rect, icon: &deckcraft_engine::icons::Icon, color: Color32) { - let Some(src) = deckcraft_engine::icons::outline(icon.name) else { return }; - let mut bp = src.clone(); - let (w, h) = (r.width().max(1.0) as f64, r.height().max(1.0) as f64); - bp.apply_affine(deckcraft_geom::Affine::scale_non_uniform(w / deckcraft_engine::icons::VIEW, h / deckcraft_engine::icons::VIEW)); - let sw = ((r.width() * icon.stroke as f32) / deckcraft_engine::icons::VIEW as f32).clamp(1.0, 3.5); - let mut pts: Vec = vec![]; - let mut polys: Vec<(Vec, bool)> = vec![]; - kurbo_flatten(&bp, |el| match el { - Fl::Move(x, y) => { - if pts.len() > 1 { - polys.push((std::mem::take(&mut pts), false)); - } - pts.clear(); - pts.push(pos2(r.min.x + x as f32, r.min.y + y as f32)); - } - Fl::Line(x, y) => pts.push(pos2(r.min.x + x as f32, r.min.y + y as f32)), - Fl::Close => { - if pts.len() > 1 { - polys.push((std::mem::take(&mut pts), true)); - } - } - }); - if pts.len() > 1 { - polys.push((pts, false)); - } - for (poly, closed) in polys { - p.add(egui::Shape::Path(egui::epaint::PathShape { - points: poly, - closed, - fill: Color32::TRANSPARENT, - stroke: egui::epaint::PathStroke::new(sw, color), - })); + stroke_path(points, false); } } @@ -278,9 +270,3 @@ pub(super) fn chart_menu_types() -> Vec) { - let _ = (app, row); - todo!("rb.A4") -} diff --git a/crates/ui-egui/src/ribbon/view.rs b/crates/ui-egui/src/ribbon/view.rs index f3492ad37..7bbc20d14 100644 --- a/crates/ui-egui/src/ribbon/view.rs +++ b/crates/ui-egui/src/ribbon/view.rs @@ -1,171 +1,133 @@ -use super::{Icon, SlideApp, Target, Ui, big_button, big_button_ex, group, json, rows, run, theme}; +use super::{Icon, SlideApp}; +use crate::state; +use craft::keymap::CommandRef; +use craft::menu::ribbon::{RibbonGroup, RibbonRow}; +use craft::ui::buttons::{Arrangement, Button, SplitButton, SplitMenu, ToggleButton}; +use craft::ui::choice::{Checkbox, Segmented}; +use craft::ui::contract::{Bind, BodyCx, Entry, Props as _, Show as _, ShowContainer as _, TooltipSpec}; +use craft::ui::display::{Divider, Text}; +use craft::ui::layout_components::Stack; +use egui::Ui; +use serde_json::json; -// P3(ribbon-w7): rb.A4 -pub(super) fn view_base(app: &mut SlideApp, ui: &mut Ui) { - use crate::ViewMode; - group(ui, |ui| { - for (icon, label, id, mode) in [ - (Icon::ViewNormal, "Normal", "view.normal", Some(ViewMode::Normal)), - (Icon::ViewOutline, "Outline\nView", "view.outline", Some(ViewMode::Outline)), - (Icon::ViewSorter, "Slide\nSorter", "view.sorter", Some(ViewMode::Sorter)), - (Icon::ViewNotesPage, "Notes\nPage", "view.notesPage", Some(ViewMode::NotesPage)), - (Icon::ViewReading, "Reading\nView", "view.reading", None), - ] { - let sel = mode.is_some_and(|m| app.ui.view == m); - if big_button_ex(ui, icon, label, true, false, sel).0.clicked() { - let _ = app.run(id, json!({})); - } - } - }); - group(ui, |ui| { - let in_master = app.session.active().is_some_and(|d| d.selection.target != Target::Slides); - if big_button_ex(ui, Icon::SlideMaster, "Slide\nMaster", true, false, in_master).0.clicked() { - let _ = app.run(if in_master { "view.closeMaster" } else { "view.slideMaster" }, json!({})); - } - let in_handout = app.session.active().is_some_and(|d| d.selection.target == Target::Handout); - if big_button_ex(ui, Icon::HandoutMaster, "Handout\nMaster", true, false, in_handout).0.clicked() { - let _ = app.run(if in_handout { "view.closeMaster" } else { "view.handoutMaster" }, json!({})); - } - let in_notes = app.session.active().is_some_and(|d| d.selection.target == Target::NotesMaster); - if big_button_ex(ui, Icon::NotesMaster, "Notes\nMaster", true, false, in_notes).0.clicked() { - let _ = app.run(if in_notes { "view.closeMaster" } else { "view.notesMaster" }, json!({})); - } - }); - group(ui, |ui| { - rows(ui, |ui| { - let mut r = app.ui.ruler; - if ui.checkbox(&mut r, "Ruler").changed() { - app.ui.ruler = r; - } - let mut g = app.ui.gridlines; - if ui.checkbox(&mut g, "Gridlines").changed() { - app.ui.gridlines = g; - } - let mut gd = app.ui.guides; - if ui.checkbox(&mut gd, "Guides").changed() { - app.ui.guides = gd; - } - }); - if big_button(ui, Icon::Gridlines, "Grid\nOptions", true).clicked() { - let _ = app.run("view.gridOptions", json!({})); - } - let n = app.ui.notes; - if big_button_ex(ui, Icon::Notes, "Notes", true, false, n).0.clicked() { - app.ui.notes = !n; - } - }); - group(ui, |ui| { - let (main, arrow) = big_button_ex(ui, Icon::ZoomGlass, "Zoom", true, true, false); - if main.on_hover_text("Zoom").clicked() { - let _ = app.run("view.zoomDialog", json!({})); - } - if let Some(a) = arrow { - egui::Popup::menu(&a).show(|ui| { - for pct in [400, 200, 150, 100, 75, 66, 50, 33] { - if ui.button(format!("{pct}%")).clicked() { - let _ = app.run("view.zoom", json!({"percent": pct})); - ui.close(); - } - } - if ui.button("Fit").clicked() { - let _ = app.run("view.fit", json!({})); - ui.close(); - } - }); - } - if big_button(ui, Icon::FitToWindow, "Fit to\nWindow", true).clicked() { - app.ui.zoom = None; - } - }); - group(ui, |ui| { - let has = app.session.active().is_some(); - let on = app.doc_window.is_some(); - let resp = big_button_ex(ui, Icon::NewWindow, "New\nWindow", has, false, on).0; - if resp.on_hover_text("Open another window on this presentation").clicked() { - let _ = app.run("view.newWindow", json!({})); - } - }); - group(ui, |ui| { - let gs = app.ui.grayscale; - if big_button_ex(ui, Icon::Grayscale, "Grayscale", true, false, gs).0.clicked() { - app.ui.grayscale = !gs; - } - let dark = app.ui.brightness == theme::Brightness::Dark; - if big_button_ex(ui, Icon::Palette, "Dark\nMode", true, false, dark).0.clicked() { - let _ = app.run("view.dark", json!({})); - } - }); -} - -/// Insert › Zoom: pick Summary, Section or Slide Zoom and what it zooms to, as PowerPoint's -/// Insert Zoom dialogs do (a checklist of slides or sections). -pub(super) fn zoom_menu(app: &mut SlideApp, ui: &mut Ui) { - let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return }; - let id = egui::Id::unique("insert_zoom_menu"); - let (mut kind, mut picked): (u8, Vec) = ui.data_mut(|d| d.get_temp(id).unwrap_or((0, vec![]))); - ui.horizontal(|ui| { - for (k, label) in [(0u8, "Slide Zoom"), (1, "Section Zoom"), (2, "Summary Zoom")] { - if ui.selectable_label(kind == k, label).clicked() && kind != k { - kind = k; - picked.clear(); - } - } - }); - ui.separator(); - let items: Vec = if kind == 1 { - doc.sections.iter().map(|s| s.name.clone()).collect() - } else { - doc.slides - .iter() - .enumerate() - .map(|(i, s)| { - let t = s.title(); - format!("{}. {}", i + 1, t.lines().next().unwrap_or("").trim()) - }) - .collect() - }; - if items.is_empty() { - ui.label(if kind == 1 { "The presentation has no sections. Add one with Home › Section." } else { "No slides." }); - } - egui::ScrollArea::vertical().max_height(260.0).show(ui, |ui| { - for (i, label) in items.iter().enumerate() { - let mut on = picked.contains(&i); - if ui.checkbox(&mut on, label).changed() { - if on { - picked.push(i); - } else { - picked.retain(|x| *x != i); - } - } - } - }); - ui.data_mut(|d| d.insert_temp(id, (kind, picked.clone()))); - ui.separator(); - if ui.add_enabled(!picked.is_empty(), egui::Button::new("Insert")).clicked() { - let mut v = picked.clone(); - v.sort_unstable(); - let p = match kind { - 1 => json!({"kind": "section", "sections": v}), - 2 => json!({"kind": "summary", "slides": v}), - _ => json!({"kind": "slide", "slides": v}), - }; - run(app, "insert.zoom", p); - ui.data_mut(|d| d.remove::<(u8, Vec)>(id)); - ui.close(); - } -} - -/// Unsaved ribbon zoom selection. -#[allow(dead_code)] // P3(ribbon-w7): rb.A15 +/// The unsaved choices in the Insert Zoom popup. #[derive(Default)] pub(crate) struct ZoomPick { kind: u8, picked: Vec, } -/// Opens this tab's ribbon groups. -#[allow(dead_code)] // P3(ribbon-w7): rb.A4 -pub(crate) fn view(app: &mut SlideApp, row: &mut craft::menu::ribbon::RibbonRow<'_>) { - let _ = (app, row); - todo!("rb.A4") +/// Opens the presentation view and display groups. +pub(crate) fn view(app: &mut SlideApp, row: &mut RibbonRow<'_>) { + row.group(RibbonGroup::new("views", "Presentation Views", Icon::ViewNormal.id().into()), |ui| { + for (icon, id) in [ + (Icon::ViewNormal, "view.normal"), + (Icon::ViewOutline, "view.outline"), + (Icon::ViewSorter, "view.sorter"), + (Icon::ViewNotesPage, "view.notesPage"), + ] { + ToggleButton::command(id).icon(icon.id()).arrangement(Arrangement::Stacked).show(ui); + } + Button::command("view.reading").icon(Icon::ViewReading.id()).arrangement(Arrangement::Stacked).show(ui); + }); + row.group(RibbonGroup::new("masters", "Master Views", Icon::SlideMaster.id().into()), |ui| { + for (icon, id) in + [(Icon::SlideMaster, "view.slideMaster"), (Icon::HandoutMaster, "view.handoutMaster"), (Icon::NotesMaster, "view.notesMaster")] + { + ToggleButton::command(CommandRef::with_params(id, json!({"toggle": true}))).icon(icon.id()).arrangement(Arrangement::Stacked).show(ui); + } + }); + row.group(RibbonGroup::new("show", "Show", Icon::Gridlines.id().into()), |ui| { + Stack::new().show(ui, |ui, _| { + Checkbox::new(Bind::given(app.ui.ruler)).command("view.ruler").show(ui); + Checkbox::new(Bind::given(app.ui.gridlines)).command("view.gridlines").show(ui); + Checkbox::new(Bind::given(app.ui.guides)).command("view.guides").show(ui); + }); + Button::command("view.gridOptions").icon(Icon::Gridlines.id()).arrangement(Arrangement::Stacked).show(ui); + ToggleButton::command("view.notes").icon(Icon::Notes.id()).arrangement(Arrangement::Stacked).show(ui); + }); + row.group(RibbonGroup::new("zoom", "Zoom", Icon::ZoomGlass.id().into()), |ui| { + let mut entries: Vec>> = + [400, 200, 150, 100, 75, 66, 50, 33].into_iter().map(|pct| Entry::new(Some(pct), format!("{pct}%"))).collect(); + entries.push(Entry::new(None, "Fit")); + let picked = SplitButton::command("view.zoomDialog", SplitMenu::Entries(&entries)) + .arrow_label("Zoom options") + .icon(Icon::ZoomGlass.id()) + .arrangement(Arrangement::Stacked) + .show(ui); + if let Some(percent) = picked.chosen { + match percent { + Some(percent) => { + let _ = app.run("view.zoom", json!({"percent": percent})); + } + None => { + let _ = app.run("view.fit", json!({})); + } + } + } + Button::command("view.fit").label("Fit to Window").icon(Icon::FitToWindow.id()).arrangement(Arrangement::Stacked).show(ui); + }); + row.group(RibbonGroup::new("window", "Window", Icon::NewWindow.id().into()), |ui| { + ToggleButton::command("view.newWindow") + .icon(Icon::NewWindow.id()) + .arrangement(Arrangement::Stacked) + .enabled(app.session.active().is_some()) + .tooltip(TooltipSpec::new("Open another window on this presentation")) + .show(ui); + }); + row.group(RibbonGroup::new("appearance", "Appearance", Icon::Palette.id().into()), |ui| { + ToggleButton::command("view.grayscale").icon(Icon::Grayscale.id()).arrangement(Arrangement::Stacked).show(ui); + let dark = app.ui.brightness == state::Brightness::Dark; + ToggleButton::new("Dark Mode", Bind::given(dark)).command("view.dark").icon(Icon::Palette.id()).arrangement(Arrangement::Stacked).show(ui); + }); +} + +/// Chooses slide or section destinations for an inserted zoom. +pub(super) fn zoom_menu(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) { + let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return }; + let entries = [Entry::new(0u8, "Slide Zoom"), Entry::new(1, "Section Zoom"), Entry::new(2, "Summary Zoom")]; + let previous = app.insert_zoom.kind; + Segmented::new("Zoom kind", Bind::bound(&mut app.insert_zoom.kind), &entries).show(ui); + if previous != app.insert_zoom.kind { + app.insert_zoom.picked.clear(); + } + Divider::horizontal().show(ui); + let items: Vec = if app.insert_zoom.kind == 1 { + doc.sections.iter().map(|s| s.name.clone()).collect() + } else { + doc.slides.iter().enumerate().map(|(i, s)| format!("{}. {}", i + 1, s.title().lines().next().unwrap_or("").trim())).collect() + }; + if items.is_empty() { + Text::new(if app.insert_zoom.kind == 1 { "The presentation has no sections. Add one with Home › Section." } else { "No slides." }).show(ui); + } + egui::ScrollArea::vertical().max_height(260.0).show(ui, |ui| { + Stack::new().show(ui, |ui, _| { + for (i, label) in items.iter().enumerate() { + let was = app.insert_zoom.picked.contains(&i); + let mut on = was; + Checkbox::new(Bind::bound(&mut on)).label(label.as_str()).show(ui); + if on != was { + if on { + app.insert_zoom.picked.push(i); + } else { + app.insert_zoom.picked.retain(|picked| *picked != i); + } + } + } + }); + }); + Divider::horizontal().show(ui); + + if Button::new("Insert").enabled(!app.insert_zoom.picked.is_empty()).show(ui).clicked() { + let mut picked = app.insert_zoom.picked.clone(); + picked.sort_unstable(); + let params = match app.insert_zoom.kind { + 1 => json!({"kind": "section", "sections": picked}), + 2 => json!({"kind": "summary", "slides": picked}), + _ => json!({"kind": "slide", "slides": picked}), + }; + let _ = app.run("insert.zoom", params); + app.insert_zoom = ZoomPick::default(); + cx.request_close(); + } }