Merge dom and component focus (#978)

Instead of two levels of focus with `focus` and `selected`, use a recursive
level. The components set the one "active" and hbox/vbox/dbox 

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Ayaan
2025-03-19 20:03:05 +05:30
committed by GitHub
parent 8519e9b0f3
commit b0e087ecef
38 changed files with 431 additions and 341 deletions

View File

@@ -96,9 +96,9 @@ class InputBase : public ComponentBase, public InputOption {
private:
// Component implementation:
Element Render() override {
Element OnRender() override {
const bool is_focused = Focused();
const auto focused = (!is_focused && !hovered_) ? select
const auto focused = (!is_focused && !hovered_) ? nothing
: insert() ? focusCursorBarBlinking
: focusCursorBlockBlinking;
@@ -108,15 +108,12 @@ class InputBase : public ComponentBase, public InputOption {
// placeholder.
if (content->empty()) {
auto element = text(placeholder()) | xflex | frame;
if (is_focused) {
element |= focus;
}
return transform_func({
std::move(element), hovered_, is_focused,
true // placeholder
}) |
reflect(box_);
focus | reflect(box_);
}
Elements elements;
@@ -176,7 +173,7 @@ class InputBase : public ComponentBase, public InputOption {
elements.push_back(element);
}
auto element = vbox(std::move(elements)) | frame;
auto element = vbox(std::move(elements), cursor_line) | frame;
return transform_func({
std::move(element), hovered_, is_focused,
false // placeholder