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: f32The content point at the view’s top left: x.
y: f32And y.
zoom: f32Window units per content unit: 2 is twice as near.
Implementations§
Source§impl PanZoom
impl PanZoom
Sourcepub fn to_window(&self, point: Point, at: Rect) -> Point
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).
Sourcepub fn from_window(&self, place: Point, at: Rect) -> Point
pub fn from_window(&self, place: Point, at: Rect) -> Point
The content point at place in the window, the view at at.
Sourcepub fn visible_rect(&self, size: Size) -> Rect
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}Trait Implementations§
impl Copy for PanZoom
impl StructuralPartialEq for PanZoom
Auto Trait Implementations§
impl Forget for PanZoom
impl Freeze for PanZoom
impl Move for PanZoom
impl RefUnwindSafe for PanZoom
impl Send for PanZoom
impl Sync for PanZoom
impl Unpin for PanZoom
impl UnsafeUnpin for PanZoom
impl UnwindSafe for PanZoom
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more