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)]
#[serde(default)]
pub struct Config {
pub dark_theme: Colors,
pub light_theme: Colors,
dark_colors: 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)]
@ -34,7 +43,8 @@ pub struct LayerColor {
impl Default for Config {
fn default() -> Self {
let dark_theme = Colors {
Self {
dark_colors: Colors {
layers: LayerColors {
default: LayerColor {
normal: egui::Color32::from_rgb(255, 255, 255),
@ -85,11 +95,59 @@ impl Default for Config {
),
]),
},
};
Self {
dark_theme: dark_theme.clone(),
light_theme: dark_theme,
},
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(
&mut self,
ctx: &egui::Context,
_ctx: &egui::Context,
ui: &mut egui::Ui,
tr: &Translator,
viewport: &mut Viewport,

View File

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

View File

@ -17,7 +17,6 @@ use topola::{
geometry::{shape::AccessShape, GenericNode},
layout::{poly::MakePolyShape, via::ViaWeight},
math::Circle,
specctra::mesadata::SpecctraMesadata,
};
use crate::{config::Config, menu_bar::MenuBar, painter::Painter, workspace::Workspace};
@ -93,15 +92,15 @@ impl Viewport {
.selection()
.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() {
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 {
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 {
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);
@ -112,9 +111,9 @@ impl Viewport {
.selection()
.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 {
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)

View File

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