Skip to content

[Feature] UI widget base trait and rendering #148

@vmarcella

Description

@vmarcella

Overview

Define the base widget trait that all UI elements implement and establish the
rendering model for UI components.

Current State

No response

Scope

Goals:

  • Widget trait defining common interface
  • Widget bounds and layout rect
  • Basic rendering abstraction
  • Hit testing for input handling

Non-Goals:

  • Specific widget types
  • Layout system
  • Styling

Proposed API

// crates/lambda-rs/src/ui/widget.rs
pub struct Rect {
  pub x: f32,
  pub y: f32,
  pub width: f32,
  pub height: f32,
}

impl Rect {
  pub fn contains(&self, x: f32, y: f32) -> bool;
}

pub trait Widget {
  fn bounds(&self) -> Rect;
  fn set_bounds(&mut self, rect: Rect);
  fn render(&self, ctx: &mut UiRenderContext) -> Vec<RenderCommand>;
  fn hit_test(&self, x: f32, y: f32) -> bool;
}

pub struct UiRenderContext<'a> {
  render_context: &'a mut RenderContext,
  // UI-specific state
}

Acceptance Criteria

  • Widget trait is object-safe (can use dyn Widget)
  • Bounds stored and queryable
  • Hit test uses bounds by default
  • Render returns commands for drawing
  • Trait extensible for specific widgets

Affected Crates

lambda-rs

Notes

  • Consider immediate-mode alternative (egui integration)

Metadata

Metadata

Assignees

No one assigned

    Labels

    UIAll things user interface relatedenhancementNew feature or requestlambda-rsIssues pertaining to the core framework

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions