Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 191 additions & 44 deletions crates/ui-egui/src/chrome.rs

Large diffs are not rendered by default.

640 changes: 640 additions & 0 deletions crates/ui-egui/src/inuse.rs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mod geometrycalc;
mod globe_drape;
mod graphicformat;
pub mod icons;
mod inuse;
mod keymap;
mod labelfonts;
mod labelpane;
Expand Down Expand Up @@ -1014,6 +1015,8 @@ pub struct UiState {
pub tab_strip_rect: Option<egui::Rect>,
/// Where the left and right panes were drawn on the last frame, while they show.
pub pane_rects: [Option<egui::Rect>; 2],
/// The pane the user is working in, for the keys that act on it.
pub(crate) in_use: inuse::InUse,
/// Tabs hidden from the ribbon (Settings › Customize › Ribbon).
pub hidden_tabs: Vec<String>,
/// Extra Quick Access Toolbar commands.
Expand Down Expand Up @@ -1276,6 +1279,7 @@ impl Default for UiState {
shortcut_preferences_full: false,
tab_strip_rect: None,
pane_rects: [None; 2],
in_use: inuse::InUse::default(),
copy_out: None,
open_url: None,
copy_image: None,
Expand Down Expand Up @@ -7551,6 +7555,8 @@ impl RustGisApp {
let t = theme::Tokens::get(&ctx);
// Before the shortcuts and the fields: the row picked in a text field's menu, as its keys.
fieldmenu::play(self, &ctx);
// Before the shortcuts: a key acts on the pane this frame's press is in.
inuse::follow(self, &ctx);
chrome::shortcuts(self, &ctx);
panes::follow_layer_filter(self);
// A Zarr summary or point series, a trend, a workflow, an export or a read running on its thread lands
Expand Down Expand Up @@ -7606,6 +7612,9 @@ impl RustGisApp {
chrome::about(self, &ctx);
#[cfg(not(target_arch = "wasm32"))]
agentthreads::windows(self, &ctx);
// The keys that follow a click of this frame, now that the panes have taken it and the
// dialogs it opened are up. Before the notices, which a key that can't run adds to.
chrome::late_keys(self, &ctx);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
chrome::notices(self, &ctx);
// After every field is drawn: one right-clicked opens its menu.
fieldmenu::show(self, &ctx);
Expand Down
8 changes: 8 additions & 0 deletions crates/ui-egui/src/mapview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) {
if app.chrome.is_none() {
view_tabs(app, ui, &t);
}
app.ui.in_use.drawn(crate::inuse::Pane::View, ui.layer_id(), ui.available_rect_before_wrap());
crate::vertexedit::cancel_stale_drag(app);
crate::vertexedit::say_unplaced(app);
if app.mb.shown() {
Expand Down Expand Up @@ -4451,6 +4452,7 @@ fn popup(app: &mut RustGisApp, ui: &mut Ui, rect: Rect) {
// Keyed by the feature: egui remembers an area's (and a scroll area's and grid's) size, and
// the next popup mustn't start from the last one's.
let key = (&layer, &title, attrs.len());
let mut drawn = None;
egui::Area::new(egui::Id::unique(("identify_popup", key))).fixed_pos(pos).order(egui::Order::Foreground).show(ui.ctx(), |ui| {
let frame = egui::Frame::NONE
.fill(t.menu)
Expand Down Expand Up @@ -4636,7 +4638,12 @@ fn popup(app: &mut RustGisApp, ui: &mut Ui, rect: Rect) {
new_limit = Some(vec2(limit.x + d.x, r.height() + d.y).clamp(vec2(240.0, 120.0), space));
}
ui.ctx().data_mut(|d| d.insert_temp(shown_id, r.height()));
drawn = Some((ui.layer_id(), r));
});
// The pop-up is the map's: a press in it leaves the layer list, as one on the map does.
if let Some((layer, r)) = drawn {
app.ui.in_use.drawn(crate::inuse::Pane::View, layer, r);
}
if let Some(l) = new_limit {
ui.ctx().data_mut(|d| d.insert_temp(limit_id, l));
}
Expand Down Expand Up @@ -4815,6 +4822,7 @@ fn next_view_tab(ui: &mut Ui, w: f32) -> Rect {
/// is always in sight.
fn view_tabs(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) {
let (r, _) = ui.allocate_exact_size(vec2(ui.available_width(), 30.0), Sense::hover());
app.ui.in_use.drawn(crate::inuse::Pane::Tabs, ui.layer_id(), r);
ui.painter().rect_filled(r, 0.0, t.tab_strip);
ui.painter().line_segment([pos2(r.min.x, r.max.y - 0.5), pos2(r.max.x, r.max.y - 0.5)], Stroke::new(1.0, t.border));
// The tabs take the strip but the New Map button's room and the gaps around it.
Expand Down
70 changes: 67 additions & 3 deletions crates/ui-egui/src/modelbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ impl ModelBuilder {
self.open && self.active
}

/// Whether a question about unsaved changes is up, or about to be drawn.
pub fn asking(&self) -> bool {
self.confirm.is_some()
}

/// Whether the canvas has changes not saved to the project.
pub fn dirty(&self) -> bool {
self.graph != self.saved || self.saved_as.as_deref().is_some_and(|s| s != self.name.trim())
Expand Down Expand Up @@ -587,19 +592,29 @@ fn request(app: &mut RustGisApp, p: Pending) {
}

/// ModelBuilder's keys, before the app's own: Delete (or Backspace) deletes the selection,
/// Ctrl+D duplicates the selected node, Ctrl+Z and Ctrl+Y undo and redo canvas edits.
/// Ctrl+D duplicates the selected node, Ctrl+Z and Ctrl+Y undo and redo canvas edits. With the
/// layer list in use, Delete and Backspace are left for it.
pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) {
if !app.mb.shown() || ctx.egui_wants_keyboard_input() {
return;
}
let cmd = egui::Modifiers::COMMAND;
// The pane in use as the key went down: the wheel turned over the canvas after it doesn't
// make the key the canvas's, on the same frame or while the key is held (its repeats are the
// pane's it was pressed in, as in `chrome::shortcuts`).
let layers = |key| {
let pressed_in = crate::inuse::press(app, key, None).map(|press| press.pane).or_else(|| crate::inuse::held_in(app, key));
pressed_in.unwrap_or_else(|| crate::inuse::pane(app)) == crate::inuse::Pane::Layers
};
Comment thread
Mavrick-F marked this conversation as resolved.
Resolved
let (mut del, mut dup, mut undo, mut redo) = (false, false, false, false);
ctx.input_mut(|i| {
undo = i.consume_shortcut(&egui::KeyboardShortcut::new(cmd, egui::Key::Z));
redo = i.consume_shortcut(&egui::KeyboardShortcut::new(cmd | egui::Modifiers::SHIFT, egui::Key::Z))
|| i.consume_shortcut(&egui::KeyboardShortcut::new(cmd, egui::Key::Y));
if app.mb.selected.is_some() || app.mb.selected_edge.is_some() {
del = i.consume_key(egui::Modifiers::NONE, egui::Key::Delete) || i.consume_key(egui::Modifiers::NONE, egui::Key::Backspace);
// Nothing is deleted while a mouse button is down, as with the app's own Delete.
if (app.mb.selected.is_some() || app.mb.selected_edge.is_some()) && !crate::inuse::down(app) {
del =
[egui::Key::Delete, egui::Key::Backspace].into_iter().any(|key| !layers(key) && i.consume_key(egui::Modifiers::NONE, key));
}
if app.mb.selected.is_some() {
dup = i.consume_shortcut(&egui::KeyboardShortcut::new(cmd, egui::Key::D));
Expand Down Expand Up @@ -2120,6 +2135,55 @@ mod tests {
assert_eq!(h.state().mb.graph.nodes.len(), 3, "the canvas is kept");
}

/// A layer clicked in the list with a node selected on the canvas: Delete is the list's. It
/// removes that layer and leaves the node (#2945).
#[test]
fn delete_is_the_layer_lists_while_it_is_in_use() {
use egui_kittest::kittest::Queryable;
let mut app = RustGisApp::with_sample();
app.ui.right_open.clear();
app.ui.right = None;
app.run("ui.modelBuilder", Value::Null).unwrap();
let node = app.mb.add(&Add::Input, pos2(0.0, 0.0));
app.mb.selected = Some(node);
let layers = app.session.map().layers.len();
// The whole window: the layer list beside the canvas.
let mut h = egui_kittest::Harness::builder().with_size(vec2(1300.0, 900.0)).with_max_steps(64).build_ui_state(
|ui, app: &mut RustGisApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
app,
);
h.run_steps(6);
assert!(h.state().mb.shown());
h.get_by_label("Rivers").click();
h.run_steps(2);
h.event(Event::Key { key: Key::Delete, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
h.run_steps(2);
assert_eq!(h.state().mb.graph.nodes.len(), 1, "the node stays");
assert_eq!(h.state().session.map().layers.len(), layers - 1);
assert!(h.state().session.map().layer_by_name("Rivers").is_none(), "Delete removed the layer clicked in the list");
// The key still held, and the wheel turned over the canvas: its repeats stay the layer
// list's, and the node stays.
let canvas = pos2(800.0, 500.0);
h.event(Event::PointerMoved(canvas));
h.step();
h.event(Event::MouseWheel {
unit: egui::MouseWheelUnit::Line,
delta: vec2(0.0, 1.0),
modifiers: Modifiers::NONE,
phase: egui::TouchPhase::Move,
source: egui::MouseWheelSource::Wheel,
});
h.run_steps(2);
h.event(Event::Key { key: Key::Delete, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
h.run_steps(2);
assert_eq!(h.state().mb.graph.nodes.len(), 1, "a held Delete's repeat on the canvas leaves the node");
assert_eq!(h.state().session.map().layers.len(), layers - 1);
}

/// Closing with unsaved changes asks first; Discard closes, Cancel keeps the model open.
#[test]
fn closing_asks_about_unsaved_changes() {
Expand Down
5 changes: 4 additions & 1 deletion crates/ui-egui/src/panes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) {
let rect = ui.available_rect_before_wrap();
let mut body = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(*ui.layout()));
match left {
LeftPane::Contents => contents(app, &mut body, &t),
LeftPane::Contents => {
app.ui.in_use.drawn(crate::inuse::Pane::Layers, body.layer_id(), rect);
contents(app, &mut body, &t);
}
LeftPane::Catalog => catalog(app, &mut body, &t),
LeftPane::Sources => crate::sourcespane::show(app, &mut body, &t),
}
Expand Down
4 changes: 3 additions & 1 deletion crates/ui-egui/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) {
}
let t = Tokens::get(ui.ctx());
let pass = ui.ctx().cumulative_pass_nr();
egui::Panel::bottom("attribute_table")
let layer = ui.layer_id();
let panel = egui::Panel::bottom("attribute_table")
.resizable(true)
.default_size(250.0)
.size_range(120.0..=600.0)
Expand Down Expand Up @@ -800,6 +801,7 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) {
}
}
});
app.ui.in_use.drawn(crate::inuse::Pane::Table, layer, panel.response.rect);
statistics_window(app, ui.ctx());
}

Expand Down
9 changes: 7 additions & 2 deletions docs/user-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,19 @@ with `{"layer":"parcels"}`.
| ++ctrl+equal++ / ++ctrl+minus++ | Zoom in / out |
| ++home++ | Full extent |
| ++esc++ | Back to Explore; cancel a sketch |
| ++delete++ | Delete selected features; with Edit Vertices, the chosen vertex; in a layout, the selected element |
| ++delete++ | Delete selected features; with Edit Vertices, the chosen vertex; in a layout, the selected element; in the layer list, remove the selected layers (++backspace++ too) |
| ++ctrl+d++ | Duplicate the selected layout element |
| Arrow keys / ++shift++ + arrow keys | Nudge the selected layout element / nudge it further |
| ++alt+shift+right++ / ++alt+shift+left++ | Indent the active layer into the group above it / outdent it out of its group |
| ++alt+shift+up++ / ++alt+shift+down++ | Move the active layer up / down one step in the Layers pane |
| ++f2++ | Rename the active layer |
| ++f2++ | Rename the active layer; on the map and layout tabs, and in a layout, the map or layout in view |
| ++ctrl+c++ / ++ctrl+x++ / ++ctrl+v++ | Copy / Cut / Paste features |

On macOS, ++cmd++ takes the place of ++ctrl++. **Help › Shortcuts** lists them all in the app,
from the same table the app runs them from. While you type in a text field, undo and redo take
back its typing, not the project's last change.

++delete++ and ++f2++ act on the part of the window you last clicked, dragged or scrolled in.
Click a layer in the Layers pane and ++delete++ removes it (Undo brings it back), whatever is
selected on the map; click or scroll the map and it deletes the selected features again. When
++delete++ has nothing to act on, a notice says why.
Loading