-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request focus on widget #145
Comments
Widgets can currently request focus by using I like both of the proposed APIs and I think they could work well together! The This proposal would probably require us to either move some input state into the |
Instead of a pending requested focus on I've done that at #146 |
I'd like to bring back the idea of handling this in Input. I propose adding: The reason for this is that it would be useful to be able to sequentially request focus then send input events to the focused widget. For instance Move cursor to the end of an input yak.handle_event(Event::RequestFocus(Some(chat_widget)));
// or: `yak.request_focus(Some(chat_widget));`
yak.handle_event(Event::KeyChanged{ key: KeyCode::End, down: true});
yak.handle_event(Event::KeyChanged{ key: KeyCode::End, down: false}); Activate multiple text inputs for textbox in textboxes {
yak.handle_event(Event::RequestFocus(Some(textbox)));
// or: `yak.request_focus(Some(textbox));`
yak.handle_event(Event::KeyChanged{ key: KeyCode::Enter, down: true});
yak.handle_event(Event::KeyChanged{ key: KeyCode::Enter, down: false});
}
yak.handle_event(Event::RequestFocus(None));
// or: `yak.request_focus(None);` There could be a fn request_focus(&mut self, widget_id: Option<WidgetId>) {
self.handle_event(Event::RequestFocus(widget_id));
} But also feeding fake input events to yakui to do things that maybe should be supported through their own APIs is maybe a huge hack. So I understand if that's not really desirable. The behavior of the current dom API is also a little bit subtle. You might use it like: // Doctor, it hurts when I do this
yak.dom().request_focus(chat_input);
yak.handle_event(Event::KeyInput{ key: KeyCode::End, bool: true});
yak.handle_event(Event::KeyInput{ key: KeyCode::End, bool: false});
// Doctor: have you tried not doing that and expect these events to happen sequentially, but the acutal widget focus will happen only on the next dom rebuild. Moving the api from This breaks the SummaryI don't think |
Sometimes we think about custom events in yakui that are local to widgets. We don't personally believe that, as a UI library focused on providing you with scaffolding to build your own, and not providing a fully fleshed out UI, we should aim to provide this stuff instead. There's an idea to take the request_focus stuff and think about it in another way: Exclusivity. There's a lot of ways to do this, maybe something like a An idea is to somehow leverage Rust's type system and perhaps use a typemap or something, and then you can import common events like This can be nice because you can stuff all the collected events into the Yakui state, move it and pass it around in all the widgets as they handle them. Perhaps one would also need to use the widget Id to use this in situations like focusing a single widget. Any thoughts? We'd like to discuss 💯 |
Currently writing a simple chat. I'd like to be able to automatically focus the textbox when pressing "T" and the textbox appears.
There appears to be some state about which widget is focused as there is
WidgetEvent::FocusChanged
.I was thinking of adding a method to the Dom with a widget id. Would that be a good API?
so you could do
could even be implemented on top of Response
The text was updated successfully, but these errors were encountered: