@@ -44,17 +44,23 @@ export struct FocusListener {
4444 }
4545};
4646
47+ struct FocusableProps {
48+ bool visual = true ;
49+ bool steal = false ;
50+ };
51+
4752struct Focusable : ProxyNode<Focusable> {
4853 bool _focused = false ;
54+ FocusableProps _props;
4955
50- Focusable (Ui::Child child)
51- : ProxyNode<Focusable>(std::move(child)) {
56+ Focusable (Ui::Child child, FocusableProps props )
57+ : ProxyNode<Focusable>(std::move(child)), _props(props) {
5258 }
5359
5460 void paint (Gfx::Canvas& g, Math::Recti r) override {
5561 ProxyNode<Focusable>::paint (g, r);
5662
57- if (_focused) {
63+ if (_props. visual and _focused) {
5864 g.strokeStyle (Gfx::stroke (ACCENT500).withWidth (2 ).withAlign (Gfx::INSIDE_ALIGN));
5965 g.stroke (bound ().cast <f64 >(), 4 );
6066 }
@@ -93,17 +99,23 @@ struct Focusable : ProxyNode<Focusable> {
9399 }
94100
95101 if (_focused or passthrough)
96- ProxyNode<Focusable>::event (e);
102+ ProxyNode::event (e);
103+
104+ if (e.is <RebuiltEvent>() and
105+ _props.steal and
106+ not _focused) {
107+ _stealFocus ();
108+ }
97109 }
98110};
99111
100- export Ui::Child focusable (Ui::Child child) {
101- return makeRc<Focusable>(std::move (child));
112+ export Ui::Child focusable (Ui::Child child, FocusableProps props = {} ) {
113+ return makeRc<Focusable>(std::move (child), props );
102114}
103115
104- export auto focusable () {
105- return [](Ui::Child child) {
106- return focusable (std::move (child));
116+ export auto focusable (FocusableProps props = {} ) {
117+ return [props ](Ui::Child child) {
118+ return focusable (std::move (child), props );
107119 };
108120}
109121
0 commit comments