Giter VIP home page Giter VIP logo

Comments (15)

emoon avatar emoon commented on May 14, 2024 1

I think I will try to implement this unless it's too complicated. Any pointers before I start?

from egui.

emoon avatar emoon commented on May 14, 2024 1

Cool. Thanks! I agree with your thoughts on focus above, I will start to hack around and see where I end up and ping you on discord if needed :)

from egui.

emilk avatar emilk commented on May 14, 2024 1

I'm gonna start working on this

from egui.

emilk avatar emilk commented on May 14, 2024 1

@emoon no worries, I know the feeling :)
Please prioritize real life to egui - I sure do!

from egui.

emilk avatar emilk commented on May 14, 2024

Switching between input fields with tab and shift-tab has now been implemented on master. Pressing enter in a singleline text edit box now sets the kb_focus_lost flag in the Response object, so you can use that.

from egui.

emoon avatar emoon commented on May 14, 2024

Tested this today and it seems that I wonder if it would be possible to support for all widgets (such the way it works in a regular gui) and not just for input fields?

from egui.

emilk avatar emilk commented on May 14, 2024

That would be nice yes, but it is not very high on my priority list right now

from egui.

emilk avatar emilk commented on May 14, 2024

Wow, that would be great!

The feature that handles focus of TextEdit:s is called "kb_focus".

I think first of all, let's split this into two tasks:

A) tab also moves kb_focus to buttons, checkboxes, sliders etc
B) gamepad support for moving kb_focus up/down/left/right

Let's start with A, and postpone B until A is done.


First we have some design problems:

When clicking a TextEdit we get a cursor in it, and it is obvious it has kb_focus. If we then press tab and move focus to a checkbox, how do we indicate it has focus? We need a uniform language for focus. To start, the easiest would probably be some sort of thing colored rectangle around the widget with kb_focus (including TextEdit:s). That or changing its fg_color. This accent could perhaps become confusing when it comes to SelectableLabel which uses color to indicate "this is selected".

We can give kb_focus to a TextEdit by clicking it. Can we give kb_focus to a checkbox or slider by clicking it? I strongly vote no on this one, as it would give add some weird accent to the last button you pressed all the time. Instead I propose that the only way to give kb_focus to a button is by using tab/shift-tab.

What happens when a slider has kb_focus? Arrows to move the slider one pixel? Enter to edit the value?

How do we toggle/click buttons? Enter? Space?


As for the implementation:

Look at TextEdit. It uses interested_in_kb_focus to communicate that it want tab to select it. It asks if it has focus with has_kb_focus. So most buttons would just need to call interested_in_kb_focus and then ask has_kb_focus. It should be pretty straight-forward.

For the accent: whatever style you go with, make sure it is stored in struct Visuals


Good luck!

If you want to discuss this in more detail, you can find me in the Egui discord channel at https://discord.gg/vY8ZGS292W

from egui.

emoon avatar emoon commented on May 14, 2024

Some initial testing with checkbox (ignore the red colors for the radiobuttons, it was me playing around) :)

test

from egui.

ndarilek avatar ndarilek commented on May 14, 2024

Any new progress on this? It's something I need too, so I may take a crack at it.

from egui.

emoon avatar emoon commented on May 14, 2024

I haven't got around to do it 😞 if you want to take a stab at it that would be great!

from egui.

ndarilek avatar ndarilek commented on May 14, 2024

from egui.

emilk avatar emilk commented on May 14, 2024

@ndarilek keyboard focus is indeed part of egui::Memory, in particular these functions: https://github.com/emilk/egui/blob/master/egui/src/memory.rs#L202-L244

Basically what is needed for this issue is that all interactive widgets call interested_in_kb_focus, and then checks has_kb_focus to see if they have kb_focus, and if so paint a rectangle around them and maybe response to space/return (e.g. to press the selected button). If you are interested in working on this I suggest you check out how text_edit.rs are calling the kb_focus methods. Since a lot of widgets will do similar things (request focus, check focus, paint frame when selected, ...) it would make sense to create some helper functions for it.

from egui.

emilk avatar emilk commented on May 14, 2024

I added the accessibility and high priority labels since this is crucial for the accessibility story (#167)

from egui.

emoon avatar emoon commented on May 14, 2024

Awesome! Sorry I didn't manage to get around to do it, but real life has gotten a bit in the way :/

from egui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.