pub struct UiSurface<Msg: Clone> { /* private fields */ }Expand description
A retained rendering target for code that wants ltk widgets without
ltk::run.
A compositor can keep one UiSurface per decoration or panel, mutate
focus/hover/pressed state from its own input routing, then call
Self::render whenever it decides a repaint is needed.
Implementations§
Source§impl<Msg: Clone> UiSurface<Msg>
impl<Msg: Clone> UiSurface<Msg>
Sourcepub fn new(width: u32, height: u32) -> Self
pub fn new(width: u32, height: u32) -> Self
Create a software-backed surface of the given physical size.
This is intentionally conservative for compositor integrations: an
embedder typically already owns an EGL/GLES context, so new must
not allocate a hidden offscreen context per decoration. Use
Self::from_gles_context when the caller can provide an
already-current GL context.
Sourcepub fn new_software(width: u32, height: u32) -> Self
pub fn new_software(width: u32, height: u32) -> Self
Create a software-backed surface explicitly.
Sourcepub fn try_new_gles(width: u32, height: u32) -> Result<Self, String>
pub fn try_new_gles(width: u32, height: u32) -> Result<Self, String>
Create a GLES-backed surface with an ltk-owned offscreen EGL context.
The context is made current before render/resize operations. This is
useful for runtime-free rendering; compositors that already own a GL
context can instead build a Canvas::new_gles(...) and pass it to
Self::from_canvas.
Sourcepub fn from_gles_context(
gl: Arc<Context>,
version: GlesVersion,
width: u32,
height: u32,
) -> Self
pub fn from_gles_context( gl: Arc<Context>, version: GlesVersion, width: u32, height: u32, ) -> Self
Create a GLES-backed surface from a caller-owned, already-current GL context.
This is the path intended for compositor embedders: no EGL display, EGL context, or pbuffer is allocated by ltk. The caller must keep the underlying GL context alive and current whenever this surface is created, rendered, resized, or dropped.
Sourcepub unsafe fn from_current_gles_loader<F>(
loader: F,
version: GlesVersion,
width: u32,
height: u32,
) -> Self
pub unsafe fn from_current_gles_loader<F>( loader: F, version: GlesVersion, width: u32, height: u32, ) -> Self
Create a GLES-backed surface from the GL function loader of the current context.
This is useful for renderers such as Smithay’s GlesRenderer, which
keep their own EGL context and expose custom GL access through a
callback. This constructor does not allocate an EGL context; it only
builds ltk’s glow dispatch table and GPU canvas resources in the
context that is current while this function runs.
§Safety
loader must resolve symbols for the GL context that is current on this
thread. That same context must remain alive, and must be made current
before any call that touches the returned surface — including the
implicit destructor: dropping the UiSurface releases GPU resources
(textures, FBOs, programs) through the caller-owned context and will
leak / corrupt state if that context is not current at drop time.
Sourcepub fn from_canvas(canvas: Canvas) -> Self
pub fn from_canvas(canvas: Canvas) -> Self
Wrap an existing canvas. This is the hook for compositor-owned GPU
targets once the caller provides an already-current GL context. If
canvas is Canvas::Gles, the caller remains responsible for making the
matching GL context current before calling methods that touch the
canvas — including the implicit destructor: dropping the
UiSurface releases GPU resources (textures, FBOs, programs) through
the caller-owned context and will leak / corrupt state if that context
is not current at drop time.
Sourcepub fn canvas_mut(&mut self) -> &mut Canvas
pub fn canvas_mut(&mut self) -> &mut Canvas
Mutable access to the backing canvas for compositor-specific upload or presentation code. Mark content dirty afterwards if external drawing changes what ltk should preserve across partial redraws.
Sourcepub fn resize(&mut self, width: u32, height: u32)
pub fn resize(&mut self, width: u32, height: u32)
Resize the backing canvas and force the next render to redraw fully.
Sourcepub fn set_dpi_scale(&mut self, scale: f32)
pub fn set_dpi_scale(&mut self, scale: f32)
Set the DPI scale used for text and font metrics.
Sourcepub fn mark_content_dirty(&mut self)
pub fn mark_content_dirty(&mut self)
Mark the next render as content-changing, forcing a full repaint.
Sourcepub fn widget_rects(&self) -> &[LaidOutWidget<Msg>]
pub fn widget_rects(&self) -> &[LaidOutWidget<Msg>]
Current laid-out interactive widgets from the last render.
Sourcepub fn hit_test(&self, pos: Point) -> Option<usize>
pub fn hit_test(&self, pos: Point) -> Option<usize>
Hit-test a physical point against the last rendered widget rects.
Sourcepub fn widget(&self, flat_idx: usize) -> Option<&LaidOutWidget<Msg>>
pub fn widget(&self, flat_idx: usize) -> Option<&LaidOutWidget<Msg>>
Lookup a laid-out widget by flat index.
Sourcepub fn handlers(&self, flat_idx: usize) -> Option<&WidgetHandlers<Msg>>
pub fn handlers(&self, flat_idx: usize) -> Option<&WidgetHandlers<Msg>>
Lookup the handler snapshot for a laid-out widget.
Sourcepub fn set_focused(&mut self, idx: Option<usize>)
pub fn set_focused(&mut self, idx: Option<usize>)
Update keyboard focus state. This is interaction-only, so the next render can use partial damage when layout/content did not change.
Sourcepub fn set_hovered(&mut self, idx: Option<usize>)
pub fn set_hovered(&mut self, idx: Option<usize>)
Update hover state. This is interaction-only.
Sourcepub fn set_pressed(&mut self, idx: Option<usize>)
pub fn set_pressed(&mut self, idx: Option<usize>)
Update pressed state. This is interaction-only.
pub fn focused(&self) -> Option<usize>
pub fn hovered(&self) -> Option<usize>
pub fn pressed(&self) -> Option<usize>
Sourcepub fn render(
&mut self,
element: &Element<Msg>,
options: RenderOptions,
) -> RenderOutput
pub fn render( &mut self, element: &Element<Msg>, options: RenderOptions, ) -> RenderOutput
Render element into the backing canvas.
This does not commit, swap buffers, request frame callbacks, or talk to Wayland. The caller owns presentation and frame pacing.
Trait Implementations§
Auto Trait Implementations§
impl<Msg> Freeze for UiSurface<Msg>
impl<Msg> !RefUnwindSafe for UiSurface<Msg>
impl<Msg> !Send for UiSurface<Msg>
impl<Msg> !Sync for UiSurface<Msg>
impl<Msg> Unpin for UiSurface<Msg>where
Msg: Unpin,
impl<Msg> !UnwindSafe for UiSurface<Msg>
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§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