ltk::core

Struct UiSurface

Source
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>

Source

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.

Source

pub fn new_software(width: u32, height: u32) -> Self

Create a software-backed surface explicitly.

Source

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.

Source

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.

Source

pub unsafe fn from_current_gles_loader<F>( loader: F, version: GlesVersion, width: u32, height: u32, ) -> Self
where F: FnMut(&str) -> *const c_void,

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.

Source

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.

Source

pub fn canvas(&self) -> &Canvas

Access the backing canvas after a render pass.

Source

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.

Source

pub fn size(&self) -> (u32, u32)

Current canvas size in physical pixels.

Source

pub fn resize(&mut self, width: u32, height: u32)

Resize the backing canvas and force the next render to redraw fully.

Source

pub fn set_dpi_scale(&mut self, scale: f32)

Set the DPI scale used for text and font metrics.

Source

pub fn mark_content_dirty(&mut self)

Mark the next render as content-changing, forcing a full repaint.

Source

pub fn widget_rects(&self) -> &[LaidOutWidget<Msg>]

Current laid-out interactive widgets from the last render.

Source

pub fn hit_test(&self, pos: Point) -> Option<usize>

Hit-test a physical point against the last rendered widget rects.

Source

pub fn widget(&self, flat_idx: usize) -> Option<&LaidOutWidget<Msg>>

Lookup a laid-out widget by flat index.

Source

pub fn handlers(&self, flat_idx: usize) -> Option<&WidgetHandlers<Msg>>

Lookup the handler snapshot for a laid-out widget.

Source

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.

Source

pub fn set_hovered(&mut self, idx: Option<usize>)

Update hover state. This is interaction-only.

Source

pub fn set_pressed(&mut self, idx: Option<usize>)

Update pressed state. This is interaction-only.

Source

pub fn focused(&self) -> Option<usize>

Source

pub fn hovered(&self) -> Option<usize>

Source

pub fn pressed(&self) -> Option<usize>

Source

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§

Source§

impl<Msg: Clone> Drop for UiSurface<Msg>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: 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.
§

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

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

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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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