Skip to content
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

Add a focus border on ScrollContainer #97521

Merged

Conversation

pafuent
Copy link
Contributor

@pafuent pafuent commented Sep 27, 2024

Also added child_has_focus function to Control. This is used by ScrollContainer to detect if one of its childs has focus and should draw the focus border.
Also added focus SceneStringName.
Also added new unit tests for Control.

Supersedes #59362

ScrollContainerFocusBorder

@pafuent pafuent requested review from a team as code owners September 27, 2024 03:17
@pafuent
Copy link
Contributor Author

pafuent commented Sep 27, 2024

@ator-dev, here is the re-implementation of your PR on master
If you have some spare cycles I would really appreciate if you can test it and verify that I capture properly all your intentions.

@WhalesState
Copy link
Contributor

WhalesState commented Sep 28, 2024

I like it, but it may be more useful if we can scroll the view with Ctrl + Arrow keys when the focus style is drawn ie. the ScrollContainer or one of it's children has focus, also you will need to accept the events to avoid focusing another child when the ctrl is pressed.

@pafuent
Copy link
Contributor Author

pafuent commented Sep 30, 2024

I like it, but it may be more useful if we can scroll the view with Ctrl + Arrow keys when the focus style is drawn ie. the ScrollContainer or one of it's children has focus, also you will need to accept the events to avoid focusing another child when the ctrl is pressed.

Should I add this in this PR or in another?
To be honest, I tried to do it to see if the change is small and decide if I should create a new PR, but my knowledge about Godot GUI is pretty limited and the result that I got was not satisfactory.

@WhalesState
Copy link
Contributor

Should I add this in this PR or in another? To be honest, I tried to do it to see if the change is small and decide if I should create a new PR, but my knowledge about Godot GUI is pretty limited and the result that I got was not satisfactory.

It's ok, I think i can do it later since we can't rely on gui_input() when a child is focused, this will require a new variable focused and a scroll_page to define how much we should scroll when a key is pressed and to use shortcut_input, so i don't think it will be merged to 4.x if we apply all those changes at once.

@ator-dev
Copy link
Contributor

Great to see this discussion and thanks for the reimplementation PR!

If you have some spare cycles I would really appreciate if you can test it and verify that I capture properly all your intentions.

I'm sorry, although I mean to, I'm really busy at the moment. What's most important is that the result is accessible and doesn't affect anything weirdly.

@pafuent
Copy link
Contributor Author

pafuent commented Oct 1, 2024

I'm sorry, although I mean to, I'm really busy at the moment. What's most important is that the result is accessible and doesn't affect anything weirdly.

No problem!

@WhalesState
Copy link
Contributor

WhalesState commented Oct 2, 2024

Note: The focus StyleBox is clipped for the default theme, this should be documented that it will require a focus StyleBox to be drawn without expanding and adding some content margin for the ScrollContainer panel style to avoid drawing the focus StyleBox behind the children.

Edit: I see you're not using the default focus style for the ScrollContainer, so in both cases, you will need to document this since the users will not be able to see the focus style box because it's empty when they enable this feature.

@pafuent
Copy link
Contributor Author

pafuent commented Oct 3, 2024

Note: The focus StyleBox is clipped for the default theme, this should be documented that it will require a focus StyleBox to be drawn without expanding and adding some content margin for the ScrollContainer panel style to avoid drawing the focus StyleBox behind the children.

Could you please elaborate this? I'm still too new to Godot GUI.

Edit: I see you're not using the default focus style for the ScrollContainer, so in both cases, you will need to document this since the users will not be able to see the focus style box because it's empty when they enable this feature.

When you say that I should add/update documentation, Are you talking about this file, right?

I'm wondering where I could document the use set_draw_focus_border because that method is public but is not bind/exposed to Godot Engine users. It's not clear to me if this method will be available through GDExtension just because the method is public. If that is the case, Where I should document that GDExtension new method? If not, Will be enough if I add a comment in the C++ code?

@WhalesState
Copy link
Contributor

WhalesState commented Oct 3, 2024

One more change is to check if (Engine::get_singleton()->is_editor_hint()) inside ScrollContainer cpp file to avoid running the code when we run a scene in editor builds.

@pafuent pafuent force-pushed the enhance_scroll_container_focus branch from 3fd9448 to 10a88ae Compare October 3, 2024 20:28
@pafuent
Copy link
Contributor Author

pafuent commented Oct 3, 2024

One more change is to check if (Engine::get_singleton()->is_editor_hint()) inside ScrollContainer cpp file to avoid running the code when we run a scene in editor builds.

Done

@pafuent
Copy link
Contributor Author

pafuent commented Oct 4, 2024

@AThousandShips sorry if I tag you wrongly, but this CI job is being running for more than 5 hours. I know I can "stop" it submitting a new commit into the PR, and I'll do it soon, but I would like to let you know because you could set a configuration on GitHub or something to kill stuck CI actions.

image

@pafuent pafuent force-pushed the enhance_scroll_container_focus branch from 10a88ae to 6a2c7e1 Compare October 4, 2024 02:32
@pafuent pafuent force-pushed the enhance_scroll_container_focus branch from 2a95377 to 3235814 Compare November 20, 2024 03:37
@pafuent
Copy link
Contributor Author

pafuent commented Nov 20, 2024

I think I got it working.
ScrollContainerFocusOnRuntime

@pafuent pafuent force-pushed the enhance_scroll_container_focus branch 2 times, most recently from 293ff8c to d03d8b1 Compare November 20, 2024 11:44
@KoBeWi
Copy link
Member

KoBeWi commented Nov 20, 2024

Tested and it seems to work correctly.
ScrollContainer does not need to be focused to display the border, so I think the focus change to the inspector is not needed.
Could be nice to have some default focus style in default theme, you could copy some existing one.

@pafuent
Copy link
Contributor Author

pafuent commented Nov 20, 2024

@KoBeWi sorry but I'm not getting this:

ScrollContainer does not need to be focused to display the border, so I think the focus change to the inspector is not needed.

@pafuent pafuent force-pushed the enhance_scroll_container_focus branch 3 times, most recently from d52846a to 7f03663 Compare November 23, 2024 02:50
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good.

@pafuent pafuent force-pushed the enhance_scroll_container_focus branch from 7f03663 to 1bf1ab9 Compare November 24, 2024 02:24
Also added new unit tests for `Control`.

Co-authored-by: ator-dev <dominic.codedeveloper@gmail.com>
@pafuent pafuent force-pushed the enhance_scroll_container_focus branch from 1bf1ab9 to 86ea012 Compare November 24, 2024 02:54
@akien-mga akien-mga modified the milestones: 4.x, 4.4 Nov 28, 2024
@akien-mga akien-mga merged commit 8d3fc48 into godotengine:master Nov 29, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@@ -3281,6 +3281,8 @@ void EditorPropertyResource::update_property() {
sub_inspector->set_read_only(is_read_only());
sub_inspector->set_use_folding(is_using_folding());

sub_inspector->set_draw_focus_border(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sub_inspector needs to grab focus, but not show the style? It seems that sub_inspector does not need to grab focus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants