From fc8d1205abf18cf40719313af633c40bd7bfee00 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 06:40:20 +0000 Subject: [PATCH] Use const for immutable UI tables (#2336) --- crates/browse/src/ui/relink/badge.rs | 8 ++++---- crates/color-ui/src/ui/info.rs | 2 +- crates/color-ui/src/ui/picker/stories.rs | 2 +- crates/draw/src/ui/transform/transform_fields.rs | 4 ++-- crates/font-manager/src/panel/app.rs | 2 +- crates/font-manager/src/panel/browse.rs | 2 +- crates/font-manager/src/panel/details.rs | 2 +- crates/imaging/src/ui/scopes/panel.rs | 2 +- crates/menu/src/shortcuts/view.rs | 2 +- crates/table/src/ui/error_tag/stories.rs | 2 +- crates/text/src/ui/character.rs | 2 +- crates/ui-canvas/src/canvas/full_window_parts/stories.rs | 4 ++-- crates/ui-contract/src/contract/entry.rs | 2 +- crates/ui-contract/src/testing/icon_trials.rs | 4 ++-- crates/ui-gallery/src/chrome/card.rs | 2 +- .../ui-patterns/src/patterns/form_dialogs/new_document.rs | 2 +- crates/ui-widgets/src/controls/disclosure.rs | 6 +++--- crates/ui-widgets/src/display/spinner/stories.rs | 2 +- crates/ui-widgets/src/graph/stories.rs | 2 +- crates/ui-widgets/src/layout_components/stories.rs | 6 +++--- 20 files changed, 30 insertions(+), 30 deletions(-) diff --git a/crates/browse/src/ui/relink/badge.rs b/crates/browse/src/ui/relink/badge.rs index 8451a06ea..b1981a39d 100644 --- a/crates/browse/src/ui/relink/badge.rs +++ b/crates/browse/src/ui/relink/badge.rs @@ -34,10 +34,10 @@ enum StatusGlyph { Modified, } -static MISSING: StatusGlyph = StatusGlyph::Missing; -static UNREADABLE: StatusGlyph = StatusGlyph::Unreadable; -static REFUSED: StatusGlyph = StatusGlyph::Refused; -static MODIFIED: StatusGlyph = StatusGlyph::Modified; +const MISSING: StatusGlyph = StatusGlyph::Missing; +const UNREADABLE: StatusGlyph = StatusGlyph::Unreadable; +const REFUSED: StatusGlyph = StatusGlyph::Refused; +const MODIFIED: StatusGlyph = StatusGlyph::Modified; impl Glyph for StatusGlyph { fn paint(&self, painter: &Painter, tokens: &UiTokens, rect: Rect, _: Color32, _: bool) { diff --git a/crates/color-ui/src/ui/info.rs b/crates/color-ui/src/ui/info.rs index 46238e585..1c7d6ef4e 100644 --- a/crates/color-ui/src/ui/info.rs +++ b/crates/color-ui/src/ui/info.rs @@ -21,7 +21,7 @@ const DASH: &str = "–"; /// The grid's columns: a name and its value, twice, so that the two readouts of a line stand side by side and each /// column lines up down the grid. -static COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content, ColumnWidth::Content, ColumnWidth::Content, ColumnWidth::Content]; +const COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content, ColumnWidth::Content, ColumnWidth::Content, ColumnWidth::Content]; craft_ui::words! { /// The words of the Info panel, in the installed language unless set. diff --git a/crates/color-ui/src/ui/picker/stories.rs b/crates/color-ui/src/ui/picker/stories.rs index ca0df2461..a3302806a 100644 --- a/crates/color-ui/src/ui/picker/stories.rs +++ b/crates/color-ui/src/ui/picker/stories.rs @@ -52,7 +52,7 @@ impl ColorModel for NaiveCmyk { } } -static CMYK_MODEL: NaiveCmyk = NaiveCmyk; +const CMYK_MODEL: NaiveCmyk = NaiveCmyk; /// The picker's output with the readout of its latest event, kept in the story's data across passes. fn with_readout(data: &mut StoryData, shown: ColorPickerOutput) -> StoryOutput { diff --git a/crates/draw/src/ui/transform/transform_fields.rs b/crates/draw/src/ui/transform/transform_fields.rs index 86c62b5ad..6514371c4 100644 --- a/crates/draw/src/ui/transform/transform_fields.rs +++ b/crates/draw/src/ui/transform/transform_fields.rs @@ -359,9 +359,9 @@ struct Cells<'a> { } /// The panel form's columns: a field, the link, a field; the fields share the width. -static FIELD_COLUMNS: [ColumnWidth; 3] = [ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)]; +const FIELD_COLUMNS: [ColumnWidth; 3] = [ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)]; /// The panel form's columns with the reference point before them. -static REFERENCE_COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content, ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)]; +const REFERENCE_COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content, ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)]; /// Which form the cells show in. #[derive(Clone, Copy, PartialEq, Eq)] diff --git a/crates/font-manager/src/panel/app.rs b/crates/font-manager/src/panel/app.rs index dc92fc3af..e3feab10d 100644 --- a/crates/font-manager/src/panel/app.rs +++ b/crates/font-manager/src/panel/app.rs @@ -42,7 +42,7 @@ pub fn install_interface_fonts(ctx: &Context, language: &str, craft_faces: &[Emb } /// The filters column takes the width of its widest section; the list and toolbar take the rest. -static PANES: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::fill(1.0)]; +const PANES: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::fill(1.0)]; /// Preview downloads: at most this much per file, and this many faces in a session. const PREVIEW_LIMITS: Limits = Limits { max_file_bytes: 64 << 20, max_faces_per_file: 512, max_added_faces: 20_000 }; diff --git a/crates/font-manager/src/panel/browse.rs b/crates/font-manager/src/panel/browse.rs index d954b2c05..574b36113 100644 --- a/crates/font-manager/src/panel/browse.rs +++ b/crates/font-manager/src/panel/browse.rs @@ -159,7 +159,7 @@ impl Texts<'_> { const TABS_SHARE: f32 = 2.0; /// The search field's share of the top bar beside the tabs. const SEARCH_SHARE: f32 = 1.0; -static TOP_BAR: [ColumnWidth; 2] = [ColumnWidth::fill(TABS_SHARE), ColumnWidth::fill(SEARCH_SHARE)]; +const TOP_BAR: [ColumnWidth; 2] = [ColumnWidth::fill(TABS_SHARE), ColumnWidth::fill(SEARCH_SHARE)]; impl FontsPanel { pub(crate) fn top_bar(&mut self, ui: &mut Ui, browse: &FontsBrowseWords, format: &Format, search: Id) { diff --git a/crates/font-manager/src/panel/details.rs b/crates/font-manager/src/panel/details.rs index c47105448..f38fe36c1 100644 --- a/crates/font-manager/src/panel/details.rs +++ b/crates/font-manager/src/panel/details.rs @@ -37,7 +37,7 @@ const HERO_POINTS: f32 = 96.0; const LANGUAGES_SHOWN: usize = 60; /// The facts' labels over their values. -static FACT_COLUMNS: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::fill(1.0)]; +const FACT_COLUMNS: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::fill(1.0)]; /// The installed catalog and the preview catalog, which the faces of the two owners load from. type Catalogs = (Arc, Arc); diff --git a/crates/imaging/src/ui/scopes/panel.rs b/crates/imaging/src/ui/scopes/panel.rs index 9ef85fd14..76686ea94 100644 --- a/crates/imaging/src/ui/scopes/panel.rs +++ b/crates/imaging/src/ui/scopes/panel.rs @@ -33,7 +33,7 @@ use craft_ui::style::TypeRole; use egui::{Rect, Response, Ui, pos2}; /// The columns of the statistics grid: label and value, twice. -static STATISTICS_COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content; 4]; +const STATISTICS_COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content; 4]; /// Runs `content` in a block that resolves the dark mode when `dark`, else in the flow. fn themed(ui: &mut Ui, dark: bool, mut content: impl FnMut(&mut Ui) -> R) -> Option { diff --git a/crates/menu/src/shortcuts/view.rs b/crates/menu/src/shortcuts/view.rs index cbb4858d7..524d7566c 100644 --- a/crates/menu/src/shortcuts/view.rs +++ b/crates/menu/src/shortcuts/view.rs @@ -35,7 +35,7 @@ use crate::shortcuts::{keyboard, review, sets}; const TABLE_SHARE: f32 = 0.62; /// The detail pane's share of the width beside the table. const DETAIL_SHARE: f32 = 0.38; -static PANES: [ColumnWidth; 2] = [ColumnWidth::fill(TABLE_SHARE), ColumnWidth::fill(DETAIL_SHARE)]; +const PANES: [ColumnWidth; 2] = [ColumnWidth::fill(TABLE_SHARE), ColumnWidth::fill(DETAIL_SHARE)]; /// One frame of the dialog body. pub(crate) fn body(ui: &mut Ui, cx: &mut BodyCx<'_>, env: &mut Env<'_>, state: &mut DialogState) { diff --git a/crates/table/src/ui/error_tag/stories.rs b/crates/table/src/ui/error_tag/stories.rs index 39c295e28..1084b9e6b 100644 --- a/crates/table/src/ui/error_tag/stories.rs +++ b/crates/table/src/ui/error_tag/stories.rs @@ -6,7 +6,7 @@ use craft_ui::runtime::env::Label; use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story}; use egui::Ui; -static FIXES: [Label; 3] = [Label::Static("Convert to Number"), Label::Static("Help on this Error"), Label::Static("Ignore Error")]; +const FIXES: [Label; 3] = [Label::Static("Convert to Number"), Label::Static("Help on this Error"), Label::Static("Ignore Error")]; #[story(ErrorTag<'static>, covers = [Default], drive = Drive::Activate)] fn error_tag(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { diff --git a/crates/text/src/ui/character.rs b/crates/text/src/ui/character.rs index 4d45ed78f..34e186e24 100644 --- a/crates/text/src/ui/character.rs +++ b/crates/text/src/ui/character.rs @@ -135,7 +135,7 @@ const TRACKING_RANGE: RangeInclusive = -1000.0..=10000.0; /// The range of the scale fields, percent. const SCALE_RANGE: RangeInclusive = 0.0..=1000.0; /// Two columns of the same share, for the rows of two fields. -static TWO_COLUMNS: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::fill(1.0)]; +const TWO_COLUMNS: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::fill(1.0)]; /// The variable-font axes of the current face: what the axis sliders under the style row show. #[cfg(feature = "font-picker")] diff --git a/crates/ui-canvas/src/canvas/full_window_parts/stories.rs b/crates/ui-canvas/src/canvas/full_window_parts/stories.rs index 101de494e..dc8fe5de4 100644 --- a/crates/ui-canvas/src/canvas/full_window_parts/stories.rs +++ b/crates/ui-canvas/src/canvas/full_window_parts/stories.rs @@ -104,8 +104,8 @@ fn status_failed(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { #[story(FullWindowCanvas<'static>, covers = [], drive = Drive::Never)] fn canvas(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - static IMAGE_SOURCE: Flat = Flat { colour: Color32::from_rgb(0x4a, 0x7f, 0xc1), half: true }; - static MASK: Flat = Flat { colour: Color32::from_rgba_premultiplied(0x40, 0x00, 0x00, 0x40), half: false }; + const IMAGE_SOURCE: Flat = Flat { colour: Color32::from_rgb(0x4a, 0x7f, 0xc1), half: true }; + const MASK: Flat = Flat { colour: Color32::from_rgba_premultiplied(0x40, 0x00, 0x00, 0x40), half: false }; let checkerboard = *data.value("checkerboard", true); let overlay = *data.value("overlay", true); let tint = *data.value("tint", true); diff --git a/crates/ui-contract/src/contract/entry.rs b/crates/ui-contract/src/contract/entry.rs index 51bae9f28..dfffeaf84 100644 --- a/crates/ui-contract/src/contract/entry.rs +++ b/crates/ui-contract/src/contract/entry.rs @@ -6,7 +6,7 @@ use crate::runtime::env::Label; use craft_theme::Srgba; /// The label of a separator, which has none. -static NO_LABEL: Label = Label::Empty; +const NO_LABEL: Label = Label::Empty; /// A row of entries: an item that reports its value when picked, a heading over a group of items, or a separator /// between groups of items. diff --git a/crates/ui-contract/src/testing/icon_trials.rs b/crates/ui-contract/src/testing/icon_trials.rs index db89c9f64..27c72f843 100644 --- a/crates/ui-contract/src/testing/icon_trials.rs +++ b/crates/ui-contract/src/testing/icon_trials.rs @@ -17,8 +17,8 @@ const DISC: &[u8] = b""; -static FIRST_SET: AppIcons = AppIcons { name: "t10-first", stroke_width: None, icons: &[(FIRST_NAME, DISC), (CATALOG_NAME, DISC)] }; -static SECOND_SET: AppIcons = AppIcons { name: "t10-second", stroke_width: None, icons: &[(FIRST_NAME, SQUARE), (SECOND_NAME, SQUARE)] }; +const FIRST_SET: AppIcons = AppIcons { name: "t10-first", stroke_width: None, icons: &[(FIRST_NAME, DISC), (CATALOG_NAME, DISC)] }; +const SECOND_SET: AppIcons = AppIcons { name: "t10-second", stroke_width: None, icons: &[(FIRST_NAME, SQUARE), (SECOND_NAME, SQUARE)] }; fn icon(name: &'static str) -> Option { let tokens = style::tokens(Mode::Light, Contrast::Standard); diff --git a/crates/ui-gallery/src/chrome/card.rs b/crates/ui-gallery/src/chrome/card.rs index 9f5d56520..75754c601 100644 --- a/crates/ui-gallery/src/chrome/card.rs +++ b/crates/ui-gallery/src/chrome/card.rs @@ -123,7 +123,7 @@ pub struct CardEvents { } /// The column lists of story grids, by count. -static COLUMNS: [ColumnWidth; 4] = [ColumnWidth::fill(1.0); 4]; +const COLUMNS: [ColumnWidth; 4] = [ColumnWidth::fill(1.0); 4]; /// The columns of a form-rows card: the captions, the stories, then the values they show. The stories' column is as /// wide as its widest story, so each value sits a gap past its control, as the old gallery showed it. diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs index 95b449b17..c9b8f6745 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs @@ -377,7 +377,7 @@ impl Outcome for NewDocumentOutput { } /// The columns of the body: the cards take the room the details column leaves. -static COLUMNS: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::Content]; +const COLUMNS: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::Content]; /// The body of the dialog: the columns, then what they asked for. fn body(ui: &mut Ui, form: &mut FormCx<'_, '_>, values: &mut DocumentOptions, shared: &Shared<'_>) -> bool { diff --git a/crates/ui-widgets/src/controls/disclosure.rs b/crates/ui-widgets/src/controls/disclosure.rs index 8f306a17f..7453bdd4c 100644 --- a/crates/ui-widgets/src/controls/disclosure.rs +++ b/crates/ui-widgets/src/controls/disclosure.rs @@ -53,11 +53,11 @@ pub struct DisclosureGlyph { } /// The arrow of a field or picker. -static DROPDOWN: DisclosureGlyph = DisclosureGlyph::dropdown_form(); +const DROPDOWN: DisclosureGlyph = DisclosureGlyph::dropdown_form(); /// The arrow of a button that opens a menu. -static MENU_BUTTON: DisclosureGlyph = DisclosureGlyph { open: 1.0, form: ArrowForm::Dropdown, stroke: StrokeWidth::Medium }; +const MENU_BUTTON: DisclosureGlyph = DisclosureGlyph { open: 1.0, form: ArrowForm::Dropdown, stroke: StrokeWidth::Medium }; /// The submenu arrow. -static SUBMENU: DisclosureGlyph = DisclosureGlyph { open: 0.0, form: ArrowForm::Submenu, stroke: StrokeWidth::Thin }; +const SUBMENU: DisclosureGlyph = DisclosureGlyph { open: 0.0, form: ArrowForm::Submenu, stroke: StrokeWidth::Thin }; impl DisclosureGlyph { /// The disclosure triangle `open` of the way turned. diff --git a/crates/ui-widgets/src/display/spinner/stories.rs b/crates/ui-widgets/src/display/spinner/stories.rs index 5d8569835..ad6a865f0 100644 --- a/crates/ui-widgets/src/display/spinner/stories.rs +++ b/crates/ui-widgets/src/display/spinner/stories.rs @@ -9,7 +9,7 @@ use craft_behavior::ColumnWidth; use egui::Ui; /// The name and the spinner of each size, in two columns that fit their content. -static COLUMNS: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::Content]; +const COLUMNS: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::Content]; #[story(Spinner, covers = [Default], drive = Drive::Never)] fn spinner(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { diff --git a/crates/ui-widgets/src/graph/stories.rs b/crates/ui-widgets/src/graph/stories.rs index c644dcabb..71240217d 100644 --- a/crates/ui-widgets/src/graph/stories.rs +++ b/crates/ui-widgets/src/graph/stories.rs @@ -26,7 +26,7 @@ enum CompEdit { /// Two inputs on the left and an output on the right. struct Mix; -static MIX: Mix = Mix; +const MIX: Mix = Mix; impl NodeKind for Mix { fn title(&self) -> &str { diff --git a/crates/ui-widgets/src/layout_components/stories.rs b/crates/ui-widgets/src/layout_components/stories.rs index 50bb18891..f2f3472d5 100644 --- a/crates/ui-widgets/src/layout_components/stories.rs +++ b/crates/ui-widgets/src/layout_components/stories.rs @@ -32,14 +32,14 @@ fn stack_footer(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { outlined(ui, |ui| Stack::new().gap(Gap::Stack).pad(Pad::Regular).footer(|ui, _| words(ui, 2..3)).show(ui, |ui, _| words(ui, 0..2)).into()) } -static COLUMNS: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::Fixed(60.0)]; +const COLUMNS: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::Fixed(60.0)]; #[story(Grid, covers = [Default])] fn grid(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { outlined(ui, |ui| Grid::new(&COLUMNS).pad(Pad::Regular).show(ui, |ui, _| words(ui, 0..4)).into()) } -static FIXED: [ColumnWidth; 3] = [ColumnWidth::Content, ColumnWidth::Content, ColumnWidth::Content]; +const FIXED: [ColumnWidth; 3] = [ColumnWidth::Content, ColumnWidth::Content, ColumnWidth::Content]; /// A grid whose arrangement is fixed: in a room narrower than its columns it keeps them beside each other and /// overflows, and its second row leaves the first cell empty, so the cells after it stay in their columns. @@ -58,7 +58,7 @@ fn grid_fixed(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { }) } -static TOP: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::Content]; +const TOP: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::Content]; /// A grid whose cells stand at the top of their row: a short column of words beside a taller one starts level with it. #[story(Grid, covers = [])]