ui/ruler.rs#
Source: lib/ui/ruler.rs
ruler -- a ruler along a canvas (ZF-02): ticks and numbers in the document's units for the
view of a ui.diagram canvas, the page's extent lighter, marks (the selection's edges and
middle while it moves or changes size), the pointer's position; dragging out of it makes a
guide (SP-10)
ui.ruler(id, &vp, &RulerSpec) -> RulerEv a horizontal ruler (above the canvas) or a
vertical one (left of it) in the next layout slot (size it
with next_size: the canvas' width or height, 20 DIP across)
RulerSpec { vertical, origin, per_world, page, marks, pointer }
RulerEv::None | Guide { at, done } a guide dragged out of the ruler: its world position
(y of a horizontal guide from the top ruler, x of a vertical
one from the left ruler) while the button is held, done when
released over the canvas (Esc: none)
Units: a world coordinate c (the canvas', y down) shows as (c - origin) * per_world; a vertical
ruler whose numbers grow upwards (a page with its origin at the bottom) has per_world < 0. The
step between numbered ticks is 1, 2 or 5 times a power of ten, at least 48 DIP apart; between
them 10, 5 or 2 smaller ticks as there is room. The ruler has a semantic record (K_SLIDER-like
K_BOX "Lineal") so scripts drag from it.
struct RulerSpec<'a>what a ruler showsvertical: bool-- a vertical ruler (left of the canvas) instead of a horizontal oneorigin: f32-- the world coordinate of 0per_world: f64-- units per world unit (negative: the numbers grow up / to the left)page: [f32; 2]-- the page's extent along the ruler (world, from .. to), drawn lightermarks: &'a [f32]-- world coordinates to mark (edges and middle of the selection)pointer: Option<f32>-- the pointer's world coordinate along the ruler
enum RulerEvwhat the user did with a rulerNoneGuide { at: f32, done: bool }-- a guide is dragged out of the ruler: its world coordinate across the ruler; done = released over the canvasGuideCancel-- the drag of a guide ended outside the canvas or with Esc
impl Ui
fn ruler(&mut self, id: u32, vp: &Viewport, spec: &RulerSpec) -> RulerEvui_ruler(id, vp, spec) -> what the user did: a ruler for the view vp of a canvas (see the file header)