feat(egui): have a separate layout color theme for light mode

This commit is contained in:
Mikolaj Wielgus 2024-12-09 14:21:04 +01:00
parent a5503de0a2
commit 0184a6537e
5 changed files with 125 additions and 75 deletions

View File

@ -3,8 +3,17 @@ use std::collections::HashMap;
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(default)] #[serde(default)]
pub struct Config { pub struct Config {
pub dark_theme: Colors, dark_colors: Colors,
pub light_theme: Colors, light_colors: Colors,
}
impl Config {
pub fn colors(&self, ctx: &egui::Context) -> &Colors {
match ctx.theme() {
egui::Theme::Dark => &self.dark_colors,
egui::Theme::Light => &self.light_colors,
}
}
} }
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
@ -34,62 +43,111 @@ pub struct LayerColor {
impl Default for Config { impl Default for Config {
fn default() -> Self { fn default() -> Self {
let dark_theme = Colors {
layers: LayerColors {
default: LayerColor {
normal: egui::Color32::from_rgb(255, 255, 255),
highlighted: egui::Color32::from_rgb(255, 255, 255),
},
colors: HashMap::from([
(
"F.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(255, 52, 52),
highlighted: egui::Color32::from_rgb(255, 100, 100),
},
),
(
"1".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(255, 52, 52),
highlighted: egui::Color32::from_rgb(255, 100, 100),
},
),
(
"B.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(52, 52, 255),
highlighted: egui::Color32::from_rgb(100, 100, 255),
},
),
(
"2".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(52, 52, 255),
highlighted: egui::Color32::from_rgb(100, 100, 255),
},
),
(
"In1.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(127, 200, 127),
highlighted: egui::Color32::from_rgb(213, 236, 213),
},
),
(
"In2.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(206, 125, 44),
highlighted: egui::Color32::from_rgb(232, 195, 158),
},
),
]),
},
};
Self { Self {
dark_theme: dark_theme.clone(), dark_colors: Colors {
light_theme: dark_theme, layers: LayerColors {
default: LayerColor {
normal: egui::Color32::from_rgb(255, 255, 255),
highlighted: egui::Color32::from_rgb(255, 255, 255),
},
colors: HashMap::from([
(
"F.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(255, 52, 52),
highlighted: egui::Color32::from_rgb(255, 100, 100),
},
),
(
"1".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(255, 52, 52),
highlighted: egui::Color32::from_rgb(255, 100, 100),
},
),
(
"B.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(52, 52, 255),
highlighted: egui::Color32::from_rgb(100, 100, 255),
},
),
(
"2".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(52, 52, 255),
highlighted: egui::Color32::from_rgb(100, 100, 255),
},
),
(
"In1.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(127, 200, 127),
highlighted: egui::Color32::from_rgb(213, 236, 213),
},
),
(
"In2.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(206, 125, 44),
highlighted: egui::Color32::from_rgb(232, 195, 158),
},
),
]),
},
},
light_colors: Colors {
layers: LayerColors {
default: LayerColor {
normal: egui::Color32::from_rgb(0, 0, 0),
highlighted: egui::Color32::from_rgb(0, 0, 0),
},
colors: HashMap::from([
(
"F.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(255, 27, 27),
highlighted: egui::Color32::from_rgb(255, 52, 52),
},
),
(
"1".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(255, 27, 27),
highlighted: egui::Color32::from_rgb(255, 52, 52),
},
),
(
"B.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(27, 27, 255),
highlighted: egui::Color32::from_rgb(52, 52, 255),
},
),
(
"2".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(27, 27, 255),
highlighted: egui::Color32::from_rgb(52, 52, 255),
},
),
(
"In1.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(76, 169, 76),
highlighted: egui::Color32::from_rgb(127, 200, 127),
},
),
(
"In2.Cu".to_string(),
LayerColor {
normal: egui::Color32::from_rgb(183, 80, 12),
highlighted: egui::Color32::from_rgb(206, 125, 44),
},
),
]),
},
},
} }
} }
} }

View File

