Apply application themes throughout the layout viewport

This commit is contained in:
Dandaedre 2026-11-13 15:58:43 +01:00
parent df0ee4cf5d
commit e87db59790
7 changed files with 84 additions and 42 deletions

View File

@ -352,6 +352,7 @@ fn paint_pattern_clipped(
crop: Crop,
clip: Rect,
) {
let palette = theme::palette(painter.ctx());
let Ok(input) = source.input() else {
return;
};
@ -385,19 +386,24 @@ fn paint_pattern_clipped(
cell,
0.0,
if (row + col) % 2 == 0 {
Color32::from_rgb(38, 75, 93)
palette.pattern[0]
} else {
Color32::from_rgb(26, 51, 68)
palette.pattern[1]
},
);
p.rect_stroke(cell, 0.0, Stroke::new(1.0_f32, MUTED), StrokeKind::Inside);
p.rect_stroke(
cell,
0.0,
Stroke::new(1.0_f32, palette.muted),
StrokeKind::Inside,
);
if cell.width() > 35.0 && cell.height() > 25.0 {
p.text(
cell.center(),
Align2::CENTER_CENTER,
format!("{},{}", col, row),
FontId::proportional(11.0),
TEXT,
palette.text,
);
}
}
@ -406,7 +412,7 @@ fn paint_pattern_clipped(
p.circle_stroke(
center,
(source.native[0].min(source.native[1]) as f64 * k * 0.2) as f32,
Stroke::new(2.0_f32, AMBER),
Stroke::new(2.0_f32, palette.amber),
);
}

View File

