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 more fill modes to ProgressBar #46208

Merged
merged 1 commit into from
May 10, 2022

Conversation

floppyhammer
Copy link
Contributor

@floppyhammer floppyhammer commented Feb 19, 2021

Add more fill modes to ProgressBar, as TextureProgressBar already has many. Currently, only FILL_RIGHT_TO_LEFT, FILL_TOP_TO_BOTTOM, and FILL_BOTTOM_TO_TOP were implemented besides the default FILL_LEFT_TO_RIGHT mode.
progress-bar

Bugsquad edit: This closes godotengine/godot-proposals#4514.

@floppyhammer floppyhammer requested a review from a team as a code owner February 19, 2021 06:10
@floppyhammer
Copy link
Contributor Author

I have a question though. What does is_layout_rtl() do in progress_bar.cpp? Since I don't know when the function returns true, I haven't tested the fill modes in those situations yet.

@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch 2 times, most recently from 56ccafb to 4f30226 Compare February 19, 2021 06:40
@floppyhammer floppyhammer requested a review from a team as a code owner February 19, 2021 06:40
@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch from 4f30226 to f4b03fe Compare February 19, 2021 07:35
@EricEzaM
Copy link
Contributor

I have a question though. What does is_layout_rtl() do in progress_bar.cpp? Since I don't know when the function returns true, I haven't tested the fill modes in those situations yet.

It's to do with right-to-left UI layouts, typically used for languages which read R-T-L. It checks if the setting is set which makes it RLT... that's about all I know, @bruvzg could explain more.

@floppyhammer
Copy link
Contributor Author

I changed the editor language to Arabic and now is_layout_rtl() returns true. But I don't see the reason for ProgressBar to behave differently for different language layouts. Also TextureProgressBar doesn't do this check at all.

@groud
Copy link
Member

groud commented Feb 19, 2021

I changed the editor language to Arabic and now is_layout_rtl() returns true. But I don't see the reason for ProgressBar to behave differently for different language layouts. Also TextureProgressBar doesn't do this check at all.

Well, it makes sense that Right-to-Left languages have progress bars filling from the right to the left. If @bruvzg implemented it, it means that likely how things happen with right-to-left languages. Please keep this behavior.

However it is not needed for top-to-bottom and bottom-to-top, so your PR needs an edit there.

@floppyhammer
Copy link
Contributor Author

@groud But considering it's now possible to manually select from left-to-right and right-to-left fill modes, isn't it more reasonable to discard this check. Otherwise, when the left-to-right is selected by default, the progress actually goes from right to left. Instead, we could do this check when setting the initial fill mode, i.e. left-to-right for usual languages and right-to-left for rtl languages.

@groud
Copy link
Member

groud commented Feb 19, 2021

@groud But considering it's now possible to manually select from left-to-right and right-to-left fill modes, isn't it more reasonable to discard this check. Otherwise, when the left-to-right is selected by default, the progress actually goes from right to left. Instead, we could do this check when setting the initial fill mode, i.e. left-to-right for usual languages and right-to-left for rtl languages.

No, this has to be automatic, that's the point of what @bruvzg implemented.
I don't know much about the details, but if I record correctly, you can override this behavior at the Control node level.

Worst case, it could eventually be renamed to "Begin to end" or something like that. But for now, it's better to keep compatibility.

@floppyhammer
Copy link
Contributor Author

@groud Alright. But it might need some fix as it behaves like this with original code:
progress-bar3

In addition, it seems it goes from left to right by default in the first place (I moved original code inside left_to_right case block, so it should behave exactly the same way as before when left_to_right fill mode is selected).

@groud
Copy link
Member

groud commented Feb 19, 2021

@groud Alright. But it might need some fix as it behaves like this with original code

Ah, It might indeed need a bugfix I don't know.

groud
groud previously requested changes Feb 19, 2021
@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch from f4b03fe to d2d7ad0 Compare February 19, 2021 11:12
@floppyhammer floppyhammer requested review from groud and removed request for a team February 19, 2021 11:35
@Calinou Calinou added this to the 4.0 milestone Feb 19, 2021
@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch 5 times, most recently from 520d1a5 to ed54fe8 Compare February 20, 2021 00:56
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Feature looks good to me.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Should be good to merge after rebasing.

@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch from b4a4f69 to 2fafb4a Compare May 10, 2022 02:02
@floppyhammer
Copy link
Contributor Author

@Calinou Rebasing done.

@akien-mga akien-mga requested a review from bruvzg May 10, 2022 05:50
@akien-mga
Copy link
Member

I think this might not respect the UI mirroring convention for RTL. I see there's a switch in the constructor but that's only valid for the default mode.

It would likely be better to use BEGIN_TO_END instead of LEFT_TO_RIGHT and do the mirroring there.

@floppyhammer
Copy link
Contributor Author

@akien-mga Makes sense.

@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch from 2fafb4a to 8b564c0 Compare May 10, 2022 09:36
@floppyhammer
Copy link
Contributor Author

@akien-mga Might be good to go now.

