mirror of https://codeberg.org/topola/topola.git
egui: support displaying an arbitrary number of layers
This commit is contained in:
parent
300529ea75
commit
1cca9fe6e1
|
|
@ -1,18 +1,82 @@
|
|||
use topola::board::{mesadata::MesadataTrait, Board};
|
||||
|
||||
pub struct Layers {
|
||||
// TODO:
|
||||
// In1.Cu shall be #7fc87f (#d5ecd5 when selected).
|
||||
// In2.Cu shall be #ce7d2c (#e8c39e when selected).
|
||||
pub visible: Box<[bool]>,
|
||||
pub colors: Box<[egui::Color32]>,
|
||||
pub highlight_colors: Box<[egui::Color32]>,
|
||||
}
|
||||
|
||||
impl Layers {
|
||||
pub fn new(board: &Board<impl MesadataTrait>) -> Self {
|
||||
let layer_count = board.layout().drawing().layer_count();
|
||||
|
||||
Self {
|
||||
visible: std::iter::repeat(true)
|
||||
let visible = std::iter::repeat(true)
|
||||
.take(layer_count.try_into().unwrap() /* FIXME */)
|
||||
.collect::<Vec<_>>()
|
||||
.into_boxed_slice(),
|
||||
.into_boxed_slice();
|
||||
let colors = std::iter::repeat(egui::Color32::from_rgb(255, 255, 255))
|
||||
.enumerate()
|
||||
.map(|(i, color)| {
|
||||
if matches!(
|
||||
board
|
||||
.layout()
|
||||
.drawing()
|
||||
.rules()
|
||||
.layer_layername(i.try_into().unwrap() /* FIXME */),
|
||||
Some("F.Cu")
|
||||
) {
|
||||
egui::Color32::from_rgb(255, 52, 52)
|
||||
} else if matches!(
|
||||
board
|
||||
.layout()
|
||||
.drawing()
|
||||
.rules()
|
||||
.layer_layername(i.try_into().unwrap() /* FIXME */),
|
||||
Some("B.Cu")
|
||||
) {
|
||||
egui::Color32::from_rgb(52, 52, 255)
|
||||
} else {
|
||||
color
|
||||
}
|
||||
})
|
||||
.take(layer_count.try_into().unwrap() /* FIXME */)
|
||||
.collect::<Vec<_>>()
|
||||
.into_boxed_slice();
|
||||
let highlight_colors = std::iter::repeat(egui::Color32::from_rgb(255, 255, 255))
|
||||
.enumerate()
|
||||
.map(|(i, color)| {
|
||||
if matches!(
|
||||
board
|
||||
.layout()
|
||||
.drawing()
|
||||
.rules()
|
||||
.layer_layername(i.try_into().unwrap() /* FIXME */),
|
||||
Some("F.Cu")
|
||||
) {
|
||||
egui::Color32::from_rgb(255, 100, 100)
|
||||
} else if matches!(
|
||||
board
|
||||
.layout()
|
||||
.drawing()
|
||||
.rules()
|
||||
.layer_layername(i.try_into().unwrap() /* FIXME */),
|
||||
Some("B.Cu")
|
||||
) {
|
||||
egui::Color32::from_rgb(100, 100, 255)
|
||||
} else {
|
||||
color
|
||||
}
|
||||
})
|
||||
.take(layer_count.try_into().unwrap() /* FIXME */)
|
||||
.collect::<Vec<_>>()
|
||||
.into_boxed_slice();
|
||||
|
||||
Self {
|
||||
visible,
|
||||
colors,
|
||||
highlight_colors,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,8 +109,9 @@ impl Viewport {
|
|||
let board = invoker.autorouter().board();
|
||||
|
||||
if let Some(layers) = maybe_layers {
|
||||
if layers.visible[1] {
|
||||
for primitive in board.layout().drawing().layer_primitive_nodes(1) {
|
||||
for i in (0..layers.visible.len()).rev() {
|
||||
if layers.visible[i] {
|
||||
for primitive in board.layout().drawing().layer_primitive_nodes(i.try_into().unwrap() /* FIXME */) {
|
||||
let shape = primitive.primitive(board.layout().drawing()).shape();
|
||||
|
||||
let color = if shared_data.highlighteds.contains(&primitive)
|
||||
|
|
@ -118,10 +119,11 @@ impl Viewport {
|
|||
.selection()
|
||||
.contains_node(board, GenericNode::Primitive(primitive))
|
||||
{
|
||||
egui::Color32::from_rgb(100, 100, 255)
|
||||
layers.highlight_colors[i]
|
||||
} else {
|
||||
egui::Color32::from_rgb(52, 52, 200)
|
||||
layers.colors[i]
|
||||
};
|
||||
|
||||
painter.paint_primitive(&shape, color);
|
||||
}
|
||||
|
||||
|
|
@ -130,41 +132,14 @@ impl Viewport {
|
|||
.selection()
|
||||
.contains_node(board, GenericNode::Compound(zone.into()))
|
||||
{
|
||||
egui::Color32::from_rgb(100, 100, 255)
|
||||
layers.highlight_colors[i]
|
||||
} else {
|
||||
egui::Color32::from_rgb(52, 52, 200)
|
||||
layers.colors[i]
|
||||
};
|
||||
|
||||
painter.paint_polygon(&board.layout().zone(zone).shape().polygon, color)
|
||||
}
|
||||
}
|
||||
|
||||
if layers.visible[0] {
|
||||
for primitive in board.layout().drawing().layer_primitive_nodes(0) {
|
||||
let shape = primitive.primitive(board.layout().drawing()).shape();
|
||||
|
||||
let color = if shared_data.highlighteds.contains(&primitive)
|
||||
|| overlay
|
||||
.selection()
|
||||
.contains_node(board, GenericNode::Primitive(primitive))
|
||||
{
|
||||
egui::Color32::from_rgb(255, 100, 100)
|
||||
} else {
|
||||
egui::Color32::from_rgb(200, 52, 52)
|
||||
};
|
||||
painter.paint_primitive(&shape, color);
|
||||
}
|
||||
|
||||
for zone in board.layout().layer_zone_nodes(0) {
|
||||
let color = if overlay
|
||||
.selection()
|
||||
.contains_node(board, GenericNode::Compound(zone.into()))
|
||||
{
|
||||
egui::Color32::from_rgb(255, 100, 100)
|
||||
} else {
|
||||
egui::Color32::from_rgb(200, 52, 52)
|
||||
};
|
||||
painter.paint_polygon(&board.layout().zone(zone).shape().polygon, color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue