diff --git a/crates/ui-egui/src/panels/color_themes.rs b/crates/ui-egui/src/panels/color_themes.rs index 3590d70812..18a9466664 100644 --- a/crates/ui-egui/src/panels/color_themes.rs +++ b/crates/ui-egui/src/panels/color_themes.rs @@ -4,44 +4,105 @@ //! or HSB sliders), the My Themes tab lists the themes saved in the preferences (the panel //! menu's Show Find Field adds a field that lists only the themes whose names hold its text). Themes are //! saved, edited, deleted and added to Swatches as colour groups through `colorTheme.*`; the theme -//! being made is panel state. +//! being made is panel state (`ThemesUi`). -use egui::{Rect, Sense, Ui, vec2}; +// PLAN: the module paths of the craft_ui / craft_color_ui / craft_theme re-exports below follow the +// framework crates' layout (racheck-fw); none of them is imported anywhere else in the app yet. +use std::borrow::Cow; + +use craft::behavior::{DisplayOrder, IconId, ItemSource, Selection, SelectionChange}; +use craft::color_ui::ui::{ChannelRow, ChannelRule, HarmonyWheel}; +use craft::theme::Rgba; +use craft::theme::variant::Tone; +use craft_ui::buttons::IconButton; +use craft_ui::choice::{SwatchSpacing, SwatchTable}; +use craft_ui::contract::{Bind, CollectionEvent, Entry, Outcome as _, Props as _, Show as _, ShowCollection as _}; +use craft_ui::list::{List, ListRow, ThumbSize}; +use craft_ui::menu::PanelRow; +use craft_ui::notices::Notice; +use craft_ui::pickers::Select; +use craft_ui::primitives::IconSpec; +use craft_ui::runtime::commands::{CommandRef, CommandState, CommandStates}; +use craft_ui::runtime::env::Label; +use craft_ui::sections::{FooterAction, FooterBar}; +use craft_ui::tabs::{Tab, TabKind, TabStrip}; +use craft_ui::text::{HexField, TextField}; +use egui::{Rect, Ui, vec2}; use serde_json::{Value, json}; use vectorcraft_color::Color; use vectorcraft_color::harmony::{Harmony, THEME_SIZE, move_on_wheel}; use vectorcraft_engine::cmd::colortheme::ColorTheme; -use super::color::{Mode, components, from_components, track_color}; -use super::{active_paint, c32, color_json, empty_state, proxy_cmd, pstate, set_pstate}; +use super::color::{ColorPanelMode, ModelValues, color_of_values}; +use super::{active_paint, c32, color_json, proxy_cmd, srgba}; use crate::VectorcraftApp; -use crate::dialogs::recolor::slider_cell; -use crate::theme::{self, Tokens}; -use crate::widgets::{self, menu_item}; /// The rule a new theme starts with. const DEFAULT_RULE: Harmony = Harmony::Analogous2; /// The base colour before one is picked: a teal. const DEFAULT_BASE: Color = Color::Rgb { r: 0.1, g: 0.55, b: 0.6 }; -/// Diameter of the harmony wheel. -const WHEEL: f32 = 150.0; /// The color modes of the selected color's sliders, in the order the Color Mode menu lists them. -const SLIDER_MODES: [Mode; 4] = [Mode::Cmyk, Mode::Rgb, Mode::Lab, Mode::Hsb]; -/// Widths of a slider's label and of its number field (the field's width is the Recolor dialog's). -const SLIDER_LABEL_W: f32 = 12.0; -const SLIDER_FIELD_W: f32 = 48.0; +const SLIDER_MODES: [ColorPanelMode; 4] = + [ColorPanelMode::CmykSliders, ColorPanelMode::RgbSliders, ColorPanelMode::LabSliders, ColorPanelMode::HsbSliders]; +/// Colours a slider's track shows between its ends. +const TRACK_STOPS: usize = 7; + +/// The tabs, by their index in `ThemesUi::tab`. +const CREATE: usize = 0; +const MY_THEMES: usize = 1; + +/// The panel menu's and footers' commands. +const SAVE: &str = "ui.colorThemes.save"; +const ADD_TO_SWATCHES: &str = "ui.colorThemes.addToSwatches"; +const EDIT: &str = "ui.colorThemes.edit"; +const DELETE: &str = "ui.colorThemes.delete"; +const SHOW_FIND: &str = "ui.colorThemes.showFind"; +/// Starts a new theme from the current colour (a footer button of the Create tab only). +const NEW_THEME: &str = "ui.colorThemes.new"; + +/// The panel's state: the theme being made, the pick on My Themes, the tab, the find field and the +/// sliders' mode and numbers. Lives in `UiState`, so it outlasts the panel's frames. +#[derive(Clone, Debug, Default)] +pub struct ThemesUi { + pub(crate) draft: Option, + /// The saved theme picked on My Themes; see `picked`. + pub(crate) picked: Option, + /// The tab shown: `CREATE` or `MY_THEMES`. + pub(crate) tab: usize, + /// Whether the panel menu's Show Find Field shows the find field (off in a new session). + pub(crate) show_find: bool, + /// The find field's text, kept while the panel menu hides the field. + pub(crate) find: String, + /// The mode the sliders were last switched to; `None` until then. + pub(crate) mode: Option, + pub(crate) held: Option, +} + +impl ThemesUi { + /// The find field's text, trimmed and lowercased; empty while the field is hidden. + fn query(&self) -> String { + if self.show_find { self.find.trim().to_lowercase() } else { String::new() } + } + + /// Load saved theme `t` into the Create tab to edit it. + fn edit(&mut self, t: &ColorTheme) { + let rule = t.rule.as_deref().and_then(Harmony::parse); + self.draft = Some(Draft { colors: t.colors.clone(), rule, sel: 0, name: t.name.clone(), editing: Some(t.name.clone()) }); + self.tab = CREATE; + } +} /// The theme being made on the Create tab. #[derive(Clone, Debug, Default, PartialEq)] -struct Draft { - colors: Vec, +pub(crate) struct Draft { + pub(crate) colors: Vec, /// The harmony rule (`None`: Custom). - rule: Option, + pub(crate) rule: Option, /// The selected colour (the base a rule starts from). - sel: usize, - name: String, + pub(crate) sel: usize, + pub(crate) name: String, /// The saved theme being edited: Save overwrites it. - editing: Option, + pub(crate) editing: Option, } impl Draft { @@ -86,42 +147,20 @@ fn colors_json(colors: &[Color]) -> Vec { } /// The theme being made: from the current colour when the panel first shows. -fn draft(app: &VectorcraftApp, ctx: &egui::Context) -> Draft { - if let Some(d) = pstate::>(ctx, "ct-draft") { - return d; +fn draft_mut(app: &mut VectorcraftApp) -> &mut Draft { + if app.ui.color_themes_panel.draft.is_none() { + let d = Draft::new(active_paint(app).color().unwrap_or(DEFAULT_BASE), Some(DEFAULT_RULE)); + app.ui.color_themes_panel.draft = Some(d); } - let d = Draft::new(active_paint(app).color().unwrap_or(DEFAULT_BASE), Some(DEFAULT_RULE)); - set_pstate(ctx, "ct-draft", Some(d.clone())); - d + app.ui.color_themes_panel.draft.get_or_insert_with(Draft::default) } -fn set_draft(ctx: &egui::Context, d: Draft) { - set_pstate(ctx, "ct-draft", Some(d)); +fn draft(app: &mut VectorcraftApp) -> Draft { + draft_mut(app).clone() } -/// The saved theme picked on the My Themes tab, while the list shows it: a theme that the find -/// field hides stays picked, but nothing acts on it until the list shows it again. -fn picked(app: &VectorcraftApp, ctx: &egui::Context) -> Option { - let q = query(ctx); - pstate::>(ctx, "ct-picked").filter(|n| app.session.prefs.color_themes.iter().any(|t| t.name == *n && matches(&t.name, &q))) -} - -/// The My Themes find field's text, kept while the panel menu hides the field. -fn find_id() -> egui::Id { - egui::Id::unique("ct-find") -} - -/// Whether the panel menu's Show Find Field shows the find field (off in a new session). -fn show_find(ctx: &egui::Context) -> bool { - pstate(ctx, "ct-show-find") -} - -/// The find field's text, trimmed and lowercased; empty while the field is hidden. -fn query(ctx: &egui::Context) -> String { - if !show_find(ctx) { - return String::new(); - } - ctx.data(|d| d.get_temp::(find_id())).unwrap_or_default().trim().to_lowercase() +fn set_draft(app: &mut VectorcraftApp, d: Draft) { + app.ui.color_themes_panel.draft = Some(d); } /// Whether the find field lists theme `name` for `query` (trimmed and lowercased): its name holds @@ -130,105 +169,163 @@ fn matches(name: &str, query: &str) -> bool { query.is_empty() || name.to_lowercase().contains(query) } -/// The tab shown: 0 Create, 1 My Themes. -fn tab(ctx: &egui::Context) -> usize { - pstate(ctx, "ct-tab") +/// The saved themes the My Themes list shows, in their saved order: the ones the find field keeps. +fn shown_themes(app: &VectorcraftApp) -> impl Iterator { + let q = app.ui.color_themes_panel.query(); + app.session.prefs.color_themes.iter().filter(move |t| matches(&t.name, &q)) } -/// The color mode of the sliders: the one last picked from their Color Mode menu while the app -/// runs, or else the selected color's own model (HSB for a gray). Picking a mode changes no color. -fn slider_mode(ctx: &egui::Context, c: Option<&Color>) -> Mode { - pstate::>(ctx, "ct-mode").unwrap_or_else(|| match c.map(Mode::of) { - Some(m @ (Mode::Cmyk | Mode::Rgb | Mode::Lab)) => m, - _ => Mode::Hsb, +/// The saved theme picked on the My Themes tab, while the list shows it: a theme that the find +/// field hides stays picked, but nothing acts on it until the list shows it again. +fn picked(app: &VectorcraftApp) -> Option { + let name = app.ui.color_themes_panel.picked.as_ref()?; + shown_themes(app).any(|t| t.name == *name).then(|| name.clone()) +} + +/// The mode of the sliders: the one last picked from their Color Mode menu while the app runs, or +/// else the selected color's own model (HSB for a gray). Picking a mode changes no color. +fn slider_mode(picked: Option, c: &Color) -> ColorPanelMode { + picked.unwrap_or(match c { + Color::Cmyk { .. } => ColorPanelMode::CmykSliders, + Color::Rgb { .. } => ColorPanelMode::RgbSliders, + Color::Lab { .. } => ColorPanelMode::LabSliders, + _ => ColorPanelMode::HsbSliders, }) } -/// The slider values a slider edit last set: the selected place and the color they made in -/// `mode`. While those still hold, the sliders show `v` as it was set, so an edit of one slider -/// leaves the others' numbers as they were instead of converting them back from the color. +/// The slider values a slider edit last set: the selected place and the color they made. While those +/// still hold, the sliders show `values` as they were set, so an edit of one slider leaves the +/// others' numbers as they were instead of converting them back from the color. #[derive(Clone, Debug, PartialEq)] -struct Held { - sel: usize, - color: Color, - mode: Mode, - v: Vec, +pub(crate) struct Held { + pub(crate) sel: usize, + pub(crate) color: Color, + pub(crate) values: ModelValues, } -/// The numbers the sliders show for the selected color of `d` in `mode`. -fn slider_values(ctx: &egui::Context, d: &Draft, mode: Mode) -> Option> { - let c = d.colors.get(d.sel)?; - let held = - pstate::>(ctx, "ct-held").filter(|h| h.sel == d.sel && h.color == *c && h.mode == mode && h.v.len() == mode.labels().len()); - Some(held.map_or_else(|| components(mode, c), |h| h.v)) +/// The channels of `mode`: the row's letter and range, in order. +fn channels(mode: ColorPanelMode) -> &'static [(&'static str, f64, f64)] { + match mode { + ColorPanelMode::CmykSliders => &[("C", 0.0, 100.0), ("M", 0.0, 100.0), ("Y", 0.0, 100.0), ("K", 0.0, 100.0)], + ColorPanelMode::RgbSliders => &[("R", 0.0, 255.0), ("G", 0.0, 255.0), ("B", 0.0, 255.0)], + ColorPanelMode::LabSliders => &[("L", 0.0, 100.0), ("a", -128.0, 127.0), ("b", -128.0, 127.0)], + _ => &[("H", 0.0, 360.0), ("S", 0.0, 100.0), ("B", 0.0, 100.0)], + } } -/// The Color Mode menu (CMYK, RGB, Lab and HSB) and its sliders, each a rail and a number field, for -/// the selected color of `d`. An edit sets the selected color in the menu's mode (an RGB or HSB -/// edit makes it RGB, a CMYK edit CMYK and a Lab edit Lab) as the hex field does: with a rule the -/// theme follows from it as the new base. -fn sliders(ui: &mut Ui, d: &mut Draft) { - let t = Tokens::get(ui.ctx()); - let ctx = ui.ctx().clone(); - let current = slider_mode(&ctx, d.colors.get(d.sel)); - ui.horizontal(|ui| { - ui.label(egui::RichText::new(tl!("Color Mode:")).color(t.text_dim)); - let labels: Vec<&str> = SLIDER_MODES.iter().map(|m| m.label()).collect(); - if let Some(&m) = - widgets::dropdown_named(ui, "ct-mode", Some(tl!("Color Mode:")), current.label(), &labels, 90.0).and_then(|i| SLIDER_MODES.get(i)) - { - set_pstate(&ctx, "ct-mode", Some(m)); - } - }); - ui.add_space(2.0); - let mode = slider_mode(&ctx, d.colors.get(d.sel)); - let Some(comps) = slider_values(&ctx, d, mode) else { return }; - let spacing = 6.0; - let rail = (ui.available_width() - SLIDER_LABEL_W - SLIDER_FIELD_W - 2.0 * spacing - 4.0).max(40.0); - let mut set: Option> = None; - egui::Grid::new("ct-sliders").num_columns(3).spacing([spacing, 4.0]).show(ui, |ui| { - for (n, lbl) in mode.labels().iter().enumerate() { - let v = comps.get(n).copied().unwrap_or(0.0); - let shown = widgets::SliderValue::field(f64::from(v), f64::from(mode.min(n))..=f64::from(mode.max(n)), mode.suffix(n), 0); - let track = |x: f32| c32(&track_color(mode, &comps, n, x)); - if let Some(nv) = slider_cell(ui, ("ct", mode.label(), n), lbl, shown, mode.suffix(n), &track, SLIDER_LABEL_W, rail) { - let mut c2 = comps.clone(); - c2[n] = nv as f32; - set = Some(c2); +fn mode_label(mode: ColorPanelMode) -> &'static str { + match mode { + ColorPanelMode::CmykSliders => tl!("CMYK"), + ColorPanelMode::RgbSliders => tl!("RGB"), + ColorPanelMode::LabSliders => tl!("Lab"), + _ => tl!("HSB"), + } +} + +/// The titles of a strip of tabs or the rows of a list, keyed by position. +struct Names<'a>(&'a [String]); + +impl DisplayOrder for Names<'_> { + fn len(&self) -> usize { + self.0.len() + } + + fn key(&self, at: usize) -> usize { + at + } + + fn index_of(&self, key: &usize) -> Option { + (*key < self.0.len()).then_some(*key) + } + + fn text(&self, at: usize) -> Option> { + self.0.get(at).map(|name| Cow::Borrowed(name.as_str())) + } +} + +impl ItemSource for Names<'_> {} + +/// A single-choice `Select` over `labels`: the index picked this pass. +fn select(ui: &mut Ui, label: &'static str, current: usize, labels: &[&str]) -> Option { + let entries: Vec> = labels.iter().enumerate().map(|(i, l)| Entry::new(i, Label::from(*l))).collect(); + Select::new(label, Bind::given(current), &entries).show(ui).value().copied() +} + +/// The color mode menu (CMYK, RGB, Lab and HSB) and its rows, each a rail and a number field, for the +/// selected color of `d`. An edit sets the selected color in the menu's mode (an RGB or HSB edit makes +/// it RGB, a CMYK edit CMYK and a Lab edit Lab) as the hex field does: with a rule the theme follows +/// from it as the new base. +fn sliders(ui: &mut Ui, d: &mut Draft, mode_pick: &mut Option, held: &mut Option) { + let Some(color) = d.colors.get(d.sel).cloned() else { return }; + let current = slider_mode(*mode_pick, &color); + let labels: Vec<&str> = SLIDER_MODES.iter().map(|m| mode_label(*m)).collect(); + let at = SLIDER_MODES.iter().position(|m| *m == current).unwrap_or(0); + if let Some(&m) = select(ui, tl!("Color Mode:"), at, &labels).and_then(|i| SLIDER_MODES.get(i)) { + *mode_pick = Some(m); + } + let mode = slider_mode(*mode_pick, &color); + // PLAN: assumed `ModelValues { pub mode: ColorPanelMode, pub v: Vec }` and + // `ModelValues::in_mode(&Color, ColorPanelMode) -> ModelValues` (co.A1 gives only `model_values`). + let shown = held + .as_ref() + .filter(|h| h.sel == d.sel && h.color == color && h.values.mode == mode) + .map_or_else(|| ModelValues::in_mode(&color, mode), |h| h.values.clone()); + let mut set: Option = None; + for (n, &(letter, lo, hi)) in channels(mode).iter().enumerate() { + let value = shown.v.get(n).copied().unwrap_or(0.0); + let track: Vec<_> = (0..TRACK_STOPS) + .map(|i| { + let mut probe = shown.clone(); + if let Some(x) = probe.v.get_mut(n) { + *x = lo + (hi - lo) * i as f64 / (TRACK_STOPS - 1) as f64; + } + srgba(&color_of_values(&probe)) + }) + .collect(); + let rule = ChannelRule { range: lo..=hi, step: 1.0, decimals: 0 }; + let Some(row) = ChannelRow::new(letter, Bind::given(value), rule).short(letter).track(track).show(ui) else { continue }; + for event in row.events { + if let Some(&nv) = event.value().filter(|v| v.is_finite()) { + let mut next = set.take().unwrap_or_else(|| shown.clone()); + if let Some(x) = next.v.get_mut(n) { + *x = nv.clamp(lo, hi); + } + set = Some(next); } - ui.end_row(); - } - }); - if let Some(v) = set { - d.set_selected(from_components(mode, &v)); - if let Some(&color) = d.colors.get(d.sel) { - set_pstate(&ctx, "ct-held", Some(Held { sel: d.sel, color, mode, v })); } } + if let Some(values) = set { + d.set_selected(color_of_values(&values)); + if let Some(&color) = d.colors.get(d.sel) { + *held = Some(Held { sel: d.sel, color, values }); + } + } +} + +/// A colour as the hex field's value. +fn hex_rgba(c: &Color) -> Rgba { + let h = c.to_hex(); + let byte = |i: usize| h.get(i..i + 2).and_then(|s| u8::from_str_radix(s, 16).ok()).unwrap_or(0); + Rgba::rgb(byte(1), byte(3), byte(5)) } /// Save the theme being made (overwriting the theme it edits); it then edits the saved theme. -fn save(app: &mut VectorcraftApp, ctx: &egui::Context) { - let mut d = draft(app, ctx); - if let Ok(r) = app.run("colorTheme.save", d.save_params()) { +fn save(app: &mut VectorcraftApp) { + let params = draft_mut(app).save_params(); + if let Ok(r) = app.run("colorTheme.save", params) { let name = r["name"].as_str().unwrap_or_default().to_string(); - set_pstate(ctx, "ct-picked", Some(name.clone())); - d.name = name.clone(); - d.editing = Some(name); - set_draft(ctx, d); + let st = &mut app.ui.color_themes_panel; + st.picked = Some(name.clone()); + if let Some(d) = st.draft.as_mut() { + d.name = name.clone(); + d.editing = Some(name); + } } } -/// Load saved theme `t` into the Create tab to edit it. -fn edit(ctx: &egui::Context, t: &ColorTheme) { - let rule = t.rule.as_deref().and_then(Harmony::parse); - set_draft(ctx, Draft { colors: t.colors.clone(), rule, sel: 0, name: t.name.clone(), editing: Some(t.name.clone()) }); - set_pstate(ctx, "ct-tab", 0usize); -} - /// Add the theme being made to Swatches as a colour group (one undo step). -fn add_draft_to_swatches(app: &mut VectorcraftApp, ctx: &egui::Context) { - let d = draft(app, ctx); +fn add_draft_to_swatches(app: &mut VectorcraftApp) { + let d = draft(app); let name = if d.name.trim().is_empty() { "Color Theme" } else { d.name.trim() }; app.run("swatch.newGroup", json!({ "name": name, "colors": colors_json(&d.colors), "keepModel": true })).ok(); } @@ -244,255 +341,247 @@ fn set_active_color(app: &mut VectorcraftApp, d: &Draft) { } } -pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { - let ctx = ui.ctx().clone(); - ui.horizontal(|ui| { - let cur = tab(&ctx); - for (i, label) in [tl!("Create"), tl!("My Themes")].into_iter().enumerate() { - if ui.selectable_label(cur == i, egui::RichText::new(label).font(theme::semibold(12.5))).clicked() { - set_pstate(&ctx, "ct-tab", i); +/// Edit saved theme `name` on the Create tab. +fn edit_saved(app: &mut VectorcraftApp, name: &str) { + if let Some(th) = app.session.prefs.color_themes.iter().find(|t| t.name == name) { + app.ui.color_themes_panel.edit(th); + } +} + +/// Delete saved theme `name`; the theme being made no longer edits it. +fn delete(app: &mut VectorcraftApp, name: &str) { + if app.run("colorTheme.delete", json!({ "name": name })).is_ok() + && let Some(d) = app.ui.color_themes_panel.draft.as_mut().filter(|d| d.editing.as_deref() == Some(name)) + { + d.editing = None; + } +} + +/// Whether command `id` can run now: Edit, Delete and (on My Themes) Add to Swatches need a shown pick, +/// Add to Swatches a document. The menu rows and the footer buttons read this one rule. +fn enabled(app: &VectorcraftApp, id: &str) -> bool { + let pick = picked(app).is_some(); + match id { + ADD_TO_SWATCHES => app.session.active().is_some() && (app.ui.color_themes_panel.tab == CREATE || pick), + EDIT | DELETE => pick, + _ => true, + } +} + +/// The rows of the panel menu: Save Theme and Add to Swatches on Create; Edit Theme, Add to Swatches, +/// Delete Theme and Show Find Field on My Themes. +pub(crate) fn menu_rows(app: &VectorcraftApp) -> Vec { + let row = |id: &str| PanelRow::Command(CommandRef::new(id)); + if app.ui.color_themes_panel.tab == MY_THEMES { + vec![row(EDIT), row(ADD_TO_SWATCHES), row(DELETE), PanelRow::Separator, row(SHOW_FIND)] + } else { + vec![row(SAVE), row(ADD_TO_SWATCHES)] + } +} + +/// The enabled and checked state of the panel menu's rows. +pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) { + for id in [SAVE, ADD_TO_SWATCHES, EDIT, DELETE] { + states.set(CommandRef::new(id), CommandState::new().enabled(enabled(app, id))); + } + states.set(CommandRef::new(SHOW_FIND), CommandState::new().checked(app.ui.color_themes_panel.show_find)); +} + +/// Run panel command `id`; `None` when it is not this panel's. A command that is off does nothing. +pub(crate) fn run(app: &mut VectorcraftApp, id: &str, _params: &Value) -> Option> { + let known = [SAVE, ADD_TO_SWATCHES, EDIT, DELETE, SHOW_FIND, NEW_THEME]; + if !known.contains(&id) { + return None; + } + if enabled(app, id) { + let pick = picked(app); + match (id, pick) { + (SAVE, _) => save(app), + (ADD_TO_SWATCHES, _) if app.ui.color_themes_panel.tab == CREATE => add_draft_to_swatches(app), + (ADD_TO_SWATCHES, Some(n)) => { + app.run("colorTheme.addToSwatches", json!({ "name": n })).ok(); } + (EDIT, Some(n)) => edit_saved(app, &n), + (DELETE, Some(n)) => delete(app, &n), + (SHOW_FIND, _) => app.ui.color_themes_panel.show_find ^= true, + (NEW_THEME, _) => { + let rule = draft_mut(app).rule.or(Some(DEFAULT_RULE)); + set_draft(app, Draft::new(active_paint(app).color().unwrap_or(DEFAULT_BASE), rule)); + } + _ => {} } + } + Some(Ok(Value::Null)) +} + +fn icon(name: &'static str) -> IconSpec<'static> { + IconSpec::svg(IconId::new(name)) +} + +/// The footer under a tab: one action per command of `ids`, from the end edge, with `icons`; a click runs +/// the command the same way the panel menu does. +fn footer(app: &mut VectorcraftApp, ui: &mut Ui, ids: &[&str], icons: &[&'static str], labels: Vec