linebender / linebender/druid

Focusing widgets

Open
#1,087 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion widget
Dominant language
Rust
Stars
9.7k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Hello there, at the moment API for focusing widgets quite unfinished, I have been playing around with it.

I would like to suggest such an API: add two widgets FocusScope - serves as a scope for its descendants, restricting focus traversal to the scoped controls, it can be useful if I would like to add some overlay UI like alert and strict scope for this area. We could create FocusSope in the root by default.

Focus widget - is a control widget that can capture the focus and spread focus state to its descendants; in that case, all descendants can receive keyboard events. It's nice to have such a widget because we could handle all focus events like request next and previous focus only there. And we can wrap up focusable widgets, which could handle keyboard events to some other decorator widgets that also could be rendered differently depends on focus state.

I have already implemented the Focus widget and now working on the FocusScope widget; it's much trickier.

**Example:**

```rust
let input = Focus::new(
AccessorDecorator::new(
FocusDecorator::new(),
AccessorDecorator::new(
TextboxDecorator::new(),
TextBox::new()
.with_placeholder("Enter the command")
.fix_width(TEXT_BOX_WIDTH)
.lens(HelloState::name),
)
.padding(2.0),
),
);
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing focus API and the Focus, FocusScope, FocusDecorator, and AccessorDecorator entry points shown in the issue. Compare the implemented Focus behavior with the proposed descendant scoping and keyboard-event behavior. Done means the intended Focus and FocusScope semantics are defined and implemented consistently with the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.