Skip to main content

egui_pop_viewport/
navigation.rs

1//! One navigation model for every canvas larger than its view (the node
2//! graph, the image viewport, plots): what `docs/design/navigation.md`
3//! proposes, in one place so each canvas behaves the same.
4//!
5//! <div class="warning">Experimental: may change in any release
6//! (docs/stability.md).</div>
7//!
8//! - **Hand mode** ([`hand`]): H toggles it, Space held is the same for
9//!   the moment; a primary drag then pans from anywhere on the canvas,
10//!   for a pen, a touch screen or a mouse without a middle button. The
11//!   canvas shows it with the grab cursor and an indicator
12//!   ([`indicator`]).
13//! - **Navigation commands** ([`NavCommand`]): `view.fit`,
14//!   `view.frame_selection`, `view.zoom_in`, `view.zoom_out`,
15//!   `view.zoom_100`, `view.pan_left` (`_right`, `_up`, `_down`) and
16//!   `view.hand`. Their keys ([`NavKeys`]) are the pointer profile's
17//!   (its `view_keys`): on the widget alone it reads them; in an
18//!   application they are keymap bindings (shown and rebound in the
19//!   shortcuts editor), and the commands reach the canvas in use through
20//!   `egui_pop_core::canvas`.
21//! - **The zoom control** ([`CanvasZoom`]): zoom out, the percentage
22//!   with a menu of fit, 100 % and steps, zoom in and hand mode, over
23//!   any canvas, through the same commands.
24//! - **Touch screens**: two fingers pan ([`touch_pan`]) and a pinch
25//!   zooms every canvas.
26//! - **The overview** shows when the content is much larger than the
27//!   view ([`overview_needed`]).
28//! - **The view kept** across sessions for a canvas given an id
29//!   ([`load_view`], [`save_view`]), in egui's persisted memory.
30//! - **A one-time hint** on a canvas kind's first use ([`hint`]),
31//!   dismissed by the first pan or a click, remembered.
32
33use egui::{
34    Align2, Context, CursorIcon, Id, Key, Modifiers, Rect, Response, Sense, Ui, Vec2, vec2,
35};
36use egui_pop_core::canvas;
37use egui_pop_core::state::Slot;
38use egui_pop_core::strings::tr;
39
40use crate::strings as s;
41
42/// A navigation command, the same on every canvas.
43#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
44pub enum NavCommand {
45    /// Frames all the content.
46    Fit,
47    /// Frames the selection (all the content when nothing is selected).
48    FrameSelection,
49    ZoomIn,
50    ZoomOut,
51    /// One content unit to one point (an image's pixel to a pixel).
52    Zoom100,
53    /// A zoom in percent, around the view's centre (a zoom control's
54    /// step); sent as `view.zoom_to:<percent>`, it has no key.
55    ZoomTo(u32),
56    /// Pans a step that way.
57    Pan(PanDir),
58    /// Toggles hand mode.
59    Hand,
60}
61
62/// A direction to pan.
63#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
64pub enum PanDir {
65    Left,
66    Right,
67    Up,
68    Down,
69}
70
71impl PanDir {
72    /// Which way the view moves, as a unit vector.
73    pub fn vec(self) -> Vec2 {
74        match self {
75            PanDir::Left => vec2(-1.0, 0.0),
76            PanDir::Right => vec2(1.0, 0.0),
77            PanDir::Up => vec2(0.0, -1.0),
78            PanDir::Down => vec2(0.0, 1.0),
79        }
80    }
81}
82
83impl NavCommand {
84    /// Every command with keys, in the palette's order.
85    pub const ALL: [NavCommand; 10] = [
86        NavCommand::Fit,
87        NavCommand::FrameSelection,
88        NavCommand::ZoomIn,
89        NavCommand::ZoomOut,
90        NavCommand::Zoom100,
91        NavCommand::Pan(PanDir::Left),
92        NavCommand::Pan(PanDir::Right),
93        NavCommand::Pan(PanDir::Up),
94        NavCommand::Pan(PanDir::Down),
95        NavCommand::Hand,
96    ];
97
98    /// The command's id (`view.fit`; `view.zoom_to` for any zoom to a
99    /// percent).
100    pub fn id(self) -> &'static str {
101        match self {
102            NavCommand::Fit => "view.fit",
103            NavCommand::FrameSelection => "view.frame_selection",
104            NavCommand::ZoomIn => "view.zoom_in",
105            NavCommand::ZoomOut => "view.zoom_out",
106            NavCommand::Zoom100 => "view.zoom_100",
107            NavCommand::ZoomTo(_) => "view.zoom_to",
108            NavCommand::Pan(PanDir::Left) => "view.pan_left",
109            NavCommand::Pan(PanDir::Right) => "view.pan_right",
110            NavCommand::Pan(PanDir::Up) => "view.pan_up",
111            NavCommand::Pan(PanDir::Down) => "view.pan_down",
112            NavCommand::Hand => "view.hand",
113        }
114    }
115
116    /// A command by its id (one of [`NavCommand::ALL`]).
117    pub fn from_id(id: &str) -> Option<NavCommand> {
118        NavCommand::ALL.into_iter().find(|c| c.id() == id)
119    }
120
121    /// The command as sent to a canvas (`egui_pop_core::canvas::request`):
122    /// its id, or `view.zoom_to:<percent>`.
123    pub fn request(self) -> String {
124        match self {
125            NavCommand::ZoomTo(p) => format!("view.zoom_to:{p}"),
126            c => c.id().to_string(),
127        }
128    }
129
130    /// A command as sent to a canvas ([`NavCommand::request`]).
131    pub fn parse(text: &str) -> Option<NavCommand> {
132        if let Some(p) = text.strip_prefix("view.zoom_to:") {
133            return p
134                .trim()
135                .parse()
136                .ok()
137                .filter(|p| *p > 0)
138                .map(NavCommand::ZoomTo);
139        }
140        NavCommand::from_id(text)
141    }
142}
143
144/// A key and its modifiers.
145pub type Chord = (Modifiers, Key);
146
147/// The navigation keys: each command's chords. A pointer profile gives
148/// them ([`egui_pop_core::model::pointer::Profile::view_keys`]), through
149/// the keymap in an application, where the user rebinds them in the
150/// shortcuts editor.
151#[derive(Clone, Debug, Default, PartialEq)]
152pub struct NavKeys {
153    pub bindings: Vec<(NavCommand, Chord)>,
154}
155
156impl NavKeys {
157    /// The keys of a pointer map ([`PointerMap::view_keys`]).
158    ///
159    /// [`PointerMap::view_keys`]: egui_pop_core::model::pointer::PointerMap::view_keys
160    pub fn from_map(map: &egui_pop_core::model::pointer::PointerMap) -> NavKeys {
161        let mut bindings = Vec::new();
162        for c in NavCommand::ALL {
163            for chord in map.view_keys(c.id()) {
164                if let Some((m, k)) = egui_pop_core::keys::key_of(chord) {
165                    // Ctrl is the command key (Cmd on macOS), as egui
166                    // matches it logically.
167                    let m = Modifiers {
168                        ctrl: false,
169                        command: m.ctrl,
170                        mac_cmd: false,
171                        ..m
172                    };
173                    bindings.push((c, (m, k)));
174                }
175            }
176        }
177        // More modifiers first: Shift+2 is not read as a plain 2.
178        bindings.sort_by_key(|(_, (m, _))| {
179            std::cmp::Reverse(u8::from(m.command) + u8::from(m.shift) + u8::from(m.alt))
180        });
181        NavKeys { bindings }
182    }
183
184    /// A shipped profile's keys (the default profile's for an unknown
185    /// id).
186    pub fn for_profile(id: &str) -> NavKeys {
187        use egui_pop_core::model::pointer;
188        let p = pointer::profile(id).unwrap_or_else(pointer::default_profile);
189        NavKeys::from_map(&pointer::PointerMap::from_profile(p))
190    }
191
192    /// The chords of a command.
193    pub fn chords(&self, command: NavCommand) -> impl Iterator<Item = Chord> + '_ {
194        self.bindings
195            .iter()
196            .filter(move |(c, _)| *c == command)
197            .map(|(_, k)| *k)
198    }
199
200    /// The keymap's spelling of a command's keys (`Ctrl+Plus`), for
201    /// tooltips and the palette.
202    pub fn keys_of(&self, command: NavCommand) -> Vec<String> {
203        self.chords(command)
204            .map(|(m, k)| egui_pop_core::keys::chord_of(k, m).to_string())
205            .collect()
206    }
207
208    /// The commands whose keys were pressed, the keys consumed.
209    fn read(&self, ctx: &Context) -> Vec<NavCommand> {
210        let mut out = Vec::new();
211        ctx.input_mut(|i| {
212            for &(c, (m, k)) in &self.bindings {
213                if i.consume_key(m, k) && !out.contains(&c) {
214                    out.push(c);
215                }
216            }
217        });
218        out
219    }
220}
221
222const KEYS: Slot<NavKeys> = Slot::new("viewport.navigation.keys");
223
224/// The navigation keys in force: set with [`set_keys`], else the pointer
225/// map's (the profile's, with the user's changes in an application).
226pub fn keys(ctx: &Context) -> NavKeys {
227    KEYS.get(ctx)
228        .unwrap_or_else(|| NavKeys::from_map(&egui_pop_core::pointer::map(ctx)))
229}
230
231/// Sets the navigation keys outright; a canvas then reads them itself,
232/// in an application too.
233pub fn set_keys(ctx: &Context, keys: NavKeys) {
234    KEYS.set(ctx, keys);
235}
236
237/// Whether hand mode is on (a primary drag pans).
238pub fn hand(ctx: &Context) -> bool {
239    canvas::hand(ctx)
240}
241
242/// Turns hand mode on or off.
243pub fn set_hand(ctx: &Context, on: bool) {
244    canvas::set_hand(ctx, on);
245}
246
247/// Whether a primary drag pans now: hand mode, or Space held.
248pub fn primary_pans(ctx: &Context) -> bool {
249    hand(ctx) || ctx.input(|i| i.key_down(Key::Space))
250}
251
252/// A canvas's navigation for this frame: marks it active when the
253/// pointer is over it or it has the keyboard, reads its keys then (not
254/// while a text input owns the keyboard, nor in an application, whose
255/// keymap reads them and sends the commands), and gives what was asked,
256/// the application's commands included. Hand mode is toggled here and
257/// not returned.
258pub fn commands(ctx: &Context, id: Id, hovered: bool, focused: bool) -> Vec<NavCommand> {
259    let mut out = Vec::new();
260    if hovered || focused {
261        canvas::mark_active(ctx, id);
262        let own = KEYS.get(ctx);
263        let reads = own.is_some() || !egui_pop_core::pointer::map(ctx).keys_dispatched;
264        if reads && !egui_pop_core::focus::text_input_owns_keyboard(ctx) && !ctx.text_edit_focused()
265        {
266            out = own.unwrap_or_else(|| keys(ctx)).read(ctx);
267        }
268    }
269    out.extend(
270        canvas::take(ctx, id)
271            .iter()
272            .filter_map(|c| NavCommand::parse(c)),
273    );
274    out.retain(|c| {
275        if *c == NavCommand::Hand {
276            set_hand(ctx, !hand(ctx));
277            false
278        } else {
279            true
280        }
281    });
282    out
283}
284
285/// Whether two fingers or more are on a touch screen now (egui's
286/// multi-touch): a canvas then pans and zooms with them, and leaves the
287/// first finger's drag alone.
288pub fn touching(ctx: &Context) -> bool {
289    ctx.input(|i| i.multi_touch().is_some())
290}
291
292/// How far two fingers or more moved this frame on a touch screen, in
293/// points, when they started over `rect`: the content follows them. A
294/// pinch's zoom comes with the wheel's inputs
295/// (`egui_pop_core::pointer::wheel_inputs`).
296pub fn touch_pan(ctx: &Context, rect: Rect) -> Vec2 {
297    ctx.input(|i| {
298        i.multi_touch()
299            .filter(|t| rect.contains(t.start_pos))
300            .map_or(Vec2::ZERO, |t| t.translation_delta)
301    })
302}
303
304/// How much larger than the view the content must be, on one axis, for
305/// the overview to show.
306pub const OVERVIEW_RATIO: f32 = 2.0;
307
308/// When a canvas shows its overview (a minimap in a corner).
309#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
310pub enum Overview {
311    /// When the content is much larger than the view ([`overview_needed`]).
312    #[default]
313    WhenNeeded,
314    Always,
315    Never,
316}
317
318impl Overview {
319    /// Whether it shows, for this content and view (both in content
320    /// units).
321    pub fn shows(self, content: Rect, view: Rect) -> bool {
322        match self {
323            Overview::WhenNeeded => overview_needed(content, view),
324            Overview::Always => true,
325            Overview::Never => false,
326        }
327    }
328}
329
330/// Whether the content is much larger than the view: on one axis, more
331/// than [`OVERVIEW_RATIO`] times the view.
332pub fn overview_needed(content: Rect, view: Rect) -> bool {
333    if !content.is_positive() || !view.is_positive() {
334        return false;
335    }
336    content.width() > view.width() * OVERVIEW_RATIO
337        || content.height() > view.height() * OVERVIEW_RATIO
338}
339
340/// A canvas's view kept in egui's persisted memory under `id`.
341pub fn load_view(ctx: &Context, id: Id) -> Option<Rect> {
342    let v = ctx.data_mut(|d| d.get_persisted::<[f32; 4]>(view_id(id)))?;
343    let r = Rect::from_min_max(egui::pos2(v[0], v[1]), egui::pos2(v[2], v[3]));
344    (r.is_finite() && r.is_positive()).then_some(r)
345}
346
347/// Keeps a canvas's view under `id` (written when it changed).
348pub fn save_view(ctx: &Context, id: Id, view: Rect) {
349    if !view.is_finite() || !view.is_positive() {
350        return;
351    }
352    let v = [view.min.x, view.min.y, view.max.x, view.max.y];
353    let key = view_id(id);
354    if ctx.data(|d| d.get_temp::<[f32; 4]>(key)) != Some(v) {
355        ctx.data_mut(|d| d.insert_persisted(key, v));
356    }
357}
358
359fn view_id(id: Id) -> Id {
360    Id::unique("egui_pop.navigation.view").with(id)
361}
362
363fn hint_id(kind: &str) -> Id {
364    Id::unique("egui_pop.navigation.hint_seen").with(kind)
365}
366
367/// Whether a canvas kind's hint was seen (dismissed) on this
368/// installation.
369pub fn hint_seen(ctx: &Context, kind: &str) -> bool {
370    ctx.data_mut(|d| d.get_persisted::<bool>(hint_id(kind)))
371        .unwrap_or(false)
372}
373
374/// Marks a canvas kind's hint as seen.
375pub fn dismiss_hint(ctx: &Context, kind: &str) {
376    ctx.data_mut(|d| d.insert_persisted(hint_id(kind), true));
377}
378
379/// The hint showing on a canvas, by its id.
380const HINT_SHOWN: Slot<bool> = Slot::new("viewport.navigation.hint_shown");
381
382/// The one-time hint on a canvas kind's first use: shown from the first
383/// time the pointer is over the canvas until the first pan (`panned`) or
384/// a click on the canvas or on the hint; then never again for that kind.
385/// Whether it shows.
386pub fn hint(
387    ui: &mut Ui,
388    id: Id,
389    rect: Rect,
390    kind: &str,
391    response: &Response,
392    panned: bool,
393) -> bool {
394    let ctx = ui.ctx().clone();
395    if hint_seen(&ctx, kind) {
396        return false;
397    }
398    let slot = HINT_SHOWN.keyed(id);
399    let mut shown = slot.get_or_default(&ctx);
400    if !shown && response.hovered() {
401        shown = true;
402        slot.set(&ctx, true);
403    }
404    if !shown {
405        return false;
406    }
407    if panned || response.clicked() || response.drag_started() {
408        dismiss_hint(&ctx, kind);
409        slot.set(&ctx, false);
410        return false;
411    }
412    let text = tr(&ctx, &s::NAV_HINT);
413    let at = rect.center_top() + vec2(0.0, 8.0);
414    let clicked = overlay_label(ui, rect, at, Align2::CENTER_TOP, &text, Sense::click()).clicked();
415    if clicked {
416        dismiss_hint(&ctx, kind);
417        slot.set(&ctx, false);
418        return false;
419    }
420    true
421}
422
423/// The hand mode indicator in a canvas's top-left corner, and the grab
424/// cursor over the canvas, while hand mode is on. Whether it shows.
425pub fn indicator(ui: &mut Ui, rect: Rect, response: &Response) -> bool {
426    let ctx = ui.ctx().clone();
427    if !hand(&ctx) {
428        return false;
429    }
430    if response.hovered() && !ctx.input(|i| i.pointer.any_down()) {
431        ctx.set_cursor_icon(CursorIcon::Grab);
432    }
433    let text = tr(&ctx, &s::NAV_HAND);
434    overlay_label(
435        ui,
436        rect,
437        rect.left_top() + vec2(8.0, 8.0),
438        Align2::LEFT_TOP,
439        &text,
440        Sense::hover(),
441    );
442    true
443}
444
445/// A small framed label over a canvas.
446fn overlay_label(
447    ui: &mut Ui,
448    clip: Rect,
449    at: egui::Pos2,
450    align: Align2,
451    text: &str,
452    sense: Sense,
453) -> Response {
454    let galley = ui.painter().layout_no_wrap(
455        text.to_string(),
456        egui::TextStyle::Small.resolve(ui.style()),
457        ui.visuals().strong_text_color(),
458    );
459    let size = galley.size() + vec2(16.0, 8.0);
460    let min = match align {
461        Align2::CENTER_TOP => egui::pos2(at.x - size.x / 2.0, at.y),
462        _ => at,
463    };
464    let r = Rect::from_min_size(min, size).intersect(clip);
465    // In an area just above the canvas (and above the scene's own layer,
466    // where a graph's nodes are), so it takes no room in the canvas's
467    // `Ui`, and a window over the canvas stays over it.
468    let id = ui.scope_id().with(("egui_pop.navigation.overlay", text));
469    canvas_overlay(ui, id, r.min, |ui| {
470        ui.set_clip_rect(clip);
471        let (r, resp) = ui.allocate_exact_size(r.size(), sense);
472        let fill = ui.visuals().window_fill.gamma_multiply(0.92);
473        let stroke = ui.visuals().window_stroke;
474        ui.painter()
475            .rect(r, 4.0, fill, stroke, egui::StrokeKind::Inside);
476        let label = text.to_string();
477        resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, true, &label));
478        ui.painter().galley(
479            r.center() - galley.size() / 2.0,
480            galley,
481            ui.visuals().strong_text_color(),
482        );
483        resp
484    })
485    .inner
486}
487
488/// An overlay over a canvas drawn in `ui`, at `at`: an area in the
489/// canvas layer's order, drawn just above that layer (a sublayer of it),
490/// not in the foreground order, where it would lie over every window,
491/// popup or dialog that covers the canvas.
492pub(crate) fn canvas_overlay<R>(
493    ui: &Ui,
494    id: Id,
495    at: egui::Pos2,
496    add: impl FnOnce(&mut Ui) -> R,
497) -> egui::InnerResponse<R> {
498    let parent = ui.layer_id();
499    let shown = egui::Area::new(id)
500        .order(parent.order)
501        .fixed_pos(at)
502        .constrain(false)
503        .show(ui.ctx(), add);
504    let layer = shown.response.layer_id;
505    ui.ctx().set_sublayer(parent, layer);
506    shown
507}
508
509/// The zoom steps a [`CanvasZoom`]'s menu offers by default, in percent
510/// (100 % is always offered).
511pub const ZOOM_STEPS: [u32; 5] = [25, 50, 200, 400, 800];
512
513/// A zoom control for any canvas: zoom out, the zoom in percent (a menu
514/// of fit, frame the selection, 100 % and the steps), zoom in, and hand
515/// mode. It sends the canvas commands (`view.zoom_out`, `view.fit`,
516/// `view.zoom_to:200`...) to the canvas it drives through
517/// `egui_pop_core::canvas`, and shows the zoom the canvas published;
518/// each button's tooltip says its keys.
519///
520/// ```no_run
521/// # fn page(ui: &mut egui::Ui, graph: &dyn egui_pop_viewport::graph::GraphModel, state: &mut egui_pop_viewport::graph::GraphState) {
522/// use egui_pop_viewport::graph::GraphEditor;
523/// use egui_pop_viewport::navigation::CanvasZoom;
524///
525/// let out = GraphEditor::new(graph, state).show(ui);
526/// CanvasZoom::new(out.canvas).show(ui);
527/// # }
528/// ```
529#[derive(Clone, Debug)]
530pub struct CanvasZoom {
531    canvas: Option<Id>,
532    steps: Vec<u32>,
533    hand: bool,
534    frame_selection: bool,
535}
536
537impl CanvasZoom {
538    /// Drives a canvas by its id (`GraphOutput::canvas`,
539    /// `ViewportOutput::canvas`).
540    pub fn new(canvas: Id) -> CanvasZoom {
541        CanvasZoom {
542            canvas: Some(canvas),
543            steps: ZOOM_STEPS.to_vec(),
544            hand: true,
545            frame_selection: true,
546        }
547    }
548
549    /// Drives the canvas in use, else the one used last (a toolbar's
550    /// control for every canvas of a window).
551    pub fn active() -> CanvasZoom {
552        CanvasZoom {
553            canvas: None,
554            ..CanvasZoom::new(Id::NULL)
555        }
556    }
557
558    /// The menu's steps, in percent.
559    pub fn steps(mut self, steps: impl IntoIterator<Item = u32>) -> CanvasZoom {
560        self.steps = steps.into_iter().filter(|p| *p > 0).collect();
561        self
562    }
563
564    /// Shows the hand mode button (default: on).
565    pub fn hand_button(mut self, on: bool) -> CanvasZoom {
566        self.hand = on;
567        self
568    }
569
570    /// Offers "frame the selection" in the menu (default: on; off for a
571    /// canvas without a selection, an image).
572    pub fn frame_selection(mut self, on: bool) -> CanvasZoom {
573        self.frame_selection = on;
574        self
575    }
576
577    /// Draws the row. Its response is clicked when a command was sent.
578    pub fn show(self, ui: &mut Ui) -> Response {
579        use egui_pop_core::icon::{Icon, Size};
580        use egui_pop_core::ui::{Stock, Tone, UiPop as _};
581        let ctx = ui.ctx().clone();
582        let target = self
583            .canvas
584            .or_else(|| canvas::active(&ctx).or_else(|| canvas::last(&ctx)));
585        let keys = keys(&ctx);
586        let tip = |title: &str, c: NavCommand| {
587            let k = keys.keys_of(c);
588            if k.is_empty() {
589                title.to_string()
590            } else {
591                format!("{title} ({})", k.join(", "))
592            }
593        };
594        let mut sent: Vec<NavCommand> = Vec::new();
595        let inner = ui.horizontal(|ui| {
596            ui.add_enabled_ui(target.is_some(), |ui| {
597                let out = ui
598                    .add(
599                        Icon::Minus
600                            .size(Size::Toolbar)
601                            .label(&tr(&ctx, &s::ZOOM_OUT))
602                            .sense_click(),
603                    )
604                    .on_hover_text(tip(&tr(&ctx, &s::ZOOM_OUT), NavCommand::ZoomOut));
605                if out.clicked() {
606                    sent.push(NavCommand::ZoomOut);
607                }
608                let zoom = target.and_then(|id| canvas::zoom(&ctx, id));
609                let text = zoom.map_or_else(
610                    || "– %".to_string(),
611                    |z| {
612                        format!(
613                            "{} %",
614                            crate::navigator::percent_text(&ctx, f64::from(z) * 100.0)
615                        )
616                    },
617                );
618                let level = tr(&ctx, &s::ZOOM_LEVEL);
619                let menu = ui.menu_button(text.clone(), |ui| {
620                    let mut item = |ui: &mut Ui, label: String, c: NavCommand| {
621                        let mut b = ui.button(label);
622                        let k = keys.keys_of(c);
623                        if !k.is_empty() {
624                            b = b.on_hover_text(k.join(", "));
625                        }
626                        if b.clicked() {
627                            sent.push(c);
628                            ui.close();
629                        }
630                    };
631                    item(ui, tr(&ctx, &s::ZOOM_FIT), NavCommand::Fit);
632                    if self.frame_selection {
633                        item(
634                            ui,
635                            tr(&ctx, &s::ZOOM_FRAME_SELECTION),
636                            NavCommand::FrameSelection,
637                        );
638                    }
639                    item(ui, tr(&ctx, &s::ZOOM_ACTUAL), NavCommand::Zoom100);
640                    if !self.steps.is_empty() {
641                        ui.separator();
642                    }
643                    for &p in self.steps.iter().filter(|p| **p != 100) {
644                        item(
645                            ui,
646                            format!("{} %", crate::navigator::percent_text(&ctx, f64::from(p))),
647                            NavCommand::ZoomTo(p),
648                        );
649                    }
650                });
651                egui_pop_core::overlay::follow_menu(&menu.response, "zoom menu");
652                let r = menu.response.on_hover_text(level.clone());
653                ctx.accesskit_node_builder(r.id, |node| {
654                    node.set_label(level.clone());
655                    node.set_value(text.clone());
656                });
657                let into = ui
658                    .add(
659                        Icon::Plus
660                            .size(Size::Toolbar)
661                            .label(&tr(&ctx, &s::ZOOM_IN))
662                            .sense_click(),
663                    )
664                    .on_hover_text(tip(&tr(&ctx, &s::ZOOM_IN), NavCommand::ZoomIn));
665                if into.clicked() {
666                    sent.push(NavCommand::ZoomIn);
667                }
668                if self.hand {
669                    let on = hand(&ctx);
670                    let label = tr(&ctx, &s::NAV_HAND_BUTTON);
671                    let b = ui
672                        .scoped(Stock::ToggleButton, Tone::Neutral, |ui| {
673                            ui.add(egui::Button::new(label.clone()).selected(on))
674                        })
675                        .inner
676                        .on_hover_text(tip(&label, NavCommand::Hand));
677                    if b.clicked() {
678                        set_hand(&ctx, !on);
679                    }
680                }
681            });
682        });
683        let mut response = inner.response;
684        if let Some(id) = target {
685            for c in &sent {
686                canvas::request_to(&ctx, id, &c.request());
687            }
688        }
689        if !sent.is_empty() {
690            response.mark_changed();
691        }
692        response
693    }
694}