ltk

Module widget_external

Source
Expand description

Widget that hosts content rendered by an external GL producer.

Reserves layout space and, at draw time, samples a caller-provided GL texture into the LTK canvas via Canvas::draw_external_texture. The producer (a web engine, a video decoder, …) keeps ownership of the texture and updates it on its own cadence; LTK only composites.

§Source closure contract

ExternalSource::Texture carries an Arc<dyn Fn(&glow::Context, Rect) -> Option<glow::Texture>> that LTK invokes once per frame, with its GLES context current. The producer:

  1. Reads Rect (in physical pixels of the host surface) — useful for sizing the inner viewport (e.g. resizing a WPEToplevel to match) and for translating input coordinates by rect.origin.
  2. May allocate / update GL textures against the supplied glow::Context.
  3. May bind extension-imported EGLImages onto a persistent texture.
  4. Returns the glow::Texture to sample, or None to paint transparent (e.g. while the first frame is still being produced).

Returning None for one frame and Some for the next is fine; LTK re-invokes on every redraw.

§Use cases

  • ltk-webkit hosting a WPEView-rendered page.
  • Video / media playback widgets that decode into a GL texture.
  • Any embedding that already has a GLES producer and wants its output in-line with the rest of the LTK widget tree.

§Example

let cached_texture: Arc<Mutex<Option<glow::Texture>>> = Arc::new( Mutex::new( None ) );
let cached = Arc::clone( &cached_texture );
External::new(
    800.0, 600.0,
    ExternalSource::Texture( Arc::new( move | _gl, _rect | -> Option<glow::Texture>
    {
        *cached.lock().ok()?
    } ) ),
).into()

Structs§

  • A widget that defers its pixels to an external GL texture producer.

Enums§