Skip to content

feat: resolve widget styles in one place, with named states - #50

Merged
M4n0x merged 12 commits into
mainfrom
feat/style-states
Oct 16, 2026
Merged

M4n0x merged 12 commits into
mainfrom
feat/style-states

Conversation

@M4n0x

@M4n0x M4n0x commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fixes #15.

Bar widgets, workspace cells, layout and popup blocks and the bar each worked out their style in their views. They used different rules and had no tests, so every new kind of state needed a layer in four places. Built-in providers couldn't change their style by value at all.

Changes

  • One resolver (two refactor commits and a perf):
    • Bar widgets, the bar, workspace cells and blocks resolve their styles through one tested function.
    • The store resolves widget styles, so a script update redraws only the widgets it affects instead of every widget and the bar.
  • states on every style. A style can have states that apply over it while a state is active: hover, open, the workspace states focused, visible and empty, and data states.
    • Shorthand. The existing keys stay: hoverBackground and hoverForeground for states.hover, and focusedStyle, visibleStyle, emptyStyle, focusedAppStyle and visibleAppStyle for the workspace states.
    • Underline. The underline takes focused and visible states.
    • Merging. States merge through includes, templates, profiles, widget overrides and packages, themes included, one state and property at a time. A later layer removes a state with null.
    • Shorthand against states. They are compared after the layers merge, so a states.hover.background from any layer wins over hoverBackground from any layer. The README's States section says so.
    • Colors. Colors inside states take light and dark pairs and tokens.
    • Customize. The Hover background rows show the hover the bar draws and where it comes from. They write the shorthand and clear states.hover.background, so the chosen color beats an include's hover state while an active profile still wins.
  • open state for a widget whose popup shows, on the instance that opened it.
  • Data states. Script and provider output can set "state", and rules set a state from a built-in provider's values or fields, such as battery below 20 %. The README documents the shared names warning, critical, active and muted, and the modular example's theme defines them.
  • Two fixes. An empty state name counts as no state. Contradictory width limits inside states are rejected, like those in base styles.
  • Docs.
    • The README's States, Data states and rules sections.
    • In the examples, each data state that sets a background also sets its own hover background, since hover applies over the data state.

Left out, as in the issue's proposal:

  • a window-manager mode as a workspace state;
  • states on bar.style and groups;
  • Customize controls for states. States can be edited as JSON in the widget inspector's Advanced properties.

Testing

  • Suite: swift test passes 175 tests: main's 130 and 45 new ones. Every commit builds with its tests and passes the suite.
  • New tests cover:
    • the resolver for each surface;
    • states merging across layers and through edits;
    • the open state;
    • data states from output and from rules;
    • light and dark colors in states;
    • Customize's hover rows over an include, a template and an active profile.
  • Themes: a scratch test, not committed, found that all eight bundled themes draw the same resting, hover, popup and bar colors as on main.
  • Redraws: a view-level Observation test shows that one script output invalidates only its widget, where before it invalidated every widget and the bar. This wasn't measured with Instruments. Two whole-bar invalidations are unchanged from main:
    • the overflow menu reads overflowed outputs;
    • every widget reads store.actionErrors, so a failed action redraws every widget.
  • Screenshots: not yet. Before/after screenshots will follow in this pull request: the open state (examples/interactive), data states (examples/modular), workspace states and Customize's hover rows.

Merging

A merge commit, so each commit reaches the changelog: four feat, two fix and one perf.

Issues #16 and #17 build on this branch. Their pull requests will follow.

Claude Opus 5.5 via Claude Code

M4n0x added 12 commits October 16, 2026 19:52
…ts widgets

The setup preview shows the bar's scripts through a second store. It prepares its own
presentations, and scripts report to the first store that prepared them, so the bar keeps
its updates.
Every style object accepts a states map, and the hover shorthand keys fold into it; when one
style sets both, states wins. focusedStyle, visibleStyle, emptyStyle, focusedAppStyle and
visibleAppStyle are shorthand for workspace states, and the underline takes focused and visible
states. States merge through includes, templates, profiles, widget overrides and packages,
theme packages included, one state and property at a time, and a later layer removes one with
null. Colors inside states take light and dark pairs and tokens. The modular example's theme
sets its hover color as a state.

Customize's hover background rows show the hover the bar draws and set the shorthand with
states.hover.background cleared, so their color beats an include's state while an active
profile still wins.
…round

Hover applies over the data state, so a hover background replaced the background a state such
as critical set while keeping its text color: dark text on the modular theme's hover color,
and white text on the theme's hover color in the README's example. Both now set a hover
background in the state's own states, the README says to do so, and a test pins the modular
theme's hovered critical colors.
An output with "state": "" counted as a state named "", so it blocked the widget's rules and
the snapshot reported an empty state. It now counts as no state: rules still apply and the
snapshot reports none. A rule with an empty state is rejected when the configuration loads,
naming its path, and the schema requires at least one character.
minWidth and maxWidth were checked only on a widget's base style merged over the defaults, so a
state such as states.hover.minWidth above the maxWidth, or a negative minWidth inside a state,
loaded and would have given contradictory frames. Each state merged over that style is now
checked too, with the same messages.
The data state of a widget's resolved style can come from its rules as well as its output, and
dataState now takes the rules as a second argument.
A later states.hover set to null doesn't remove a hover set with hoverBackground or
hoverForeground, because the shorthand is folded back in, so those need a null too. The open
state also reaches a widget's overlay, and a block's own background, border and other box
properties change for it only through that block's own states.
@M4n0x
M4n0x requested a review from Seb-GRAF as a code owner October 16, 2026 18:29
@M4n0x
M4n0x merged commit deb8b01 into main Oct 16, 2026
4 checks passed
@M4n0x
M4n0x deleted the feat/style-states branch October 16, 2026 19:37
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve widget styles in one place, with named states

1 participant