Skip to main content

View

Struct View 

Source
pub struct View {
    draft: Option<Draft>,
    hovered: bool,
    primary_drag_pans: bool,
    touch_pans: bool,
    camera: Camera,
    images: Rc<RefCell<ImageRegistry>>,
}
Expand description

The canvas as egui shows it: the rect it is laid out in, the pointer and the gestures over it, and the in-place editor drawn into it. Where the diagram is shown from is the session’s; this reads what would move it and reports the move.

Fields§

§draft: Option<Draft>

The in-place editor shown last frame and what has been typed into it, so a freshly-shown editor (different id, or none previously) opens on the request’s text and grabs keyboard focus exactly once.

§hovered: bool

Whether the pointer was over the canvas response (not a floating overlay) as of the last Self::begin. Lets the app suppress the tool cursor when the pointer sits over the nav bar, toolbar, or selection overlay.

§primary_drag_pans: bool

Whether the primary-button drag in progress is panning the canvas (it began with the pan key held). Latched at drag start so releasing the key mid-drag can’t hand a half-finished pan to a tool.

§touch_pans: bool

Whether a two-finger gesture is in progress. MultiTouchInfo vanishes the instant a finger lifts, but the finger still down keeps arriving as an ordinary drag — so the latch holds the canvas until the last one leaves, rather than handing a half-finished pan to a tool.

§camera: Camera

What the last Self::begin made of the frame’s camera input, kept for the chrome drawn after the canvas pass.

§images: Rc<RefCell<ImageRegistry>>

The artwork the display list may name, registered through Self::register_image as each asset’s bytes are handed off.

Implementations§

Source§

impl View

Source

pub fn register_image(&self, ctx: &Context, hash: AssetHash, asset: &Asset)

Hand an asset’s bytes to the loader under the hash the display list names it by. Idempotent, so a re-sent asset costs nothing.

Source

pub fn canvas_hovered(&self) -> bool

Whether the pointer was over the canvas (not a floating overlay) as of the last Self::begin. The app gates the tool cursor on this so it never leaks over the nav bar, toolbar, or selection overlay.

Source

pub fn camera(&self) -> Camera

Whether the camera is being worked, as of the last Self::begin. The selection overlay is drawn after the canvas pass and reads it there.

Source

pub fn focused_edit_id(&self) -> Option<Id>

Id of the in-place editor rendered last frame. A fallback for surrendering editor focus when Memory::focused can’t be trusted to name it.

Source

pub fn begin(&mut self, ui: &mut Ui) -> Canvas

Open the canvas frame: allocate the viewport and read this frame’s pan/zoom — everything that would move the camera, and nothing that paints under it. The Canvas it answers with is a value, so the frame can carry it across whatever runs between reading the pointer and painting.

Source

pub fn show( &mut self, ui: &Ui, canvas: &Canvas, diagram: Diagram<'_>, ) -> Option<Cursor>

Paint the frame: the ground and the grid under diagram’s camera, then its display list replayed over them, clipped to the canvas — into the slot Self::begin reserved, so it lies under whatever the frame placed over the canvas in between. Answers the cursor the pointer is left with: the diagram’s own, unless the camera is being worked — an armed or in-progress pan owns the pointer.

Source

fn handle_pan_zoom( &mut self, ui: &Ui, response: &Response, rect: Rect, moves: &mut Vec<Move>, ) -> Camera

Wheel zoom (centered on the cursor), two-finger pan/pinch, and drag pan — right/middle button, or the primary button with the pan key held — each reported as a [Move] for the session to apply.

Source

fn handle_touch_gesture( &mut self, ui: &Ui, response: &Response, moves: &mut Vec<Move>, ) -> Option<Camera>

Two fingers pan and pinch the canvas together, about the gesture’s own center. Some means the gesture owns the frame — the primary finger also arrives as an ordinary drag, which a tool would otherwise read as a marquee or a wire.

This is the only pan a touch screen has: it has no wheel, no middle button, and no space bar to hold.

Source

fn grid(vantage: Vantage, rect: Rect, chrome: CanvasChrome) -> Vec<Shape>

The canvas background and the grid over it, in the chrome colors the caller already resolved rather than through the palette-based recording.

Source

pub fn capture( &mut self, ui: &mut Ui, field: Option<&EditField>, vantage: Vantage, ) -> Option<TextEvent>

The editor the last call asked for, run as egui’s own text field over the diagram: it keeps the draft, the caret and the selection, and says only how the edit ended. angle is not honoured — egui cannot rotate a TextEdit — so a vertical label is edited upright.

Trait Implementations§

Source§

impl Default for View

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for View

§

impl !RefUnwindSafe for View

§

impl !Send for View

§

impl !Sync for View

§

impl Unpin for View

§

impl UnsafeUnpin for View

§

impl !UnwindSafe for View

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more