From 40a4a664b3501a626b4b8f428524e976d21b79ac Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 13 Nov 2026 15:24:16 +0100 Subject: [PATCH] Add SOTV Foxified Dark and Corporate Light themes --- crates/midra-layout/src/format_ui.rs | 6 +- crates/midra-layout/src/gui.rs | 251 +++++++++++++++++---------- crates/midra-layout/src/main.rs | 30 +++- crates/midra-layout/src/menu_ui.rs | 37 ++++ crates/midra-layout/src/theme.rs | 121 +++++++++++++ docs/midra-layout.md | 17 ++ 6 files changed, 362 insertions(+), 100 deletions(-) create mode 100644 crates/midra-layout/src/theme.rs diff --git a/crates/midra-layout/src/format_ui.rs b/crates/midra-layout/src/format_ui.rs index a70a992..6a8cb18 100644 --- a/crates/midra-layout/src/format_ui.rs +++ b/crates/midra-layout/src/format_ui.rs @@ -150,7 +150,7 @@ impl Editor { if apply_button(ui,"Apply output resolution", d.size != self.layout.formats().output.map(f64::from)).clicked() { match midra_layout::formats::resolution_from_values(d.size).and_then(|size|self.layout.set_output(size)) { Ok(())=>{ self.zoom=1.0;self.pan=Vec2::ZERO;self.sync(); d.error.clear(); },Err(e)=>d.error=e } } - if !d.error.is_empty() { ui.colored_label(AMBER,&d.error); } + if !d.error.is_empty() { ui.colored_label(theme::palette(ui.ctx()).amber,&d.error); } ui.separator(); ui.label("Viewport camera (does not change layer or crop geometry)"); ui.horizontal(|ui| { @@ -242,7 +242,7 @@ impl Editor { let reviewed=if input_matches {geometry.and_then(|geometry|preview.configure(i,d.source_id,d.source,geometry,true))} else {Err("Input resolution is invalid or does not match the crop edges.".into())}; match &reviewed { Ok(message) if !message.is_empty()=>{ ui.label(message); }, - Err(e)=>{ ui.colored_label(AMBER,e); }, + Err(e)=>{ ui.colored_label(theme::palette(ui.ctx()).amber,e); }, _=>{} } let pending = d.source_id != self.layout.formats().source_for[i] @@ -287,7 +287,7 @@ impl Editor { paint_pattern(ui.painter(),preview_rect,self.layout.formats().sources[self.layout.formats().source_for[i]],self.layout.formats().advanced[i]); ui.label("Source test pattern only; the screen reference image is not source content."); } - if !d.error.is_empty() {ui.colored_label(AMBER,&d.error);} + if !d.error.is_empty() {ui.colored_label(theme::palette(ui.ctx()).amber,&d.error);} ui.collapsing("Calculated crops / provisional WebRCS mapping",|ui| { if let Ok(report)=self.layout.calculation_report(i) { ui.label(&report); diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index f8b6ba5..4369693 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -238,6 +238,7 @@ impl Editor { } } fn reference_window(&mut self, ctx: &egui::Context) { + let palette = theme::palette(ctx); let mut open = self.reference_open; egui::Window::new("Reference image") .open(&mut open) @@ -267,7 +268,14 @@ impl Editor { ); if let Some((severe, warning)) = reference.warning(self.layout.formats().output) { - ui.colored_label(if severe { Color32::LIGHT_RED } else { AMBER }, warning); + ui.colored_label( + if severe { + ui.visuals().error_fg_color + } else { + palette.amber + }, + warning, + ); } remove = ui.button("Remove reference").clicked(); } @@ -276,7 +284,7 @@ impl Editor { self.reference_error.clear(); } if !self.reference_error.is_empty() { - ui.colored_label(Color32::LIGHT_RED, &self.reference_error); + ui.colored_label(ui.visuals().error_fg_color, &self.reference_error); } ui.label("Reference stays fixed behind layers. Warnings never block placement."); }); @@ -560,6 +568,7 @@ impl Editor { } } fn paste_window(&mut self, ctx: &egui::Context) { + let palette = theme::palette(ctx); let Some(mut p) = self.paste.take() else { return; }; @@ -575,7 +584,7 @@ impl Editor { if ui.button("Read geometry").clicked() {p.parse();} if ui.button("Import SVG…").clicked() && let Some(path)=rfd::FileDialog::new().add_filter("SVG", &["svg"]).pick_file() {Self::read_svg(&path,&mut p);} }); - if !p.error.is_empty() {ui.colored_label(AMBER,&p.error);} + if !p.error.is_empty() {ui.colored_label(palette.amber,&p.error);} if p.shapes.is_empty() {return;} ui.label(&p.note); ui.horizontal(|ui| { @@ -611,7 +620,7 @@ impl Editor { let before=self.layout.layers()[target]; if let Ok(after)=p.geometry(&shape,before) { ui.columns(2,|cols| {cols[0].label("Before");cols[0].small(bounds(before));cols[1].label("After");cols[1].small(bounds(after));}); - if after.outside_on(self.layout.formats().output) {ui.colored_label(AMBER,"Outside the screen; imported coordinates will be preserved.");} + if after.outside_on(self.layout.formats().output) {ui.colored_label(palette.amber,"Outside the screen; imported coordinates will be preserved.");} } } } @@ -623,7 +632,7 @@ impl Editor { if !p.shapes.is_empty() { let mut preview=self.layout.clone(); let valid=p.apply(&mut preview); - if let Err(e)=&valid {ui.colored_label(AMBER,e);} + if let Err(e)=&valid {ui.colored_label(palette.amber,e);} if apply_button(ui,"Apply mapped values", valid.is_ok() && (preview.layers()!=self.layout.layers() || preview.formats()!=self.layout.formats())).clicked() { match p.apply(&mut self.layout) {Ok(())=>{self.sync();close=true;},Err(e)=>p.error=e} } @@ -635,30 +644,31 @@ impl Editor { } } fn inspector(&mut self, ui: &mut egui::Ui) { + let palette = theme::palette(ui.ctx()); let (r, _) = ui.allocate_exact_size( Vec2::new(ui.available_width(), 1060.0), egui::Sense::hover(), ); let ink = Ink::new(ui, r); let w = r.width(); - ink.text(0.0, 2.0, "LAYERS", 11.0, MUTED); + ink.text(0.0, 2.0, "LAYERS", 11.0, palette.muted); for i in 0..2 { let y = 28.0 + i as f32 * 44.0; let color = if self.layout.selection_mask()[i] { - AMBER + palette.amber } else { - MUTED + palette.muted }; ink.card( 0.0, y, w, 38.0, - FIELD, + palette.field, if self.layout.selection_mask()[i] { color } else { - LINE + palette.line }, ); ink.text( @@ -666,7 +676,11 @@ impl Editor { y + 10.0, label(i), 15.0, - if self.layout.visible(i) { color } else { MUTED }, + if self.layout.visible(i) { + color + } else { + palette.muted + }, ); if click(ui, &ink, [0.0, y, w - 136.0, 38.0], ("layer", i)) { if click_shift_modifier(ui) { @@ -703,10 +717,14 @@ impl Editor { y + 5.0, 60.0, 28.0, - if active { PURPLE } else { PANEL }, - LINE, + if active { + palette.purple + } else { + palette.panel + }, + palette.line, ); - ink.text(x + 8.0, y + 12.0, text, 12.0, TEXT); + ink.text(x + 8.0, y + 12.0, text, 12.0, palette.text); if click(ui, &ink, [x, y + 5.0, 60.0, 28.0], (kind, i)) { self.marquee = None; if kind == "lock" { @@ -718,7 +736,7 @@ impl Editor { } } } - ink.line([0.0, 130.0], [w, 130.0], LINE); + ink.line([0.0, 130.0], [w, 130.0], palette.line); if self.layout.selected_indices().len() > 1 { self.alignment_inspector(ui, &ink, w); return; @@ -729,27 +747,27 @@ impl Editor { 153.0, "Select a layer, or drag a selection box.", 16.0, - TEXT, + palette.text, ); ink.text( 0.0, 182.0, "Shift-click to add or remove layers.", 13.0, - MUTED, + palette.muted, ); return; }; let g = self.layout.layers()[i]; - ink.text(0.0, 150.0, label(i), 25.0, TEXT); + ink.text(0.0, 150.0, label(i), 25.0, palette.text); ink.text( 0.0, 191.0, "LAYER RESOLUTION · CLICK FOR LAYER PROPERTIES", 11.0, - MUTED, + palette.muted, ); - ink.card(0.0, 214.0, w, 34.0, FIELD, LINE); + ink.card(0.0, 214.0, w, 34.0, palette.field, palette.line); ink.text( 12.0, 223.0, @@ -760,7 +778,7 @@ impl Editor { g.width / g.height ), 13.0, - TEXT, + palette.text, ); if click(ui, &ink, [0.0, 214.0, w, 34.0], "open-formats") { self.property_tab = PropertyTab::Layer; @@ -778,7 +796,7 @@ impl Editor { m.framing.offset[1] ), 11.0, - MUTED, + palette.muted, ); } let edit_label = if self.edit_content { @@ -817,11 +835,17 @@ impl Editor { Rect::from_min_size(ink.point(0.0, 317.0), Vec2::new(w, 48.0)), egui::Label::new(egui::RichText::new( "Changes the crop values inside this layer. Drag content to reposition it; the visible box stays fixed." - ).size(12.0).color(MUTED)).wrap().halign(egui::Align::Min), + ).size(12.0).color(palette.muted)).wrap().halign(egui::Align::Min), ); let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 108.0))); - ink.text(0.0, 267.0, "POSITION FROM SCREEN CORNER", 11.0, MUTED); - ink.card(0.0, 292.0, 94.0, 58.0, FIELD, LINE); + ink.text( + 0.0, + 267.0, + "POSITION FROM SCREEN CORNER", + 11.0, + palette.muted, + ); + ink.card(0.0, 292.0, 94.0, 58.0, palette.field, palette.line); for (x, y, c) in [ (8.0, 300.0, Corner::TopLeft), (84.0, 300.0, Corner::TopRight), @@ -833,7 +857,11 @@ impl Editor { y - 3.0, 6.0, 6.0, - if c == self.corner { CYAN } else { MUTED }, + if c == self.corner { + palette.cyan + } else { + palette.muted + }, ); if click( ui, @@ -851,8 +879,8 @@ impl Editor { Corner::BottomLeft => ("Bottom left", "From left", "From bottom"), Corner::BottomRight => ("Bottom right", "From right", "From bottom"), }; - ink.text(112.0, 299.0, name, 18.0, TEXT); - ink.text(112.0, 326.0, "Offsets inward · px", 12.0, MUTED); + ink.text(112.0, 299.0, name, 18.0, palette.text); + ink.text(112.0, 326.0, "Offsets inward · px", 12.0, palette.muted); let half = (w - 12.0) / 2.0; let mut enter = false; for (index, x, y, title) in [ @@ -861,7 +889,7 @@ impl Editor { (2, 0.0, 449.0, "Layer width"), (3, half + 12.0, 449.0, "Layer height"), ] { - ink.text(x, y, title, 12.0, MUTED); + ink.text(x, y, title, 12.0, palette.muted); let rect = Rect::from_min_size(ink.point(x, y + 23.0), Vec2::new(half, 42.0)); let response = ui.put( rect, @@ -907,7 +935,7 @@ impl Editor { if !self.error.is_empty() { ui.put( Rect::from_min_size(ink.point(0.0, 575.0), Vec2::new(w, 55.0)), - egui::Label::new(egui::RichText::new(&self.error).color(AMBER)).wrap(), + egui::Label::new(egui::RichText::new(&self.error).color(palette.amber)).wrap(), ); } else if g.outside_on(self.layout.formats().output) { ink.text( @@ -915,11 +943,17 @@ impl Editor { 579.0, "Outside screen · use Fit selected to find it", 12.0, - AMBER, + palette.amber, ); } - ink.line([0.0, 612.0], [w, 612.0], LINE); - ink.text(0.0, 635.0, "VISIBLE BOX / CENTER POSITION", 11.0, CYAN); + ink.line([0.0, 612.0], [w, 612.0], palette.line); + ink.text( + 0.0, + 635.0, + "VISIBLE BOX / CENTER POSITION", + 11.0, + palette.cyan, + ); let [h, v] = g.center(); ink.field(0.0, 665.0, half, "Horizontal · from left", &number(h)); ink.field(half + 12.0, 665.0, half, "Vertical · from top", &number(v)); @@ -928,7 +962,7 @@ impl Editor { 748.0, "Layer properties: crops / provisional device mapping", 12.0, - MUTED, + palette.muted, ); ink.button(0.0, 780.0, w, "Copy position values", true); if click(ui, &ink, [0.0, 780.0, w, 34.0], "copy-values") { @@ -943,10 +977,11 @@ impl Editor { 884.0, "Or Ctrl/Cmd-V with the viewport focused", 12.0, - MUTED, + palette.muted, ); } fn alignment_menu(&mut self, ui: &mut egui::Ui) { + let palette = theme::palette(ui.ctx()); ui.set_min_width(222.0); ui.label("ALIGN TO"); if self.align_target == AlignTarget::Screen { @@ -1028,7 +1063,7 @@ impl Editor { ui.label("Select layers to align."); } if !self.error.is_empty() { - ui.colored_label(AMBER, &self.error); + ui.colored_label(palette.amber, &self.error); } } fn layer_context_menu(&mut self, ui: &mut egui::Ui) { @@ -1130,20 +1165,21 @@ impl Editor { } fn alignment_inspector(&mut self, ui: &mut egui::Ui, ink: &Ink, w: f32) { - ink.text(0.0, 150.0, "2 layers selected", 25.0, TEXT); + let palette = theme::palette(ui.ctx()); + ink.text(0.0, 150.0, "2 layers selected", 25.0, palette.text); ink.text( 0.0, 187.0, "Drag or nudge to move the selection together.", 12.0, - MUTED, + palette.muted, ); ink.text( 0.0, 225.0, "Use the toolbar alignment menu to align layers.", 12.0, - MUTED, + palette.muted, ); ui.scope_builder( egui::UiBuilder::new().max_rect(Rect::from_min_size( @@ -1192,25 +1228,31 @@ impl Editor { ResizeMode::Mirror => "Left/right mirrored handles, equal proportional scaling. Two layers. Escape exits.", ResizeMode::Opposite => "Diagonally opposite corners, equal proportional scaling. Two layers. Escape exits.", } - ).size(12.0).color(MUTED)).wrap().halign(egui::Align::Min)); + ).size(12.0).color(palette.muted)).wrap().halign(egui::Align::Min)); let shifted = Ink { painter: ink.painter.clone(), origin: ink.origin + Vec2::new(0.0, 42.0), scale: ink.scale, }; let ink = &shifted; - ink.line([0.0, 319.0], [w, 319.0], LINE); - ink.text(0.0, 341.0, "VISIBLE BOX / CENTER POSITIONS", 11.0, CYAN); + ink.line([0.0, 319.0], [w, 319.0], palette.line); + ink.text( + 0.0, + 341.0, + "VISIBLE BOX / CENTER POSITIONS", + 11.0, + palette.cyan, + ); for (row, i) in self.layout.selected_indices().into_iter().enumerate() { let y = 375.0 + row as f32 * 80.0; let [x, cy] = self.layout.layers()[i].center(); - ink.text(0.0, y, label(i), 13.0, MUTED); + ink.text(0.0, y, label(i), 13.0, palette.muted); ink.text( 0.0, y + 25.0, &format!("H {} V {}", number(x), number(cy)), 19.0, - TEXT, + palette.text, ); } ink.button(0.0, 552.0, w, "Copy selected positions", true); @@ -1222,12 +1264,12 @@ impl Editor { 609.0, "Numeric edits require one selected layer.", 12.0, - MUTED, + palette.muted, ); if !self.error.is_empty() { ui.put( Rect::from_min_size(ink.point(0.0, 640.0), Vec2::new(w, 60.0)), - egui::Label::new(egui::RichText::new(&self.error).color(AMBER)).wrap(), + egui::Label::new(egui::RichText::new(&self.error).color(palette.amber)).wrap(), ); } } @@ -1308,11 +1350,12 @@ impl Editor { None } fn workspace(&mut self, ui: &mut egui::Ui) { + let palette = theme::palette(ui.ctx()); let r = ui.max_rect(); let ink = Ink::new(ui, r); let output = self.layout.formats().output; let [sw, sh] = output.map(|v| v as f32); - ink.card(24.0, 20.0, 36.0, 36.0, FIELD, LINE); + ink.card(24.0, 20.0, 36.0, 36.0, palette.field, palette.line); if toolbar_icon( ui, Rect::from_min_size(ink.point(26.0, 22.0), Vec2::splat(32.0)), @@ -1350,8 +1393,15 @@ impl Editor { 390.0, ) }; - ink.card(strip_x, 20.0, strip_width, 36.0, FIELD, LINE); - ink.line([separator, 28.0], [separator, 48.0], LINE); + ink.card( + strip_x, + 20.0, + strip_width, + 36.0, + palette.field, + palette.line, + ); + ink.line([separator, 28.0], [separator, 48.0], palette.line); for (x, text, icon) in [ (positions[0], "Fit screen", ToolbarIcon::Screen), (positions[1], "Fit selected", ToolbarIcon::Selection), @@ -1396,9 +1446,9 @@ impl Editor { let c = response.rect.center(); let p = ui.painter(); let color = if response.hovered() || response.has_focus() { - CYAN + palette.cyan } else { - TEXT + palette.text }; let stroke = Stroke::new(1.6_f32, color); p.line_segment( @@ -1438,9 +1488,9 @@ impl Editor { let stroke = Stroke::new( 1.6_f32, if response.hovered() || response.has_focus() { - CYAN + palette.cyan } else { - TEXT + palette.text }, ); let p = ui.painter(); @@ -1495,9 +1545,9 @@ impl Editor { let stroke = Stroke::new( 1.6_f32, if response.hovered() || response.has_focus() { - CYAN + palette.cyan } else { - TEXT + palette.text }, ); let points = (0..32) @@ -1527,7 +1577,7 @@ impl Editor { egui::Align2::CENTER_TOP, label, egui::FontId::proportional(11.0), - MUTED, + palette.muted, ); } } @@ -1535,13 +1585,20 @@ impl Editor { self.edit_content = false; } let (text, color) = if !self.reference_error.is_empty() { - (self.reference_error.clone(), Color32::LIGHT_RED) + (self.reference_error.clone(), ui.visuals().error_fg_color) } else if let Some((severe, warning)) = self .reference .as_ref() .and_then(|r| r.warning(self.layout.formats().output)) { - (warning, if severe { Color32::LIGHT_RED } else { AMBER }) + ( + warning, + if severe { + ui.visuals().error_fg_color + } else { + palette.amber + }, + ) } else { ( self.reference @@ -1550,7 +1607,7 @@ impl Editor { .unwrap_or_else(|| { "Drop a reference picture here, or use Import / Reference image…".into() }), - MUTED, + palette.muted, ) }; ui.put( @@ -1976,14 +2033,14 @@ impl Editor { ResizeMode::Opposite => "Opposite handles · Opposite corners or edges · Escape exits", } }, 12.0, - MUTED, + palette.muted, ); ink.text( 24.0, r.height() - 31.0, "Scroll to zoom · Space-drag to pan · Reference image stays fixed", 12.0, - MUTED, + palette.muted, ); } } @@ -2027,6 +2084,7 @@ fn click(ui: &egui::Ui, ink: &Ink, b: [f32; 4], id: impl std::hash::Hash) -> boo } impl Editor { fn ui(&mut self, ctx: &egui::Context) { + let palette = theme::palette(ctx); let dropped = ctx.input(|i| i.raw.dropped_files.clone()); if !dropped.is_empty() { if dropped.len() == 1 { @@ -2039,13 +2097,13 @@ impl Editor { self.shortcuts(ctx); egui::TopBottomPanel::top("header") .exact_height(44.0) - .frame(egui::Frame::NONE.fill(PANEL)) + .frame(egui::Frame::NONE.fill(palette.panel)) .show(ctx, |ui| { let r = ui.max_rect(); let ink = Ink::new(ui, r); - ink.text(24.0, 11.0, "MIDRA / LAYOUT", 18.0, TEXT); - ink.line([206.0, 13.0], [206.0, 31.0], LINE); - ink.text(222.0, 15.0, "Offline position helper", 13.0, MUTED); + ink.text(24.0, 11.0, "MIDRA / LAYOUT", 18.0, palette.text); + ink.line([206.0, 13.0], [206.0, 31.0], palette.line); + ink.text(222.0, 15.0, "Offline position helper", 13.0, palette.muted); ui.scope_builder( egui::UiBuilder::new() .max_rect(Rect::from_min_size( @@ -2058,7 +2116,7 @@ impl Editor { ui.menu_button("Menu", |ui| self.application_menu(ui)); }, ); - ink.text(r.width() - 347.0, 15.0, "EIKOS 4K", 12.0, CYAN); + ink.text(r.width() - 347.0, 15.0, "EIKOS 4K", 12.0, palette.cyan); ink.button(r.width() - 212.0, 5.0, 188.0, "Copy coordinates", false); if click( ui, @@ -2071,12 +2129,13 @@ impl Editor { }); egui::TopBottomPanel::bottom("status") .exact_height(34.0) - .frame(egui::Frame::NONE.fill(PANEL)) + .frame(egui::Frame::NONE.fill(palette.panel)) .show(ctx, |ui| { let r = ui.max_rect(); let ink = Ink::new(ui, r); - ink.painter.circle_filled(ink.point(24.0, 17.0), 3.0, CYAN); - ink.text(36.0, 10.0, "OFFLINE", 11.0, MUTED); + ink.painter + .circle_filled(ink.point(24.0, 17.0), 3.0, palette.cyan); + ink.text(36.0, 10.0, "OFFLINE", 11.0, palette.muted); ink.text( 116.0, 10.0, @@ -2086,7 +2145,7 @@ impl Editor { "Select a layer to move or paste" }, 12.0, - MUTED, + palette.muted, ); ink.text( r.width() - 278.0, @@ -2097,20 +2156,20 @@ impl Editor { self.layout.formats().output[1] ), 12.0, - MUTED, + palette.muted, ); }); egui::SidePanel::right("inspector") .exact_width(392.0) .resizable(false) - .frame(egui::Frame::NONE.fill(PANEL).inner_margin(24.0)) + .frame(egui::Frame::NONE.fill(palette.panel).inner_margin(24.0)) .show(ctx, |ui| { egui::ScrollArea::vertical() .drag_to_scroll(false) .show(ui, |ui| self.inspector(ui)); }); egui::CentralPanel::default() - .frame(egui::Frame::NONE.fill(BG)) + .frame(egui::Frame::NONE.fill(palette.bg)) .show(ctx, |ui| self.workspace(ui)); self.paste_window(ctx); self.reference_window(ctx); @@ -2133,6 +2192,7 @@ fn alignment_icon( horizontal: Option, vertical: Option, ) -> egui::Response { + let palette = theme::palette(ui.ctx()); let response = ui.interact(rect, ui.id().with(title), egui::Sense::click()); response.widget_info(|| { egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), title) @@ -2142,22 +2202,22 @@ fn alignment_icon( rect, 3.0, if response.is_pointer_button_down_on() { - PURPLE + palette.purple } else if response.hovered() { - PANEL + palette.panel } else { - FIELD + palette.field }, - Stroke::new(1.0_f32, LINE), + Stroke::new(1.0_f32, palette.line), StrokeKind::Inside, ); let c = rect.center(); let stroke = Stroke::new( 1.6_f32, if response.hovered() || response.has_focus() { - CYAN + palette.cyan } else { - TEXT + palette.text }, ); let x = match horizontal { @@ -2194,7 +2254,7 @@ fn alignment_icon( p.rect( Rect::from_center_size(c + Vec2::new(x, y), Vec2::splat(8.0)), 0.0, - FIELD, + palette.field, stroke, StrokeKind::Inside, ); @@ -2202,9 +2262,14 @@ fn alignment_icon( } fn apply_button(ui: &mut egui::Ui, label: &str, pending: bool) -> egui::Response { + let palette = theme::palette(ui.ctx()); let button = egui::Button::new(label) .min_size(ui.spacing().interact_size) - .fill(if pending { PURPLE } else { FIELD }); + .fill(if pending { + palette.purple + } else { + palette.field + }); ui.add_enabled(pending, button) } @@ -2223,19 +2288,24 @@ fn toolbar_menu( title: &str, contents: impl FnOnce(&mut egui::Ui) -> R, ) -> egui::InnerResponse> { + let palette = theme::palette(ui.ctx()); let original = ui.style().clone(); let widgets = &mut ui.style_mut().visuals.widgets; for (visuals, fill, border) in [ - (&mut widgets.inactive, FIELD, LINE), - (&mut widgets.hovered, PANEL, CYAN), - (&mut widgets.active, PURPLE, CYAN), - (&mut widgets.open, PANEL, CYAN), + (&mut widgets.inactive, palette.field, palette.line), + (&mut widgets.hovered, palette.panel, palette.cyan), + (&mut widgets.active, palette.purple, palette.cyan), + (&mut widgets.open, palette.panel, palette.cyan), ] { visuals.bg_fill = fill; visuals.weak_bg_fill = fill; visuals.bg_stroke = Stroke::new(1.0_f32, border); visuals.corner_radius = egui::CornerRadius::same(4); - visuals.fg_stroke.color = if border == CYAN { CYAN } else { TEXT }; + visuals.fg_stroke.color = if border == palette.cyan { + palette.cyan + } else { + palette.text + }; } let response = ui.menu_button(title, |ui| { ui.set_style(original.clone()); @@ -2246,6 +2316,7 @@ fn toolbar_menu( } fn toolbar_icon(ui: &mut egui::Ui, rect: Rect, label: &str, icon: ToolbarIcon) -> egui::Response { + let palette = theme::palette(ui.ctx()); let response = ui.interact(rect, ui.id().with(("toolbar", label)), egui::Sense::click()); response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, label)); let painter = ui.painter(); @@ -2255,13 +2326,13 @@ fn toolbar_icon(ui: &mut egui::Ui, rect: Rect, label: &str, icon: ToolbarIcon) - rect.shrink(1.0), 4.0, if response.is_pointer_button_down_on() { - PURPLE + palette.purple } else { - PANEL + palette.panel }, ); } - let stroke = Stroke::new(1.6_f32, if focused { CYAN } else { TEXT }); + let stroke = Stroke::new(1.6_f32, if focused { palette.cyan } else { palette.text }); let c = rect.center(); let point = |x, y| c + Vec2::new(x, y); match icon { @@ -2274,7 +2345,7 @@ fn toolbar_icon(ui: &mut egui::Ui, rect: Rect, label: &str, icon: ToolbarIcon) - ); for (y, knob) in [(-4.0, -3.0), (4.0, 3.0)] { painter.line_segment([point(-7.0, y), point(7.0, y)], stroke); - painter.circle_filled(point(knob, y), 2.5, FIELD); + painter.circle_filled(point(knob, y), 2.5, palette.field); painter.circle_stroke(point(knob, y), 2.5, stroke); } } diff --git a/crates/midra-layout/src/main.rs b/crates/midra-layout/src/main.rs index da99329..df28cf3 100644 --- a/crates/midra-layout/src/main.rs +++ b/crates/midra-layout/src/main.rs @@ -29,6 +29,7 @@ fn main() -> eframe::Result { style.visuals.widgets.inactive.bg_stroke = Stroke::new(1.0_f32, LINE); style.spacing.item_spacing = Vec2::new(12.0, 10.0); cc.egui_ctx.set_style(style); + theme::Theme::Midra.apply(&cc.egui_ctx); Ok(Box::new(gui::Editor::default())) }), ) @@ -36,6 +37,7 @@ fn main() -> eframe::Result { mod gui; mod reference; +mod theme; /// Draw in local logical points; viewport artwork alone uses a fitted scale. struct Ink { @@ -93,20 +95,34 @@ impl Ink { } fn button(&self, x: f32, y: f32, w: f32, label: &str, primary: bool) { - self.card(x, y, w, 34.0, if primary { PURPLE } else { FIELD }, LINE); - self.text(x + 12.0, y + 9.0, label, 13.0, TEXT); + let palette = theme::palette(self.painter.ctx()); + self.card( + x, + y, + w, + 34.0, + if primary { + palette.purple + } else { + palette.field + }, + palette.line, + ); + self.text(x + 12.0, y + 9.0, label, 13.0, palette.text); } fn field(&self, x: f32, y: f32, w: f32, label: &str, value: &str) { - self.text(x, y, label, 12.0, MUTED); - self.card(x, y + 23.0, w, 42.0, FIELD, LINE); - self.text(x + 12.0, y + 34.0, value, 18.0, TEXT); + let palette = theme::palette(self.painter.ctx()); + self.text(x, y, label, 12.0, palette.muted); + self.card(x, y + 23.0, w, 42.0, palette.field, palette.line); + self.text(x + 12.0, y + 34.0, value, 18.0, palette.text); } } fn screen_artwork(ink: &Ink) { - ink.text(0.0, -24.0, "SCREEN 1", 12.0, MUTED); - ink.text(790.0, -24.0, "1920 × 1080 px", 13.0, MUTED); + let palette = theme::palette(ink.painter.ctx()); + ink.text(0.0, -24.0, "SCREEN 1", 12.0, palette.muted); + ink.text(790.0, -24.0, "1920 × 1080 px", 13.0, palette.muted); ink.rect(0.0, 0.0, 960.0, 540.0, Color32::from_rgb(20, 45, 64)); ink.rect(0.0, 0.0, 960.0, 36.0, Color32::from_rgb(38, 69, 86)); ink.text(24.0, 10.0, "ANNUAL FORUM / MAIN STAGE", 13.0, MUTED); diff --git a/crates/midra-layout/src/menu_ui.rs b/crates/midra-layout/src/menu_ui.rs index d15e8d3..98efaaa 100644 --- a/crates/midra-layout/src/menu_ui.rs +++ b/crates/midra-layout/src/menu_ui.rs @@ -40,6 +40,19 @@ impl Editor { } } pub(super) fn viewport_options_menu(&mut self, ui: &mut egui::Ui) { + let current = theme::Theme::current(ui.ctx()); + ui.menu_button(format!("Theme: {}", current.name()), |ui| { + for choice in theme::Theme::ALL { + if ui + .selectable_label(current == choice, choice.name()) + .clicked() + { + choice.apply(ui.ctx()); + ui.close_menu(); + } + } + }); + ui.separator(); ui.checkbox(&mut self.show_toolbar_icon_names, "Show toolbar icon names"); ui.checkbox( &mut self.keep_aspect_ratio, @@ -196,6 +209,30 @@ mod tests { frame(app, ctx, vec![mouse(pos, false)]); } #[test] + fn theme_menu_switches_chrome_without_changing_document() { + let mut app = Editor::default(); + let ctx = egui::Context::default(); + let boxes = *app.layout.layers(); + let formats = *app.layout.formats(); + for choice in theme::Theme::ALL { + click_label(&mut app, &ctx, "Menu"); + click_label(&mut app, &ctx, "Options"); + let label = format!("Theme: {}", theme::Theme::current(&ctx).name()); + click_label(&mut app, &ctx, &label); + click_label(&mut app, &ctx, choice.name()); + assert!(theme::Theme::current(&ctx) == choice); + assert_eq!( + ctx.style().visuals.dark_mode, + choice != theme::Theme::CorporateLight + ); + let output = frame(&mut app, &ctx, vec![]); + assert!(output.shapes.iter().any(|s| matches!(&s.shape, + egui::Shape::Rect(r) if r.fill == choice.palette().bg))); + assert_eq!(*app.layout.layers(), boxes); + assert_eq!(*app.layout.formats(), formats); + } + } + #[test] fn main_menu_routes_view_options_and_selection_commands() { for (section, action) in [ ("View", "Fit screen"), diff --git a/crates/midra-layout/src/theme.rs b/crates/midra-layout/src/theme.rs new file mode 100644 index 0000000..e131e50 --- /dev/null +++ b/crates/midra-layout/src/theme.rs @@ -0,0 +1,121 @@ +//! Application palettes adapted from SOTV's song database; see docs/midra-layout.md. +use super::*; + +#[derive(Clone, Copy, Default, PartialEq, Eq)] +pub enum Theme { + #[default] + Midra, + FoxifiedDark, + CorporateLight, +} + +#[derive(Clone, Copy)] +pub struct Palette { + pub bg: Color32, + pub panel: Color32, + pub field: Color32, + pub line: Color32, + pub text: Color32, + pub muted: Color32, + pub cyan: Color32, + pub amber: Color32, + pub purple: Color32, +} + +impl Theme { + pub const ALL: [Self; 3] = [Self::Midra, Self::FoxifiedDark, Self::CorporateLight]; + pub fn name(self) -> &'static str { + match self { + Self::Midra => "Midra Dark", + Self::FoxifiedDark => "Foxified Dark", + Self::CorporateLight => "Corporate Light", + } + } + pub fn current(ctx: &egui::Context) -> Self { + ctx.data(|d| { + d.get_temp(egui::Id::new("application-theme")) + .unwrap_or_default() + }) + } + pub fn palette(self) -> Palette { + let rgb = |hex: u32| Color32::from_rgb((hex >> 16) as u8, (hex >> 8) as u8, hex as u8); + match self { + Self::Midra => Palette { + bg: BG, + panel: PANEL, + field: FIELD, + line: LINE, + text: TEXT, + muted: MUTED, + cyan: CYAN, + amber: AMBER, + purple: PURPLE, + }, + Self::FoxifiedDark => Palette { + bg: rgb(0x2e1f16), + panel: rgb(0x3b261b), + field: rgb(0x1e1309), + line: rgb(0xaa6033), + text: rgb(0xffcc99), + muted: rgb(0xffd8b1), + cyan: rgb(0xff6600), + amber: AMBER, + purple: rgb(0x854018), + }, + Self::CorporateLight => Palette { + bg: rgb(0xf4f5f7), + panel: Color32::WHITE, + field: rgb(0xf0f1f3), + line: rgb(0xbbbbbb), + text: rgb(0x222222), + muted: rgb(0x52616f), + cyan: rgb(0x216783), + amber: rgb(0x815600), + purple: rgb(0xc5dce8), + }, + } + } + pub fn apply(self, ctx: &egui::Context) { + let p = self.palette(); + let mut v = if self == Self::CorporateLight { + egui::Visuals::light() + } else { + egui::Visuals::dark() + }; + v.override_text_color = Some(p.text); + v.panel_fill = p.panel; + v.window_fill = p.panel; + v.window_stroke = Stroke::new(1.0_f32, p.line); + v.extreme_bg_color = p.field; + v.faint_bg_color = p.bg; + v.code_bg_color = p.field; + v.hyperlink_color = p.cyan; + v.warn_fg_color = p.amber; + v.error_fg_color = if self == Self::CorporateLight { + Color32::from_rgb(165, 30, 40) + } else { + Color32::LIGHT_RED + }; + v.selection.bg_fill = p.purple; + v.selection.stroke = Stroke::new(1.0_f32, p.text); + for (widget, fill, border) in [ + (&mut v.widgets.noninteractive, p.panel, p.line), + (&mut v.widgets.inactive, p.field, p.line), + (&mut v.widgets.hovered, p.panel, p.cyan), + (&mut v.widgets.active, p.purple, p.cyan), + (&mut v.widgets.open, p.panel, p.cyan), + ] { + widget.bg_fill = fill; + widget.weak_bg_fill = fill; + widget.bg_stroke = Stroke::new(1.0_f32, border); + widget.fg_stroke = Stroke::new(1.0_f32, p.text); + } + ctx.set_visuals(v); + ctx.data_mut(|d| d.insert_temp(egui::Id::new("application-theme"), self)); + ctx.request_repaint(); + } +} + +pub fn palette(ctx: &egui::Context) -> Palette { + Theme::current(ctx).palette() +} diff --git a/docs/midra-layout.md b/docs/midra-layout.md index 920123d..e3d9e0b 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -430,3 +430,20 @@ Detailed numeric controls remain in their existing properties dialogs. Enable **Options → Show toolbar icon names** (also available from the toolbar cog) to display captions beneath the icons. It is off by default and saved with the project; older projects open with captions off. + +### Application themes + +**Menu → Options → Theme** (also in the toolbar cog) offers **Midra Dark**, +**Foxified Dark**, and **Corporate Light**. Switching updates toolbar, inspector, +dialogs, fields and menus immediately. Reference images, source test patterns, +and the dark screen canvas retain their colors; selected layers remain gold. +Theme choice applies to the current application session, survives opening other +projects, and is not included in project JSON or SVG exports. + +The additional palettes are adapted from the sibling `SOTV_Websites` project's +`sotv/song_database/styles/themes/theme-foxified-dark.css` and +`styles/base/variables.css` (Corporate Light, selected by +`styles/themes/theme-corporate.css`). Foxified preserves its brown surfaces, +peach text and orange accent. Corporate preserves its neutral light surfaces; +muted text, warnings and accent colors are darkened for readable contrast. +Action fills are adapted for readable button text in both themes.