-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Improve ColorPicker picker shape keyboard and joypad accessibility #99374
base: master
Are you sure you want to change the base?
Improve ColorPicker picker shape keyboard and joypad accessibility #99374
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support this usability improvement in the proposal design, but it needs technical review.
The hue slider goes exactly 3.6× slower than value slider in another shape, so your estimations were pretty correct. ^^ It is by design - value and saturation have values 0-100, but hue has values from range 0-360. Making each button press to increase hue in bigger increments always would miss some values. But I added a multiplier if the event is echo, so after few repetions it speeds up. But again, as for now it does not affect controllers. What I'm wondering now is if we should have it configurable in the editor, both for games and for ColorPickers in the editor somehow (in editor settings?). What do you think @Calinou ?
Fixed, please check it now: Nagrywanie.ekranu.2024-11-28.163308.mp4I thought about making the cursor to spin around on the edge if you keep holding the same button, but while it went well for the HSV Wheel shape, it was buggy for both Circle shapes, so I stashed it for now. This is how it looked for HSV Wheel: Nagrywanie.ekranu.2024-11-28.160945.mp4I am not sure if it is worth to try implementing it well for all Circle shapes or skip it, as I don't know if anyone will take advantage of this feature. |
This would be a pretty niche option, so I'd focus on picking a good default instead. |
#82979 could be used for better joypad navigation if it was merged. For now the only way is implement the behavior using NOTIFICATION_PROCESS manually, like it was done in Slider for example. Though the joypad navigation is a bit janky right now. When you enter the main color box, the only way out is either accepting or canceling; you can no longer select another element. There could be 2 focus modes here: one for navigating the elements and one for changing colors using the elements. You could switch them with accept/cancel. We have that in LineEdit. |
scene/gui/color_picker.h
Outdated
@@ -267,6 +274,8 @@ class ColorPicker : public VBoxContainer { | |||
void _sample_draw(); | |||
void _hsv_draw(int p_which, Control *c); | |||
void _slider_draw(int p_which); | |||
int get_wheel_h_change(Vector2 color_change_vector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused.
// HACK: I cannot draw focus stylebox on the wheel itself, as it's drawing based on shader. | ||
wheel_h_focus_display = memnew(Control); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use wheel_uv
for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In one moment I did. But it meant that I had to add logic for navigating between two focus modes for this control, capturing next/prev actions, because wheel_uv would be used to handle focus for both parts of HSV Wheel.
It added more complexity to the class that is already overloaded with a lot of ifs and was not working well always (like it was sometimes looping focus between those two states when holding ui_focus_prev
action instead of leaving the control and switching to the hex LineEdit. I thought that adding another control for both drawing the focus stylebox and making switching focus more reliable is a better choice.
If it's better to have few more ifs than using this empty control, I can work on it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#99515 makes the code cleaner.
If your PR happens to be merged first, I'll simplify it and integrate with my changes.
scene/gui/color_picker.cpp
Outdated
} else if (actual_shape == SHAPE_VHS_CIRCLE || actual_shape == SHAPE_OKHSL_CIRCLE) { | ||
Vector2 center = c->get_size() / 2.0; | ||
|
||
// HACK: It's a hack, as it messes up if I calculate it this way always. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does HACK refer to? Vector2i()
is initial value of the cursor vector, so it needs to be initialized. Not sure what the other condition is for, it can be safely removed it seems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I wanted to save the cursor position calculated in _hsv_draw
and use it in _uv_input
, but the cursor was moving in strange directions, as I mentioned in another comment. I checked if calculating it here every time would fix the issue, but it didn't. That's why I decided to calculate it only if it was not set (or was reset by clicking with mouse) and this is what the hack refers to, as it is not the way I think it should be done, but it does not seem to work well with the correct way. I might
Not sure what the other condition is for, it can be safely removed it seems.
I added it when I was working on sliding along the edge of the circle when you keep pressing any direction. But it seems it is not needed now. Removed.
// TODO: Think about better name or a way to not use it at all | ||
Vector2i hsv_keyboard_picker_cursor_position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A way to not use it is keeping the variable local in _uv_input()
, which means calculating sin/cos again every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hack mentioned in another place is connected with issues with calculating sin/cos again every time. I tried it at the beginning and it's behaviour was strange - the cursor was not going in straight lines. I believe it might be caused by some precision loss while calculating this, or something like that.
I realized that even when you drag the cursor with mouse, the offset of it's center and the mouse cursor is changing, depending on how high or low on the circle you are. You can see that on this video:
Nagrywanie.ekranu.2024-12-09.091855.mp4
I did it like in Slider, thanks for the suggestion. I tried with
I added this second focus mode like in LineEdit. I thought about it before, but I didn't see benefits in my usecase so I skipped it before. It works well, for both LineEdit and ColorPicker picker shapes now if you use a ColorPicker directly. But if you show it via ColorPickerButton, it failes in both cases. The reason is that both accept and cancel actions close the popup that ColorPicker is in. You can see the behaviour on this video: 2024-12-07.20-37-02.ColorPicker.shape.focus.like.LineEdit.mp4I didn't bother to implement this as I use focus next/prev actions to navigate through ColorPicker's controls. I configured inputs for those actions to shoulder buttons and I was using them to test this feature. I forgot that by default there are no joypad buttons connected to those actions. Is there any reason this is not done by default? I wonder if I can simply configure them within this PR to make it work better out of the box.
Done. I had it stashed, as I mentioned in one of the previous comments here, as I wasn't sure if I should try and implement similar behaviour for both circle shapes. In the end I separated their behaviours. |
You could try using |
I do. What I see now while debugging is that the |
While experimenting with accessibility, I realized that ColorPicker does not allow you to move the picker cursor around the color rectangle/wheel with keyboard or joypad (and I needed it, as it's the only part of ColorPicker that I want to show).
This PR implements:
How it works in game and in the editor:
ColorPicker.keyaboard.and.joypad.game.mp4
ColorPicker.keyboard.editor.mp4
I don't really like how it works with the controller, as I'm using
gui_input
to check for actions and the controller does not send echo events, but it's possible to use the controller at least.