Comment on lines 69 to 94
case FILL_BEGIN_TO_END: {
int mp = fg->get_minimum_size().width;
int p = round(r * (get_size().width - mp));

if (p > 0) {
if (is_layout_rtl()) {
int p_remaining = round((1.0 - r) * (get_size().width - mp));
draw_style_box(fg, Rect2(Point2(p_remaining, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
} else {
draw_style_box(fg, Rect2(Point2(0, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
}
}
} break;
case FILL_END_TO_BEGIN: {
int mp = fg->get_minimum_size().width;
int p = round(r * (get_size().width - mp));

if (p > 0) {
if (is_layout_rtl()) {
draw_style_box(fg, Rect2(Point2(0, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
} else {
int p_remaining = round((1.0 - r) * (get_size().width - mp));
draw_style_box(fg, Rect2(Point2(p_remaining, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
}
}
} break;
Copy link
Member

@akien-mga akien-mga May 10, 2022

Choose a reason for hiding this comment

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

Could maybe be simplified like this (untested):

Suggested change
case FILL_BEGIN_TO_END: {
int mp = fg->get_minimum_size().width;
int p = round(r * (get_size().width - mp));
if (p > 0) {
if (is_layout_rtl()) {
int p_remaining = round((1.0 - r) * (get_size().width - mp));
draw_style_box(fg, Rect2(Point2(p_remaining, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
} else {
draw_style_box(fg, Rect2(Point2(0, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
}
}
} break;
case FILL_END_TO_BEGIN: {
int mp = fg->get_minimum_size().width;
int p = round(r * (get_size().width - mp));
if (p > 0) {
if (is_layout_rtl()) {
draw_style_box(fg, Rect2(Point2(0, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
} else {
int p_remaining = round((1.0 - r) * (get_size().width - mp));
draw_style_box(fg, Rect2(Point2(p_remaining, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
}
}
} break;
case FILL_BEGIN_TO_END:
case FILL_END_TO_BEGIN: {
int mp = fg->get_minimum_size().width;
int p = round(r * (get_size().width - mp));
// We want FILL_BEGIN_TO_END to map to right to left when UI layout is RTL,
// and left to right otherwise. And likewise for FILL_END_TO_BEGIN.
bool right_to_left = is_layout_rtl() ? (mode == FILL_BEGIN_TO_END) : (mode == FILL_END_TO_BEGIN);
if (p > 0) {
if (right_to_left) {
int p_remaining = round((1.0 - r) * (get_size().width - mp));
draw_style_box(fg, Rect2(Point2(p_remaining, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
} else {
draw_style_box(fg, Rect2(Point2(0, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
}
}
} break;

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Looks good to me. Left a suggestion to reduce code duplication but it's also fine as is.
Would be good to get review from @bruvzg who's more familiar than me with UI mirroring requirements.

<member name="percent_visible" type="bool" setter="set_percent_visible" getter="is_percent_visible" default="true">
If [code]true[/code], the fill percentage is displayed on the bar.
</member>
</members>
<constants>
<constant name="FILL_BEGIN_TO_END" value="0" enum="FillMode">
The progress fills from begin to end horizontally.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could precise what being and end means? Or at least mention it's dependent on the language direction? Something like:

The progress bar fills from begin to end horizontally, according to the language direction.

Copy link
Member

@akien-mga akien-mga May 10, 2022

Choose a reason for hiding this comment

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

Maybe:

The progress bar fills from begin to end horizontally, according to the layout direction. If [method Control.is_layout_rtl] is [code]false[/code], it fills from left to right, and if it is [code]true[/code], it fills from right to left.

Copy link
Member

@kleonc kleonc May 10, 2022

Choose a reason for hiding this comment

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

Is "<method> is <return value>" correct though? I think it should be "<method> returns <return value>".
(yeah, nitpicking)

The progress bar fills from begin to end horizontally, according to the layout direction. If [method Control.is_layout_rtl] returns [code]false[/code], it fills from left to right, and if it returns [code]true[/code], it fills from right to left.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that's better. I thought initially that it's a property but it's indeed a method.

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

Seems fine. But I guess it should be documented what's begin-to-end means for different layout directions.

@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch 2 times, most recently from 2944c7b to e4b6fbf Compare May 10, 2022 10:09
@akien-mga akien-mga dismissed stale reviews from EricEzaM and groud May 10, 2022 10:18

Changes done.

@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch from e4b6fbf to 0c506cd Compare May 10, 2022 11:17
@floppyhammer floppyhammer force-pushed the AddFillModeToProgressBar branch from 0c506cd to f76d417 Compare May 10, 2022 11:35
@akien-mga akien-mga merged commit aee88a7 into godotengine:master May 10, 2022
@akien-mga
Copy link
Member

Thanks!

@floppyhammer floppyhammer deleted the AddFillModeToProgressBar branch May 11, 2022 01:46
@MaaaxiKing
Copy link

What was the problem with just rotating the whole Node?

@kleonc
Copy link
Member

kleonc commented May 12, 2022

What was the problem with just rotating the whole Node?

You mean why different modes instead of just rotating the Node? Rotating the Node will rotate all of its contents, including percent text or children of that Node. And this might be not wanted.

@KoBeWi
Copy link
Member

KoBeWi commented May 12, 2022

Also rotating won't work in a container.

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.

Add a vertical fill mode to ProgressBar
9 participants