ltk

Module types

Source
Expand description

Geometry and primitive value types used across the public API.

These are the cheap, copy-friendly types that flow through every widget builder, layout method and runtime hook:

  • Color — RGBA in [0.0, 1.0] floats; Color::WHITE, Color::BLACK, Color::TRANSPARENT constants and a Color::hex(r, g, b) constructor for byte literals.
  • Rect — axis-aligned (x, y, width, height); the universal layout / hit-test currency.
  • Point — a 2D point used by hit testing and gesture progress.
  • Size — a (width, height) pair without an origin.
  • Corners — per-corner radius for the Container widget and any other rounded surface; coerces from f32 for the uniform case.
  • WidgetId — a stable identifier, a &'static str name and a key, for focus management, paired with crate::App::take_focus_request.

Every type is Copy (or Clone) so passing them by value is the default. The crate root re-exports them all (ltk::Color, ltk::Rect, …) so application code rarely needs the ltk::types:: prefix.

Structs§

  • An RGBA color with floating-point channels in the range [0.0, 1.0].
  • Per-corner radii for a rounded rect, ordered top-left → top-right → bottom-right → bottom-left (clockwise from top-left, matching CSS border-radius’s long form). All four values are independent pixel radii — set any subset to 0.0 for a square corner, or use the top, bottom, left, right shortcuts for the common asymmetric cases.
  • A size or distance value that may be expressed in absolute pixels or relative to the rendering surface. Every widget API that used to take f32 for a size, padding, spacing or font height now takes impl Into<Length>, so existing call sites keep compiling unchanged while new code can switch to viewport-relative units for layouts that must scale across screen sizes (portrait phone, landscape tablet, 4K desktop) without per-target tweaks.
  • A 2-D point in screen coordinates (pixels, top-left origin).
  • An axis-aligned rectangle in screen coordinates.
  • A width/height pair in pixels.
  • A stable widget identifier used for focus management.

Enums§

  • How a draw combines with what the canvas already holds: the Porter-Duff operators plus the separable modes with an exact premultiplied form. Set with Canvas::set_composite_mode.
  • Pointer cursor shape, sent to the compositor via wp_cursor_shape_v1 when the pointer enters a widget that declares one. Mirrors cursor_icon::CursorIcon 1:1 so the runtime can convert losslessly. Compositors that do not advertise wp_cursor_shape_v1 ignore these — the user sees their default system cursor.
  • One of the pure relative-or-absolute modes a Length can carry. Split out so Length itself can stay Copy while still supporting optional clamp bounds — the recursive Clamp variant of the original sketch would have forced a Box allocation, which on a widget tree that builds these values per frame is the wrong trade.
  • Orientation of the main surface, derived from the dimensions recorded by set_viewport_size.
  • One command of a vector path, in canvas (surface) coordinates. Fed to Canvas::fill_path / stroke_path to render arbitrary shapes (e.g. an Android Path / a Lottie frame).
  • How a stock widget adapts its intrinsic geometry to the display when the app does not override it. The two modes ltk offers, chosen per process with set_widget_scaling:

Constants§

  • Upper auto-clamp factor of Length::fluid: a fluid value never resolves above px * FLUID_MAX, so it stays tasteful on a huge surface.
  • Lower auto-clamp factor of Length::fluid: a fluid value never resolves below px * FLUID_MIN, so it stays usable on a tiny surface.

Functions§

  • The id of a single widget, the same as WidgetId::keyed with key 0.
  • Current pixel density — the factor Length::dp multiplies its design pixels by. 1.0 until the runtime or set_density sets it.
  • Current reference used by Length::fluid — the short-side px at which fluid( n ) resolves to n px before clamping.
  • Orientation of the main surface: Orientation::Landscape when wider than tall, Orientation::Portrait otherwise (square counts as portrait, matching Length::orient’s resolution rule). Usable straight from view() to pick a row or a column arrangement without tracking on_resize by hand — the runtime rebuilds the view on every resize, so a layout branched on this follows the window live.
  • Logical size of the screen the main surface is on, or None before the compositor has described one. Unlike viewport_size it does not follow the window, so it can size things relative to the display.
  • Set the process-wide pixel density used by Length::dp (the WidgetScaling::Physical mode). The runtime sets it to the main surface’s buffer scale right before crate::App::on_scale_changed, so dp( n ) is n logical px by default; an app that wants a DPI-derived density overrides it from that callback. Default: 1.0.
  • Set the reference surface (short-side px) that Length::fluid interprets its design pixels against. Call once at startup (e.g. before crate::run) to align the fluid scale to the surface mock-up the app was designed for. Default: 412 px.
  • Record the logical size of the output the main surface is on. The runtime calls this when outputs appear, change or go away, and when the main surface enters one. ( 0, 0 ) clears it.
  • Set the global text scale multiplier applied to every resolved font size (the accessibility “large text” factor). Clamped to [0.5, 3.0]. The run loop keeps it synced to the desktop’s org.gnome.desktop.interface text-scaling-factor GSettings key and repaints on change, so apps normally never call this themselves; embedders driving crate::core::UiSurface directly do.
  • Record the main surface’s physical dimensions. The runtime calls this on every configure, before App::on_resize; embedders driving core::UiSurface directly should call it themselves if they want viewport_size / orientation to reflect their surface.
  • Set the process-wide WidgetScaling mode for stock-widget defaults. Call once at startup. Default: WidgetScaling::Fluid.
  • Current text scale multiplier. Default 1.0.
  • Physical dimensions of the main surface as of the last configure. ( 0, 0 ) before the first one.
  • Current WidgetScaling mode. WidgetScaling::Fluid until set_widget_scaling changes it.