pub struct Viewport {
pub zoom: f32,
pub offset: Point<Pixels>,
pub window_bounds: Option<Bounds<Pixels>>,
}Fields§
§zoom: f32§offset: Point<Pixels>§window_bounds: Option<Bounds<Pixels>>Implementations§
Source§impl Viewport
impl Viewport
pub fn new() -> Self
Sourcepub fn sync_drawable_bounds(&mut self, window: &Window)
pub fn sync_drawable_bounds(&mut self, window: &Window)
Sets Self::window_bounds to the window’s drawable area (Window::viewport_size),
origin (0, 0). Skips assignment when width/height are unchanged.
Prefer this over Window::bounds() for hit-testing and overlay layout: the latter is in
global space and can be larger than the content viewport.
Sourcepub fn world_to_screen(&self, p: Point<Pixels>) -> Point<Pixels>
pub fn world_to_screen(&self, p: Point<Pixels>) -> Point<Pixels>
Examples found in repository?
examples/extension.rs (line 55)
54 fn render(&self, node: &Node, ctx: &mut RenderContext) -> AnyElement {
55 let screen = ctx.viewport.world_to_screen(node.point());
56 let node_x = screen.x;
57 let node_y = screen.y;
58
59 div()
60 .absolute()
61 .left(node_x)
62 .top(node_y)
63 .w(node.size.width * ctx.viewport.zoom)
64 .h(node.size.height * ctx.viewport.zoom)
65 .bg(rgb(0x505078))
66 .child(div().child("Number Node").text_color(white()))
67 .into_any()
68 }pub fn screen_to_world(&self, p: Point<Pixels>) -> Point<Pixels>
pub fn is_node_visible(&self, node: &Node) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Viewport
impl RefUnwindSafe for Viewport
impl Send for Viewport
impl Sync for Viewport
impl Unpin for Viewport
impl UnsafeUnpin for Viewport
impl UnwindSafe for Viewport
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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 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>
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