Skip to content

Widget kit crate: buttons commit on release (fixes #119) - #120

Merged
IAmJSD merged 1 commit into
mainfrom
t3code/build-component-library
Sep 6, 2026
Merged

IAmJSD merged 1 commit into
mainfrom
t3code/build-component-library

Conversation

@IAmJSD

@IAmJSD IAmJSD commented Sep 6, 2026

Copy link
Copy Markdown
Member

Fixes #119.

Why

Every control in the app fired its action from gpui's on_mouse_down, so a button "clicked" the moment it went down and sliding off could not cancel it. Native buttons (AppKit, UIKit, Win32, the web) commit on release over the control, which is exactly what gpui's on_click implements.

What

  • New crate crates/ui (schist-ui). The palette, icons and tooltips move out of the app (which re-exports them), joined by Button, IconButton, Checkbox, ListItem, Tab, Link and Swatch. Every one acts on release (or Enter/Space when focused). They take plain Fn(&ClickEvent, &mut Window, &mut App) handlers so cx.listener fits directly, and implement Styled and ParentElement so a caller's refinements override the defaults. consume_press() covers buttons that sit inside selectable rows, replacing the hand-rolled stop_propagation calls.
  • Converted to the kit: dialog buttons and checkboxes, dropdown rows, menu and context-menu rows, tool flyout rows, history rows, layer eye/fold toggles, tab close buttons, panel header icon buttons, AI panel controls, typography buttons, colour swatches and wells, links, the filter gallery, and the photo gallery views. Mouse-down handlers in the app drop from 124 to 59.
  • Deliberately still on press: canvas tools, sliders, rulers, curve editor, colour wheel, drags, click-to-focus text fields, right-click context menus, sidebar and layer-row selection, tab switching, and menu/dropdown openers. Native menus open on press, and a popup dismisses on the press outside it, so a release-toggled opener would reopen at once. docs/architecture.md gains a short "Chrome" section stating the rule.

Verification

  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace all pass.
  • Headless under Xvfb with xdotool on the layer eye and the New File dialog's Cancel: a press without release does nothing, a release off the control cancels, a click acts.

Worth a glance

  • Kit buttons dim slightly while held, and icon buttons that used to be bare now get a hover fill.
  • The three small "×" controls in the gallery used to brighten their text on hover; they now show a faint hover pill, since Button's hover only changes the fill.

🤖 Generated with Claude Code

Every control in the app fired its action from gpui's on_mouse_down,
so a button "clicked" the moment it went down and sliding off could
not cancel it. Native buttons commit on release over the control, which
is what gpui's on_click implements.

Add crates/ui (schist-ui): the palette, icons and tooltips moved out of
the app, plus Button, IconButton, Checkbox, ListItem, Tab, Link and
Swatch components that all act on release. They take plain handlers so
cx.listener fits directly, implement Styled and ParentElement so callers
can override their defaults, and offer consume_press for buttons that
sit inside selectable rows.

Convert the panels, dialogs, menus, style dialog, filter gallery and the
photo gallery views to the kit. What starts a gesture keeps the press:
canvas tools, sliders, drags, click-to-focus fields, right-click menus,
row selection, tab switching, and menu/dropdown openers (native menus
open on press, and a popup dismisses on the press outside it).

Verified headlessly with xdotool: a press without release does nothing,
a release off the control cancels, and a click acts.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@IAmJSD
IAmJSD merged commit 480391e into main Sep 6, 2026
4 checks passed
@IAmJSD
IAmJSD deleted the t3code/build-component-library branch September 6, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buttons are 'clicked' before mouse release

1 participant