forked from 1b-agent/opencadstudio-upstream
feat(layers): alphabetical default order + scroll to a new layer
The Layer Manager table and the ribbon's quick layer dropdown both showed layers in document (insertion) order. Default the panel sort to Name so both list layers alphabetically; a header click still re-sorts by any other column. `apply_sort` reorders the panel's layer vector in place, which the ribbon dropdown reads, so one default covers both. With alphabetical ordering a freshly created layer can land anywhere in a long list, so give the table scrollable an id and scroll its row into view after creation, keeping the rename prompt visible. Closes #270, closes #271 Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
450dbf79ac
commit
d644a85c72
2 files changed
+27
-3
No files matched your search
@@ -635,7 +635,23 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
|
||||
self.tabs[i].layers.edit_buf = new_name.clone();
|
||||
}
|
||||
self.sync_ribbon_layers();
|
||||
Task::none()
|
||||
// With alphabetical ordering (#270) the new layer can land
|
||||
// anywhere in a long list; scroll its row into view so the
|
||||
// rename prompt is visible (#271). Offset is layout-independent
|
||||
// (idx × fixed row height), so it holds even before the freshly
|
||||
// added row is measured.
|
||||
match new_idx {
|
||||
Some(idx) => iced::widget::operation::scroll_to(
|
||||
iced::advanced::widget::Id::new(
|
||||
crate::ui::window::layers::LAYER_TABLE_SCROLL_ID,
|
||||
),
|
||||
iced::widget::scrollable::AbsoluteOffset {
|
||||
x: 0.0,
|
||||
y: idx as f32 * crate::ui::ROW_H,
|
||||
},
|
||||
),
|
||||
None => Task::none(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_layer_delete(&mut self) -> Task<Message> {
|
||||
|
||||
+10
-2
@@ -43,6 +43,9 @@ const ICON_SZ: f32 = ROW_H * 0.62; // ≈16 px at ROW_H=26
|
||||
const FONT_SZ: f32 = ROW_H * 0.42; // ≈11 px at ROW_H=26
|
||||
/// Vertical padding for combo_box / text_input so their total height = ROW_H.
|
||||
const COMBO_PAD_V: f32 = (ROW_H - FONT_SZ * 1.3 - 2.0) / 2.0;
|
||||
/// Widget id for the layer-table scrollable, so a freshly created layer can be
|
||||
/// scrolled into view after it is added (#271).
|
||||
pub const LAYER_TABLE_SCROLL_ID: &str = "layer-manager-table-scroll";
|
||||
|
||||
// ── Layer data ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -127,7 +130,10 @@ impl Default for LayerPanel {
|
||||
}]),
|
||||
lw_combo: combo_box::State::new(lw_options()),
|
||||
vp_cols: vec![],
|
||||
sort_col: None,
|
||||
// Default to alphabetical (Name) order in both the Layer Manager
|
||||
// table and the ribbon's quick layer dropdown (#270). A header
|
||||
// click still re-sorts by any other column.
|
||||
sort_col: Some(LayerSortCol::Name),
|
||||
sort_asc: true,
|
||||
}
|
||||
}
|
||||
@@ -384,7 +390,9 @@ impl LayerPanel {
|
||||
|
||||
}
|
||||
|
||||
let table = scrollable(rows_col).height(Fill);
|
||||
let table = scrollable(rows_col)
|
||||
.id(iced::advanced::widget::Id::new(LAYER_TABLE_SCROLL_ID))
|
||||
.height(Fill);
|
||||
|
||||
// ── Full-window frame ─────────────────────────────────────────────
|
||||
container(column![toolbar, col_header, table].spacing(0))
|
||||
|
||||
Reference in new issue
Block a user