forked from 1b-agent/opencadstudio-upstream
fix(layers): carry layer name instead of row index in Message::Layer*
Closes the view-to-dispatch resort race: the nine Layer* variants plus ColorPickTarget::Layer now carry the layer name and resolve to the current panel row at dispatch time via layer_panel_index; unknown names no-op. View sites (layer panel, ribbon dropdown) and the CLI/plugin path send names, so the CLI position lookup and the ribbon enumerate are deleted. Panel-internal selection state stays index-based. Tests: layer_toggle_visible_targets_layer_by_name_after_resort pins name targeting across a re-sort; layer_toggle_visible_unknown_name_is_noop pins the graceful no-op. Full suite: 1974 passed / 0 failed / 25 ignored.
This commit is contained in:
1 parent
c5f8eb2921
commit
5f016e1192
7 files changed
+186
-52
No files matched your search
@@ -992,11 +992,10 @@ impl Ribbon {
|
||||
let rows: Vec<Element<Message>> = self
|
||||
.layer_infos
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, info)| {
|
||||
.filter(|info| {
|
||||
filter.is_empty() || info.name.to_lowercase().contains(&filter)
|
||||
})
|
||||
.map(|(index, info)| {
|
||||
.map(|info| {
|
||||
let is_active = info.name == self.active_layer;
|
||||
let lc = info.color;
|
||||
let lv = info.visible;
|
||||
@@ -1019,15 +1018,15 @@ impl Ribbon {
|
||||
|
||||
let vis = icon_btn(
|
||||
crate::ui::icons::layer_visible(lv),
|
||||
Message::LayerToggleVisible(index),
|
||||
Message::LayerToggleVisible(info.name.clone()),
|
||||
);
|
||||
let freeze = icon_btn(
|
||||
crate::ui::icons::layer_freeze(lf),
|
||||
Message::LayerToggleFreeze(index),
|
||||
Message::LayerToggleFreeze(info.name.clone()),
|
||||
);
|
||||
let lock = icon_btn(
|
||||
crate::ui::icons::layer_lock(ll),
|
||||
Message::LayerToggleLock(index),
|
||||
Message::LayerToggleLock(info.name.clone()),
|
||||
);
|
||||
let checkmark: Element<'_, Message> =
|
||||
crate::ui::icons::themed_check_cell(is_active);
|
||||
|
||||
+14
-10
@@ -673,6 +673,9 @@ fn layer_row<'a>(
|
||||
vp_cols: &'a [VpCol],
|
||||
name_col_w: f32,
|
||||
) -> Element<'a, Message> {
|
||||
// #22: messages carry the layer name (resolved at dispatch time) so a
|
||||
// resort between view() and the handler cannot mistarget the row.
|
||||
let lname = layer.name.clone();
|
||||
let svg_btn = |bytes: &'static [u8], on_press: Message| -> Element<'a, Message> {
|
||||
button(crate::ui::icons::semantic(bytes, ICON_SZ))
|
||||
.on_press(on_press)
|
||||
@@ -703,7 +706,7 @@ fn layer_row<'a>(
|
||||
};
|
||||
|
||||
let plot_btn: Element<'_, Message> = button(plot_icon)
|
||||
.on_press(Message::LayerTogglePlot(index))
|
||||
.on_press(Message::LayerTogglePlot(lname.clone()))
|
||||
.style(cell_button_style(is_selected, index))
|
||||
.padding(Padding {
|
||||
top: COMBO_PAD_V,
|
||||
@@ -742,7 +745,7 @@ fn layer_row<'a>(
|
||||
text(crate::ui::text_util::elide(&layer.name, name_budget))
|
||||
.size(FONT_SZ),
|
||||
)
|
||||
.on_press(Message::LayerRenameStart(index))
|
||||
.on_press(Message::LayerRenameStart(lname.clone()))
|
||||
.style(cell_button_style(is_selected, index))
|
||||
.padding(Padding {
|
||||
top: COMBO_PAD_V,
|
||||
@@ -774,9 +777,9 @@ fn layer_row<'a>(
|
||||
..Default::default()
|
||||
},
|
||||
Message::LayerColorSet,
|
||||
Message::LayerColorPickerToggle(index),
|
||||
Message::LayerColorPickerToggle(lname.clone()),
|
||||
Message::OpenColorWindow(
|
||||
crate::app::ColorPickTarget::Layer(index),
|
||||
crate::app::ColorPickTarget::Layer(lname.clone()),
|
||||
layer.color,
|
||||
),
|
||||
))
|
||||
@@ -841,8 +844,9 @@ fn layer_row<'a>(
|
||||
|
||||
// Transparency cell
|
||||
let trans_str = layer.transparency.to_string();
|
||||
let lname_trans = lname.clone();
|
||||
let trans_cell = text_input("0", &trans_str)
|
||||
.on_input(move |s| Message::LayerTransparencyEdit(index, s))
|
||||
.on_input(move |s| Message::LayerTransparencyEdit(lname_trans.clone(), s))
|
||||
.size(FONT_SZ)
|
||||
.padding(Padding {
|
||||
top: COMBO_PAD_V,
|
||||
@@ -864,13 +868,13 @@ fn layer_row<'a>(
|
||||
.align_y(iced::Center),
|
||||
name_cell,
|
||||
iced::widget::Space::new().width(2),
|
||||
container(svg_btn(vis_svg, Message::LayerToggleVisible(index)))
|
||||
container(svg_btn(vis_svg, Message::LayerToggleVisible(lname.clone())))
|
||||
.width(Length::Fixed(COL_ICON))
|
||||
.align_x(iced::Center),
|
||||
container(svg_btn(frz_svg, Message::LayerToggleFreeze(index)))
|
||||
container(svg_btn(frz_svg, Message::LayerToggleFreeze(lname.clone())))
|
||||
.width(Length::Fixed(COL_ICON))
|
||||
.align_x(iced::Center),
|
||||
container(svg_btn(lck_svg, Message::LayerToggleLock(index)))
|
||||
container(svg_btn(lck_svg, Message::LayerToggleLock(lname.clone())))
|
||||
.width(Length::Fixed(COL_ICON))
|
||||
.align_x(iced::Center),
|
||||
container(plot_btn)
|
||||
@@ -892,7 +896,7 @@ fn layer_row<'a>(
|
||||
row_content = row_content.push(
|
||||
container(svg_btn(
|
||||
vp_frz_svg,
|
||||
Message::LayerToggleVpFreeze(index, vp_idx),
|
||||
Message::LayerToggleVpFreeze(lname.clone(), vp_idx),
|
||||
))
|
||||
.width(Length::Fixed(COL_ICON))
|
||||
.align_x(iced::Center),
|
||||
@@ -925,7 +929,7 @@ fn layer_row<'a>(
|
||||
.height(Length::Fixed(ROW_H))
|
||||
.width(Fill),
|
||||
)
|
||||
.on_press(Message::LayerSelect(index))
|
||||
.on_press(Message::LayerSelect(lname))
|
||||
.into()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user