brep_app/panels/
pick_bar.rs1use crate::automation::hit_keys::HitKeyDoc;
20use brep_render::engine_state::EngineState;
21use eframe::egui;
22use std::collections::HashMap;
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum PickLayout {
27 Idle,
29 InForm,
31 Focused,
34 Modal,
37}
38
39impl PickLayout {
40 pub fn of(active: bool, in_form: bool, narrow: bool) -> Self {
41 match (active, in_form, narrow) {
42 (false, _, _) => Self::Idle,
43 (true, false, _) => Self::Modal,
44 (true, true, false) => Self::InForm,
45 (true, true, true) => Self::Focused,
46 }
47 }
48
49 pub fn shows_dock(self) -> bool {
51 matches!(self, Self::Idle | Self::InForm)
52 }
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57enum Action {
58 Finish,
59 Cancel,
60 Remove(usize),
61}
62
63#[derive(Default)]
64pub struct PickBar {
65 hits: HashMap<String, egui::Rect>,
66 shown: Option<(String, usize)>,
68}
69
70impl PickBar {
71 pub fn new() -> Self {
72 Self::default()
73 }
74
75 pub fn show(
79 &mut self,
80 ctx: &egui::Context,
81 view: egui::Rect,
82 state: &mut EngineState,
83 filter: &mut crate::panels::selection::SelectionPanel,
84 ) {
85 self.hits.clear();
86 self.shown = None;
87 let Some(field) = state.ref_select_field() else {
88 return;
89 };
90 state.ref_select_claim();
91 let label = state.ref_select_label();
92 let hint = if state.ref_select_is_sheet() {
93 "Tap an anchor marked on the sheet to pick; drag to pan."
94 } else if field.multiple {
95 "Tap in the view to add picks; drag to orbit. Finish when done."
96 } else {
97 "Tap in the view to pick; drag to orbit."
98 };
99 let width = (view.width() - 16.0).max(120.0);
100 let mut action = None;
101 egui::Area::new(egui::Id::new("brep-pick-bar"))
102 .order(egui::Order::Foreground)
103 .fixed_pos(view.left_top() + egui::vec2(8.0, 8.0))
104 .movable(false)
105 .show(ctx, |ui| {
106 let frame = egui::Frame::popup(ui.style()).show(ui, |ui| {
107 ui.set_width(width - 16.0);
108 ui.horizontal_wrapped(|ui| {
109 ui.label(egui::RichText::new(format!("Select: {label}")).strong());
110 ui.label(egui::RichText::new(format!("{} picked", field.names.len())).weak());
111 });
112 ui.label(egui::RichText::new(hint).weak().small());
113 ui.horizontal_wrapped(|ui| {
118 let finish = ui.button("Finish").on_hover_text("Put the picks in the field and return to the dialog");
119 self.hits.insert("finish".into(), finish.rect);
120 if finish.clicked() {
121 action = Some(Action::Finish);
122 }
123 let cancel = ui.button("Cancel").on_hover_text("Return to the dialog with the field unchanged");
124 self.hits.insert("cancel".into(), cancel.rect);
125 if cancel.clicked() {
126 action = Some(Action::Cancel);
127 }
128 filter.show_filter_bar(ui, state);
129 });
130 if !field.names.is_empty() {
131 egui::ScrollArea::vertical().id_salt("pick-bar-picks").max_height(96.0).show(ui, |ui| {
132 ui.horizontal_wrapped(|ui| {
133 for (i, name) in field.names.iter().enumerate() {
134 let chip = ui.add(egui::Button::new(format!("{name} \u{2716}")).small())
135 .on_hover_text("Remove this pick");
136 self.hits.insert(format!("x{i}"), chip.rect);
137 if chip.clicked() {
138 action = Some(Action::Remove(i));
139 }
140 }
141 });
142 });
143 }
144 });
145 self.hits.insert("bar".into(), frame.response.rect);
146 });
147 self.shown = Some((label, field.names.len()));
148 match action {
149 Some(Action::Finish) => state.finish_ref_select(),
150 Some(Action::Cancel) => state.cancel_ref_select(),
151 Some(Action::Remove(i)) => state.ref_select_remove(i),
152 None => {}
153 }
154 if action.is_some() {
155 ctx.request_repaint();
156 }
157 }
158
159 pub fn clear_hits(&mut self) {
161 self.hits.clear();
162 self.shown = None;
163 }
164
165 pub fn hits_json(&self) -> String {
166 crate::automation::hit_rects::hits_json(&self.hits)
167 }
168
169 pub fn state_json(&self) -> String {
171 serde_json::json!({
172 "shown": self.shown.is_some(),
173 "label": self.shown.as_ref().map(|(label, _)| label),
174 "count": self.shown.as_ref().map(|(_, count)| count),
175 })
176 .to_string()
177 }
178}
179
180pub static HIT_KEYS: &[HitKeyDoc] = &[
182 HitKeyDoc { panel: "pickbar", prefix: "bar", meaning: "the focused pick bar a touch or narrow window shows over the full-window view while a dialog's reference field picks (every other piece of chrome is hidden; the filter button rides in the bar)", command: None },
183 HitKeyDoc { panel: "pickbar", prefix: "finish", meaning: "put the picks in the field and return to the dialog", command: None },
184 HitKeyDoc { panel: "pickbar", prefix: "cancel", meaning: "return to the dialog with the field unchanged (Escape does the same)", command: None },
185 HitKeyDoc { panel: "pickbar", prefix: "x", meaning: "remove the i-th running pick (xi)", command: None },
186];
187