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 &'static str identifier 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§

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

Functions§