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};
|
use topola::board::{mesadata::MesadataTrait, Board};
|
||||||
|
|
||||||
pub struct Layers {
|
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 visible: Box<[bool]>,
|
||||||
|
pub colors: Box<[egui::Color32]>,
|
||||||
|
pub highlight_colors: Box<[egui::Color32]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Layers {
|
impl Layers {
|
||||||
pub fn new(board: &Board<impl MesadataTrait>) -> Self {
|
pub fn new(board: &Board<impl MesadataTrait>) -> Self {
|
||||||
let layer_count = board.layout().drawing().layer_count();
|
let layer_count = board.layout().drawing().layer_count();
|
||||||
|
let visible = std::iter::repeat(true)
|
||||||
|
.take(layer_count.try_into().unwrap() /* FIXME */)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.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 {
|
Self {
|
||||||
visible: std::iter::repeat(true)
|
visible,
|
||||||
.take(layer_count.try_into().unwrap() /* FIXME */)
|
colors,
|
||||||
.collect::<Vec<_>>()
|
highlight_colors,
|
||||||
.into_boxed_slice(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,61 +109,36 @@ impl Viewport {
|
||||||
let board = invoker.autorouter().board();
|
let board = invoker.autorouter().board();
|
||||||
|
|
||||||
if let Some(layers) = maybe_layers {
|
if let Some(layers) = maybe_layers {
|
||||||
if layers.visible[1] {
|
for i in (0..layers.visible.len()).rev() {
|
||||||
for primitive in board.layout().drawing().layer_primitive_nodes(1) {
|
if layers.visible[i] {
|
||||||
let shape = primitive.primitive(board.layout().drawing()).shape();
|
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)
|
let color = if shared_data.highlighteds.contains(&primitive)
|
||||||
|| overlay
|
|| overlay
|
||||||
|
.selection()
|
||||||
|
.contains_node(board, GenericNode::Primitive(primitive))
|
||||||
|
{
|
||||||
|
layers.highlight_colors[i]
|
||||||
|
} else {
|
||||||
|
layers.colors[i]
|
||||||
|
};
|
||||||
|
|
||||||
|
painter.paint_primitive(&shape, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
for zone in board.layout().layer_zone_nodes(1) {
|
||||||
|
let color = if overlay
|
||||||
.selection()
|
.selection()
|
||||||
.contains_node(board, GenericNode::Primitive(primitive))
|
.contains_node(board, GenericNode::Compound(zone.into()))
|
||||||
{
|
{
|
||||||
egui::Color32::from_rgb(100, 100, 255)
|
layers.highlight_colors[i]
|
||||||
} else {
|
} else {
|
||||||
egui::Color32::from_rgb(52, 52, 200)
|
layers.colors[i]
|
||||||
};
|
};
|
||||||
painter.paint_primitive(&shape, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
for zone in board.layout().layer_zone_nodes(1) {
|
painter.paint_polygon(&board.layout().zone(zone).shape().polygon, color)
|
||||||
let color = if overlay
|
}
|
||||||
.selection()
|
|
||||||
.contains_node(board, GenericNode::Compound(zone.into()))
|
|
||||||
{
|
|
||||||
egui::Color32::from_rgb(100, 100, 255)
|
|
||||||
} else {
|
|
||||||
egui::Color32::from_rgb(52, 52, 200)
|
|
||||||
};
|
|
||||||
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