mirror of https://codeberg.org/topola/topola.git
feat(egui): have a separate layout color theme for light mode
This commit is contained in:
parent
a5503de0a2
commit
0184a6537e
|
|
@ -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,7 +43,8 @@ pub struct LayerColor {
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let dark_theme = Colors {
|
Self {
|
||||||
|
dark_colors: Colors {
|
||||||
layers: LayerColors {
|
layers: LayerColors {
|
||||||
default: LayerColor {
|
default: LayerColor {
|
||||||
normal: egui::Color32::from_rgb(255, 255, 255),
|
normal: egui::Color32::from_rgb(255, 255, 255),
|
||||||
|
|
@ -85,11 +95,59 @@ impl Default for Config {
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
light_colors: Colors {
|
||||||
Self {
|
layers: LayerColors {
|
||||||
dark_theme: dark_theme.clone(),
|
default: LayerColor {
|
||||||
light_theme: dark_theme,
|
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),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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},
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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::{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue