Skip to main content

PanZoom

Struct PanZoom 

Source
pub struct PanZoom {
    pub x: f32,
    pub y: f32,
    pub zoom: f32,
}
Expand description

A pan-and-zoom view: what an app keeps of one. As text, three numbers (to_string(), and back with parse()).

Fields§

§x: f32

The content point at the view’s top left: x.

§y: f32

And y.

§zoom: f32

Window units per content unit: 2 is twice as near.

Implementations§

Source§

impl PanZoom

Source

pub fn to_window(&self, point: Point, at: Rect) -> Point

Where a content point shows in the window, the view at at (the rect of what Ui::pan_zoom returned).

Source

pub fn from_window(&self, place: Point, at: Rect) -> Point

The content point at place in the window, the view at at.

Source

pub fn visible_rect(&self, size: Size) -> Rect

The part of the content in view in a room of size window units.

Examples found in repository?
examples/node_editor.rs (line 194)
188pub fn describe(app: &mut Sums, ui: &mut Ui) {
189    let room = ui.size();
190    ui.row().pad(8.0).gap(6.0).open();
191    for (does, name) in KINDS {
192        // (A node added by a button goes in the middle of what is in sight.)
193        if ui.button(name).clicked {
194            let sight = app.graph.view.visible_rect(room);
195            add(app, does, pt(sight.x + sight.w / 2.0 - 80.0, sight.y + sight.h / 2.0 - 60.0));
196        }
197    }
198    ui.spacer();
199    ui.set_enabled(app.graph.can_undo());
200    let undone = ui.button("Undo").clicked && app.graph.undo();
201    ui.set_enabled(app.graph.can_redo());
202    let redone = ui.button("Redo").clicked && app.graph.redo();
203    ui.set_enabled(true);
204    ui.close();
205    if undone || redone {
206        work_out(&mut app.graph);
207    }
208    let mut changed = false;
209    while let Some(n) = ui.graph(&mut app.graph, "Sums") {
210        changed |= body(ui, &mut app.graph, n);
211        ui.close();
212    }
213    // (A wire let go on nothing opens the same menu, and the node added takes it.)
214    match app.graph.action {
215        GraphAction::Menu { node, at } => (app.menu, app.dropped) = ((node, at), None),
216        GraphAction::WireDropped { port, output, at } => (app.menu, app.dropped) = ((None, at), Some((port.0, port.1, output))),
217        GraphAction::None | GraphAction::Selected | GraphAction::Moved => {}
218        _ => changed = true,
219    }
220    if matches!(app.graph.action, GraphAction::Menu { .. } | GraphAction::WireDropped { .. }) {
221        let pointer = ui.pointer().unwrap_or_default();
222        ui.open_popup(MENU, rect(pointer.x, pointer.y, 0.0, 0.0));
223    }
224    menu(app, ui);
225    find(app, ui);
226    if changed {
227        work_out(&mut app.graph);
228        ui.rerun();
229    }
230}
231
232/// What the menu of the right button is known by.
233const MENU: taut::Id = 0x5e7_0001;
234
235/// The menu of the right button: on the canvas, the kinds of node to add where it was
236/// pressed; on a node, taking it away.
237fn menu(app: &mut Sums, ui: &mut Ui) {
238    if !ui.menu(MENU) {
239        return;
240    }
241    match app.menu {
242        (Some(node), _) => {
243            if ui.menu_item("Delete\tDelete").clicked && node < app.graph.nodes.len() {
244                app.graph.save_undo_step();
245                app.graph.remove(node);
246                work_out(&mut app.graph);
247            }
248        }
249        (None, at) => {
250            for (does, name) in KINDS {
251                if ui.menu_item(name).clicked {
252                    add(app, does, at);
253                }
254            }
255        }
256    }
257    ui.close();
258}
259
260/// Shift+A: a search for a kind of node to add, in the middle of what is in sight.
261fn find(app: &mut Sums, ui: &mut Ui) {
262    if ui.key(Key::Char('a'), Mods::SHIFT) {
263        let sight = app.graph.view.visible_rect(ui.size());
264        let middle = pt(sight.x + sight.w / 2.0 - 80.0, sight.y + sight.h / 2.0 - 60.0);
265        (app.finding, app.menu, app.dropped) = (true, (None, middle), None);
266    }
267    let names = KINDS.map(|(_, name)| name);
268    if let Some(picked) = ui.command_palette(&mut app.finding, &names) {
269        add(app, KINDS[picked].0, app.menu.1);
270    }
271}
Source

pub fn zoom_at(&mut self, by: f32, at: Point, zoom: RangeInclusive<f32>)

Zooms by by (out, below 1), clamped to zoom, keeping the content point at at (from its top left, in window units) in place.

Source

pub fn fit(&mut self, all: Rect, size: Size, zoom: RangeInclusive<f32>)

Shows all of all (content units) centred in a room of size, as near as leaves a small margin, clamped to zoom. Nothing changes for an empty all.

Trait Implementations§

Source§

impl Clone for PanZoom

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PanZoom

Source§

impl Debug for PanZoom

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PanZoom

The content’s origin at the top left, at zoom 1.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for PanZoom

Where a pan-and-zoom view looks, and its zoom: three numbers.

Source§

fn fmt(&self, to: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for PanZoom

Source§

type Err = ()

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Self, ()>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for PanZoom

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PanZoom

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.