feat(statusbar): selection cycling shows a pick list, adds to selection
Replace the repeat-click cycling with a list box: when a click lands on two or more overlapping objects (cycling on), a small list of the candidates opens at the cursor. Picking a row adds that object to the current selection (accumulate); clicking outside dismisses it. A single object under the cursor falls through to the normal click. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
ac042c5dbf
commit
bcbda65746
5 changed files with 137 additions and 28 deletions
|
|
@ -183,11 +183,11 @@ pub(super) struct OpenCADStudio {
|
|||
clean_screen: bool,
|
||||
/// Quick Properties: show a compact floating property panel on selection.
|
||||
quick_properties: bool,
|
||||
/// Selection cycling: repeated clicks at one spot step through the
|
||||
/// overlapping objects there instead of accumulating the selection.
|
||||
/// Selection cycling: clicking where objects overlap opens a list box
|
||||
/// to pick which one; the pick is added to the current selection.
|
||||
selection_cycling: bool,
|
||||
/// Cycling cursor: (screen point, ordered candidates, current index).
|
||||
cycle_state: Option<(iced::Point, Vec<acadrust::Handle>, usize)>,
|
||||
/// When set, the cycling list box is open: (canvas point, candidates).
|
||||
cycle_candidates: Option<(iced::Point, Vec<acadrust::Handle>)>,
|
||||
/// Which status-bar pills the user has chosen to show (persisted).
|
||||
statusbar_config: crate::ui::statusbar_config::StatusBarConfig,
|
||||
/// Whether Tangent snap was enabled before a tangent-pick command started.
|
||||
|
|
@ -765,6 +765,10 @@ pub enum Message {
|
|||
ToggleQuickProperties,
|
||||
/// Toggle selection cycling for overlapping objects.
|
||||
ToggleSelectionCycling,
|
||||
/// Add an object from the selection-cycling list box to the selection.
|
||||
CycleSelect(acadrust::Handle),
|
||||
/// Dismiss the selection-cycling list box without picking.
|
||||
CycleCancel,
|
||||
/// Toggle the selection-filter type picker open/closed.
|
||||
ToggleSelectionFilterPopup,
|
||||
/// Close the selection-filter type picker.
|
||||
|
|
@ -1245,7 +1249,7 @@ impl OpenCADStudio {
|
|||
clean_screen: false,
|
||||
quick_properties: false,
|
||||
selection_cycling: false,
|
||||
cycle_state: None,
|
||||
cycle_candidates: None,
|
||||
pre_cmd_tangent: None,
|
||||
ortho_mode: false,
|
||||
polar_mode: false,
|
||||
|
|
|
|||
|
|
@ -2910,9 +2910,11 @@ impl OpenCADStudio {
|
|||
let all_wires = self.tabs[i].scene.hit_test_wires();
|
||||
let vp_mat = self.tabs[i].scene.camera.borrow().view_proj(bounds);
|
||||
|
||||
// Selection cycling: step through overlapping objects
|
||||
// under the cursor on repeated clicks at the same spot.
|
||||
// Gated behind the toggle, so default picking is unchanged.
|
||||
// Selection cycling: where two or more objects
|
||||
// overlap, open a list box to pick which one; a
|
||||
// single object falls through to the normal click.
|
||||
// Gated behind the toggle, so default picking is
|
||||
// unchanged when off.
|
||||
let mut handled_by_cycling = false;
|
||||
if self.selection_cycling {
|
||||
let cands: Vec<Handle> = scene::hit_test::click_hits_all(
|
||||
|
|
@ -2925,25 +2927,9 @@ impl OpenCADStudio {
|
|||
.filter_map(|s| Scene::handle_from_wire_name(s))
|
||||
.filter(|&h| self.tabs[i].scene.passes_selection_filter(h))
|
||||
.collect();
|
||||
if !cands.is_empty() {
|
||||
let same =
|
||||
self.cycle_state.as_ref().map_or(false, |(pt, list, _)| {
|
||||
(pt.x - p.x).abs() < 3.0
|
||||
&& (pt.y - p.y).abs() < 3.0
|
||||
&& *list == cands
|
||||
});
|
||||
let idx = if same {
|
||||
(self.cycle_state.as_ref().unwrap().2 + 1) % cands.len()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let handle = cands[idx];
|
||||
self.cycle_state = Some((p, cands, idx));
|
||||
self.tabs[i].scene.deselect_all();
|
||||
self.tabs[i].scene.select_entity(handle, false);
|
||||
self.tabs[i].scene.expand_selection_for_groups(&[handle]);
|
||||
self.refresh_properties();
|
||||
selection_just_completed = true;
|
||||
if cands.len() >= 2 {
|
||||
// Overlap: open the list box at the cursor.
|
||||
self.cycle_candidates = Some((p_full, cands));
|
||||
handled_by_cycling = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -3644,7 +3630,20 @@ impl OpenCADStudio {
|
|||
}
|
||||
Message::ToggleSelectionCycling => {
|
||||
self.selection_cycling ^= true;
|
||||
self.cycle_state = None;
|
||||
self.cycle_candidates = None;
|
||||
Task::none()
|
||||
}
|
||||
Message::CycleSelect(handle) => {
|
||||
// Add the picked object to the current selection (accumulate).
|
||||
self.cycle_candidates = None;
|
||||
let i = self.active_tab;
|
||||
self.tabs[i].scene.select_entity(handle, false);
|
||||
self.tabs[i].scene.expand_selection_for_groups(&[handle]);
|
||||
self.refresh_properties();
|
||||
Task::none()
|
||||
}
|
||||
Message::CycleCancel => {
|
||||
self.cycle_candidates = None;
|
||||
Task::none()
|
||||
}
|
||||
Message::ToggleSelectionFilterPopup => {
|
||||
|
|
|
|||
|
|
@ -1014,6 +1014,24 @@ impl OpenCADStudio {
|
|||
}
|
||||
}
|
||||
|
||||
// Selection-cycling list box: pick among overlapping objects.
|
||||
if let Some((pt, cands)) = &self.cycle_candidates {
|
||||
if !tab.is_start {
|
||||
let items: Vec<(acadrust::Handle, String)> = cands
|
||||
.iter()
|
||||
.filter_map(|&h| {
|
||||
tab.scene.document.get_entity(h).map(|e| {
|
||||
(h, crate::entities::traits::entity_type_name(e).to_string())
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
if !items.is_empty() {
|
||||
viewport_stack = viewport_stack
|
||||
.push(crate::ui::cycle_popup::cycle_popup_overlay(*pt, items));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Right-click context menu. Lives inside the viewport stack so
|
||||
// the cursor position (canvas-relative) anchors the menu under
|
||||
// the cursor instead of drifting into window-relative space.
|
||||
|
|
|
|||
87
src/ui/cycle_popup.rs
Normal file
87
src/ui/cycle_popup.rs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
//! Selection-cycling list box — shown at the cursor when a click lands on
|
||||
//! two or more overlapping objects. Each row names a candidate; clicking it
|
||||
//! adds that object to the current selection. Clicking outside dismisses it.
|
||||
|
||||
use iced::widget::{button, column, container, mouse_area, opaque, row, text, Space};
|
||||
use iced::{Background, Border, Color, Element, Fill, Length, Theme};
|
||||
|
||||
use crate::app::Message;
|
||||
|
||||
/// Full-canvas overlay: the list box anchored at `anchor` (canvas
|
||||
/// coordinates) plus a transparent click-catcher that cancels.
|
||||
pub fn cycle_popup_overlay(
|
||||
anchor: iced::Point,
|
||||
items: Vec<(acadrust::Handle, String)>,
|
||||
) -> Element<'static, Message> {
|
||||
let rows: Vec<Element<'static, Message>> = items
|
||||
.into_iter()
|
||||
.map(|(handle, label)| item_row(label, Message::CycleSelect(handle)))
|
||||
.collect();
|
||||
|
||||
let panel = container(column(rows))
|
||||
.style(|_: &Theme| container::Style {
|
||||
background: Some(Background::Color(PANEL_BG)),
|
||||
border: Border {
|
||||
color: PANEL_BORDER,
|
||||
width: 1.0,
|
||||
radius: 3.0.into(),
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.width(Length::Fixed(150.0));
|
||||
|
||||
let positioned = column![
|
||||
Space::new().height(Length::Fixed(anchor.y.max(0.0))),
|
||||
row![
|
||||
Space::new().width(Length::Fixed(anchor.x.max(0.0))),
|
||||
opaque(panel),
|
||||
],
|
||||
]
|
||||
.width(Fill)
|
||||
.height(Fill);
|
||||
|
||||
mouse_area(positioned).on_press(Message::CycleCancel).into()
|
||||
}
|
||||
|
||||
fn item_row(label: String, msg: Message) -> Element<'static, Message> {
|
||||
let content = text(label).size(11).color(LABEL).align_y(iced::Center);
|
||||
button(content)
|
||||
.on_press(msg)
|
||||
.style(|_: &Theme, status| button::Style {
|
||||
background: Some(Background::Color(match status {
|
||||
button::Status::Hovered => ROW_HOVER,
|
||||
_ => Color::TRANSPARENT,
|
||||
})),
|
||||
..Default::default()
|
||||
})
|
||||
.width(Fill)
|
||||
.padding([4, 10])
|
||||
.into()
|
||||
}
|
||||
|
||||
// ── Colours ───────────────────────────────────────────────────────────────
|
||||
|
||||
const PANEL_BG: Color = Color {
|
||||
r: 0.15,
|
||||
g: 0.15,
|
||||
b: 0.15,
|
||||
a: 1.0,
|
||||
};
|
||||
const PANEL_BORDER: Color = Color {
|
||||
r: 0.32,
|
||||
g: 0.32,
|
||||
b: 0.32,
|
||||
a: 1.0,
|
||||
};
|
||||
const ROW_HOVER: Color = Color {
|
||||
r: 0.22,
|
||||
g: 0.45,
|
||||
b: 0.62,
|
||||
a: 1.0,
|
||||
};
|
||||
const LABEL: Color = Color {
|
||||
r: 0.92,
|
||||
g: 0.92,
|
||||
b: 0.92,
|
||||
a: 1.0,
|
||||
};
|
||||
|
|
@ -7,6 +7,7 @@ pub mod app_menu;
|
|||
pub mod isolate_popup;
|
||||
pub mod update_notice;
|
||||
pub mod command_line;
|
||||
pub mod cycle_popup;
|
||||
pub mod dimstyle;
|
||||
pub mod layers;
|
||||
pub mod layout_manager;
|
||||
|
|
|
|||
Loading…
Reference in a new issue