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: boolWhether 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: boolWhether 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: boolWhether 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: CameraWhat 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
impl View
Sourcepub fn register_image(&self, ctx: &Context, hash: AssetHash, asset: &Asset)
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.
Sourcepub fn canvas_hovered(&self) -> bool
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.
Sourcepub fn camera(&self) -> Camera
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.
Sourcepub fn focused_edit_id(&self) -> Option<Id>
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.
Sourcepub fn begin(&mut self, ui: &mut Ui) -> Canvas
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.
Sourcepub fn show(
&mut self,
ui: &Ui,
canvas: &Canvas,
diagram: Diagram<'_>,
) -> Option<Cursor>
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.
Sourcefn handle_pan_zoom(
&mut self,
ui: &Ui,
response: &Response,
rect: Rect,
moves: &mut Vec<Move>,
) -> Camera
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.
Sourcefn handle_touch_gesture(
&mut self,
ui: &Ui,
response: &Response,
moves: &mut Vec<Move>,
) -> Option<Camera>
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.
Sourcefn grid(vantage: Vantage, rect: Rect, chrome: CanvasChrome) -> Vec<Shape>
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.
Sourcepub fn capture(
&mut self,
ui: &mut Ui,
field: Option<&EditField>,
vantage: Vantage,
) -> Option<TextEvent>
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§
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> 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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