Skip to content

[Feature] Button widget #150

@vmarcella

Description

@vmarcella

Overview

Add a button widget that responds to mouse clicks and displays text or an icon.

Current State

No response

Scope

Goals:

  • Text button with label
  • Click detection
  • Visual states (normal, hover, pressed, disabled)
  • Callback on click

Non-Goals:

  • Icon buttons
  • Toggle buttons
  • Styling

Proposed API

pub enum ButtonState {
  Normal,
  Hovered,
  Pressed,
  Disabled,
}

pub struct Button {
  label: String,
  state: ButtonState,
  on_click: Option<Box<dyn Fn()>>,
}

impl Button {
  pub fn new(label: &str) -> Self;
  pub fn on_click(self, callback: impl Fn() + 'static) -> Self;
  pub fn set_enabled(&mut self, enabled: bool);
  pub fn state(&self) -> ButtonState;
}

impl Widget for Button {
  fn render(&self, ctx: &mut UiRenderContext) -> Vec<RenderCommand>;
  fn hit_test(&self, x: f32, y: f32) -> bool;
  // Mouse event handling internally updates state
}

Acceptance Criteria

  • Button displays label text
  • Hover state when mouse over
  • Pressed state when mouse down
  • Click callback fires on mouse up inside
  • Disabled state ignores i

Affected Crates

lambda-rs

Notes

  • State transitions: Normal <-> Hovered <-> Pressed
  • Click fires only if release is inside button

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