@ -332,7 +332,7 @@ impl MenuBar {
pub fn update_view_menu( pub fn update_view_menu(
&mut self, &mut self,
ctx: &egui::Context, _ctx: &egui::Context,
ui: &mut egui::Ui, ui: &mut egui::Ui,
tr: &Translator, tr: &Translator,
viewport: &mut Viewport, viewport: &mut Viewport,

View File

@ -9,10 +9,7 @@ use topola::{
graph::{GetLayer, MakePrimitive}, graph::{GetLayer, MakePrimitive},
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
}, },
geometry::{ geometry::shape::{AccessShape, Shape},
compound::ManageCompounds,
shape::{AccessShape, Shape},
},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetPetgraphIndex},
layout::{ layout::{
poly::{MakePolyShape, PolyWeight}, poly::{MakePolyShape, PolyWeight},

View File

@ -17,7 +17,6 @@ use topola::{
geometry::{shape::AccessShape, GenericNode}, geometry::{shape::AccessShape, GenericNode},
layout::{poly::MakePolyShape, via::ViaWeight}, layout::{poly::MakePolyShape, via::ViaWeight},
math::Circle, math::Circle,
specctra::mesadata::SpecctraMesadata,
}; };
use crate::{config::Config, menu_bar::MenuBar, painter::Painter, workspace::Workspace}; use crate::{config::Config, menu_bar::MenuBar, painter::Painter, workspace::Workspace};
@ -93,15 +92,15 @@ impl Viewport {
.selection() .selection()
.contains_node(board, GenericNode::Primitive(primitive)) .contains_node(board, GenericNode::Primitive(primitive))
{ {
config.dark_theme.layers.color(board.layout().rules().layer_layername(i)).highlighted config.colors(ctx).layers.color(board.layout().rules().layer_layername(i)).highlighted
} else if let Some(activity) = &mut workspace.interactor.maybe_activity() { } else if let Some(activity) = &mut workspace.interactor.maybe_activity() {
if activity.obstacles().contains(&primitive) { if activity.obstacles().contains(&primitive) {
config.dark_theme.layers.color(board.layout().rules().layer_layername(i)).highlighted config.colors(ctx).layers.color(board.layout().rules().layer_layername(i)).highlighted
} else { } else {
config.dark_theme.layers.color(board.layout().rules().layer_layername(i)).normal config.colors(ctx).layers.color(board.layout().rules().layer_layername(i)).normal
} }
} else { } else {
config.dark_theme.layers.color(board.layout().rules().layer_layername(i)).normal config.colors(ctx).layers.color(board.layout().rules().layer_layername(i)).normal
}; };
painter.paint_primitive(&shape, color); painter.paint_primitive(&shape, color);
@ -112,9 +111,9 @@ impl Viewport {
.selection() .selection()
.contains_node(board, GenericNode::Compound(poly.into())) .contains_node(board, GenericNode::Compound(poly.into()))
{ {
config.dark_theme.layers.color(board.layout().rules().layer_layername(i)).highlighted config.colors(ctx).layers.color(board.layout().rules().layer_layername(i)).highlighted
} else { } else {
config.dark_theme.layers.color(board.layout().rules().layer_layername(i)).normal config.colors(ctx).layers.color(board.layout().rules().layer_layername(i)).normal
}; };
painter.paint_polygon(&board.layout().poly(poly).shape().polygon, color) painter.paint_polygon(&board.layout().poly(poly).shape().polygon, color)

View File

@ -4,14 +4,10 @@ use std::{
}; };
use topola::{ use topola::{
autorouter::{history::History, invoker::Invoker, Autorouter}, autorouter::history::History,
interactor::{ interactor::{activity::InteractiveInput, Interactor},
activity::{ActivityContext, ActivityStepperWithStatus, InteractiveInput},
Interactor,
},
layout::LayoutEdit, layout::LayoutEdit,
specctra::{design::SpecctraDesign, mesadata::SpecctraMesadata}, specctra::{design::SpecctraDesign, mesadata::SpecctraMesadata},
stepper::Step,
}; };
use crate::{ use crate::{