@ -1879,9 +1879,7 @@ impl Editor {
screen_artwork(&screen);
} else {
let rect = Rect::from_min_size(origin, Vec2::new(sw, sh) * scale);
screen
.painter
.rect_filled(rect, 0.0, Color32::from_rgb(20, 45, 64));
screen.painter.rect_filled(rect, 0.0, palette.canvas);
for n in 0..=10 {
let t = n as f32 / 10.0;
screen.painter.line_segment(
@ -1889,14 +1887,14 @@ impl Editor {
rect.left_top() + Vec2::new(rect.width() * t, 0.0),
rect.left_bottom() + Vec2::new(rect.width() * t, 0.0),
],
Stroke::new(1.0_f32, LINE),
Stroke::new(1.0_f32, palette.grid),
);
screen.painter.line_segment(
[
rect.left_top() + Vec2::new(0.0, rect.height() * t),
rect.right_top() + Vec2::new(0.0, rect.height() * t),
],
Stroke::new(1.0_f32, LINE),
Stroke::new(1.0_f32, palette.grid),
);
}
}
@ -1921,9 +1919,9 @@ impl Editor {
continue;
}
let color = if self.layout.selection_mask()[i] {
AMBER
palette.amber
} else {
MUTED
palette.muted
};
let rect = Rect::from_min_size(
origin + Vec2::new(g.x as f32, g.y as f32) * scale,
@ -1934,9 +1932,14 @@ impl Editor {
rect,
0.0,
if self.reference.as_ref().is_some_and(|r| r.visible) {
Color32::from_rgba_unmultiplied(23, 59, 80, 35)
Color32::from_rgba_unmultiplied(
palette.layer.r(),
palette.layer.g(),
palette.layer.b(),
35,
)
} else {
Color32::from_rgb(23, 59, 80)
palette.layer
},
Stroke::new(1.0_f32, color),
StrokeKind::Inside,
@ -1965,7 +1968,7 @@ impl Editor {
Align2::LEFT_BOTTOM,
format!("{} × {} px", number(g.width), number(g.height)),
FontId::proportional(12.0),
TEXT,
palette.text,
);
}
}
@ -1983,7 +1986,7 @@ impl Editor {
p.rect(
Rect::from_center_size(corner, Vec2::splat(7.0)),
1.0,
PANEL,
palette.panel,
Stroke::new(1.0_f32, color),
StrokeKind::Inside,
);
@ -2006,13 +2009,18 @@ impl Editor {
}
if let Some(rect) = self.crop_bounds(origin, scale) {
let p = &screen.painter;
p.rect_stroke(rect, 0.0, Stroke::new(1.5_f32, CYAN), StrokeKind::Inside);
p.rect_stroke(
rect,
0.0,
Stroke::new(1.5_f32, palette.cyan),
StrokeKind::Inside,
);
for (_, corner) in crop_handle_positions(rect) {
p.rect(
Rect::from_center_size(corner, Vec2::splat(9.0)),
1.0,
PANEL,
Stroke::new(1.5_f32, CYAN),
palette.panel,
Stroke::new(1.5_f32, palette.cyan),
StrokeKind::Inside,
);
}
@ -2023,8 +2031,13 @@ impl Editor {
screen.painter.rect(
Rect::from_two_pos(from, to),
0.0,
Color32::from_rgba_unmultiplied(246, 197, 119, 25),
Stroke::new(1.0_f32, AMBER),
Color32::from_rgba_unmultiplied(
palette.amber.r(),
palette.amber.g(),
palette.amber.b(),
25,
),
Stroke::new(1.0_f32, palette.amber),
StrokeKind::Inside,
);
}
@ -2051,7 +2064,7 @@ impl Editor {
+ Vec2::new(if right { sw } else { 0.0 }, if bottom { sh } else { 0.0 })
* scale;
let guide = &screen.painter;
let stroke = Stroke::new(1.0_f32, AMBER);
let stroke = Stroke::new(1.0_f32, palette.amber);
guide.line_segment([edge, Pos2::new(boundary.x, edge.y)], stroke);
guide.line_segment([edge, Pos2::new(edge.x, boundary.y)], stroke);
guide.text(
@ -2059,21 +2072,21 @@ impl Editor {
Align2::CENTER_TOP,
format!("{dx:.1} px"),
FontId::proportional(11.0),
AMBER,
palette.amber,
);
guide.text(
Pos2::new(edge.x + 6.0, (edge.y + boundary.y) / 2.0),
Align2::LEFT_CENTER,
format!("{dy:.1} px"),
FontId::proportional(11.0),
AMBER,
palette.amber,
);
}
}
ink.text(
24.0,
r.height() - 57.0,
if self.edit_content { "Crop mode · Drag cyan handles to zoom content · Drag image to reposition · Click outside to finish" } else { match self.resize_mode {
if self.edit_content { "Crop mode · Drag crop handles to zoom content · Drag image to reposition · Click outside to finish" } else { match self.resize_mode {
ResizeMode::Individual => "Corners resize · Side handles keep opposite edge fixed · Shift-click selects",
ResizeMode::Same => "Same handles · Matching handles scale selected layers proportionally · Escape exits",
ResizeMode::Mirror => "Mirror horizontally · Left/right mirrored handles · Escape exits",

View File

@ -123,29 +123,25 @@ fn screen_artwork(ink: &Ink) {
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);
ink.rect(0.0, 0.0, 960.0, 540.0, palette.canvas);
ink.rect(0.0, 0.0, 960.0, 36.0, palette.banner);
ink.text(24.0, 10.0, "ANNUAL FORUM / MAIN STAGE", 13.0, palette.muted);
for x in (0..=1920).step_by(240) {
ink.line(
[x as f32 / 2.0, 36.0],
[x as f32 / 2.0, 540.0],
Color32::from_rgb(39, 71, 90),
palette.grid,
);
}
for y in (180..=1080).step_by(180) {
ink.line(
[0.0, y as f32 / 2.0],
[960.0, y as f32 / 2.0],
Color32::from_rgb(39, 71, 90),
);
ink.line([0.0, y as f32 / 2.0], [960.0, y as f32 / 2.0], palette.grid);
}
ink.text(24.0, 462.0, "Ideas worth sharing.", 27.0, MUTED);
ink.text(24.0, 462.0, "Ideas worth sharing.", 27.0, palette.muted);
ink.text(
24.0,
503.0,
"Illustrative reference artwork · opacity 65%",
12.0,
MUTED,
palette.muted,
);
}

View File

@ -273,8 +273,14 @@ mod tests {
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)));
for fill in [
choice.palette().bg,
choice.palette().canvas,
choice.palette().layer,
] {
assert!(output.shapes.iter().any(|s| matches!(&s.shape,
egui::Shape::Rect(r) if r.fill == fill)));
}
assert_eq!(*app.layout.layers(), boxes);
assert_eq!(*app.layout.formats(), formats);
}

View File

@ -52,7 +52,7 @@ impl Reference {
warning(self.size, self.preserve_ratio, output)
}
pub fn paint(&self, painter: &egui::Painter, screen: Rect) {
painter.rect_filled(screen, 0.0, BG);
painter.rect_filled(screen, 0.0, theme::palette(painter.ctx()).canvas);
if !self.visible {
return;
}

View File

@ -12,6 +12,11 @@ pub enum Theme {
#[derive(Clone, Copy)]
pub struct Palette {
pub canvas: Color32,
pub banner: Color32,
pub grid: Color32,
pub layer: Color32,
pub pattern: [Color32; 2],
pub bg: Color32,
pub panel: Color32,
pub field: Color32,
@ -42,6 +47,11 @@ impl Theme {
let rgb = |hex: u32| Color32::from_rgb((hex >> 16) as u8, (hex >> 8) as u8, hex as u8);
match self {
Self::Midra => Palette {
canvas: rgb(0x142d40),
banner: rgb(0x264556),
grid: rgb(0x27475a),
layer: rgb(0x173b50),
pattern: [rgb(0x264b5d), rgb(0x1a3344)],
bg: BG,
panel: PANEL,
field: FIELD,
@ -53,6 +63,11 @@ impl Theme {
purple: PURPLE,
},
Self::FoxifiedDark => Palette {
canvas: rgb(0x281a12),
banner: rgb(0x503322),
grid: rgb(0x62432e),
layer: rgb(0x43291d),
pattern: [rgb(0x503322), rgb(0x362318)],
bg: rgb(0x2e1f16),
panel: rgb(0x3b261b),
field: rgb(0x1e1309),
@ -64,6 +79,11 @@ impl Theme {
purple: rgb(0x854018),
},
Self::CorporateLight => Palette {
canvas: rgb(0xffffff),
banner: rgb(0xe5e9f0),
grid: rgb(0xd8dee6),
layer: rgb(0xe9eef3),
pattern: [rgb(0xe5e9f0), rgb(0xf5f7fa)],
bg: rgb(0xf4f5f7),
panel: Color32::WHITE,
field: rgb(0xf0f1f3),

View File

@ -371,7 +371,7 @@ mode and select normally. Clicking or dragging the visible image or its faded
outside preview keeps crop mode active. Property controls remain usable while
editing the crop.
In visual crop mode, a cyan bounding box surrounds the full usable input image,
In visual crop mode, an accent-colored bounding box surrounds the full usable input image,
including the faded preview. Drag any corner or side midpoint to zoom the content
through cropping; the gold visible layer box stays fixed. Content always keeps
its proportions, independently of the layer resize ratio toggle. The opposite
@ -435,8 +435,9 @@ project; older projects open with captions off.
**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.
dialogs, fields and menus immediately. The viewport, grid, layer boxes and source test patterns use the selected palette;
selected layers remain gold (darker gold for contrast in the light theme). Imported
reference image pixels retain their original colors, with themed empty margins.
Theme choice is saved automatically per user, survives restarts and opening other
projects, and is not included in project JSON or SVG exports.