mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-20 01:21:48 +01:00
Use const for immutable UI tables (#2336)
This commit is contained in:
1 parent
98b1810f8f
commit
fc8d1205ab
20 files changed
+30
-30
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<Catalog>, Arc<Catalog>);
|
||||
|
||||
@@ -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<R>(ui: &mut Ui, dark: bool, mut content: impl FnMut(&mut Ui) -> R) -> Option<R> {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -135,7 +135,7 @@ const TRACKING_RANGE: RangeInclusive<f64> = -1000.0..=10000.0;
|
||||
/// The range of the scale fields, percent.
|
||||
const SCALE_RANGE: RangeInclusive<f64> = 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")]
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -17,8 +17,8 @@ const DISC: &[u8] = b"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24
|
||||
const SQUARE: &[u8] =
|
||||
b"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" fill=\"black\"/></svg>";
|
||||
|
||||
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<SvgIcon> {
|
||||
let tokens = style::tokens(Mode::Light, Contrast::Standard);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<E: 'static> NodeKind<E> for Mix {
|
||||
fn title(&self) -> &str {
|
||||
|
||||
@@ -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 = [])]
|
||||
|
||||
Reference in new issue
Block a user