Replies: 1 comment
-
|
@RtlZeroMemory Take your time to review. I'd like to hear your thoughts, if perhaps my real-world usage are already possible and maybe I've missed how. I'd also like to know if I am thinking in the right abstractions and similar direction as your vision. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
Building interactive TUI apps with Rezi means constantly reacting to focus state — highlighting the active row, changing a button's label, dimming an inactive panel. Today this requires boilerplate: tracking focus IDs in app state, comparing them manually during render, and wiring up blur/focus callbacks just to change a style or a string.
Focus and focus zones (
ui.focusZone) are already part of the core framework. It makes sense for the framework to also pass that state back as optional render-time context, so building highly interactive apps is fun and easy rather than tedious.This is a pattern I've used across multiple apps I've built with custom focus engines, and it's by far the most common thing I reach for. I believe it would be a very likely and commonly used feature for anyone building interactive Rezi apps.
Idea
Allow children and labels of interactable nodes to optionally be callbacks that receive focus context at render time.
Button label as callback
FocusZone children as callback
Real-world usage
I've been using this pattern in my project via a patched
@rezi-ui/core. Here's how it plays out in practice:1. Header buttons show a focus indicator
Each column header shows a
▸arrow only when focused — all columns update reactively with no imperative state:2. Virtual list rows respond to zone focus
Rows change background color depending on whether their parent zone is active — passed declaratively through
zoneFocused:Inside the Row component:
3. Context-aware status bar
Help text in the status bar changes based on which zone id is focused (as
string), with no manual subscriptions:4. Higher-level action zones
The pattern composes naturally into
ui.focusTrapandui.focusZoneabstractions — with newui.actionZone(orui.keyZone) keybindings are automatically registered/unregistered based on zone focus.How it could work
All changes below are quite straight forward and easy.
activeZoneIdandfocusedIdsynchronously before eachviewFn(snapshot)call in widgetRendererbutton()checks if its label is a function — if so, calls it with{ focused: boolean }focusZone()checks if its children is a function — if so, calls it with{ zoneFocused: boolean }routeEngineEventcomputesneedsCommit = didZoneChange || didFocusChangeand returns it alongsideneedsRenderin every return pathif (routed.needsCommit) markDirty(DIRTY_VIEW)right after the existingneedsRendercheckPerformance
The proposed changes add zero overhead for the following reasons:
typeofcheck. When a callback is passed, it's one immediate function call that resolves to the same string or array the framework already expects.Thoughts / Other considerations
I am aware the current state of app quite unstable and rapidly changing, therefore I am not pushing for this to be implemented immediately. Rather I would only like to hear thoughts and keep this as a proposal for a future release.
Happy to contribute a PR if there's interest. I have been experimenting with these changes successfully in my app (by patching the core) and they work perfectly without any issues. This makes my app UI app in Rezi very intractable and more fun to build :)
Beta Was this translation helpful? Give feedback.
All reactions