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

Fix Spinbox display does not round properly when using decimal custom arrow steps #97573

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

shahriarlabib000
Copy link
Contributor

@shahriarlabib000 shahriarlabib000 commented Sep 28, 2024

Fixes #97561

@shahriarlabib000 shahriarlabib000 requested a review from a team as a code owner September 28, 2024 06:08
@AThousandShips AThousandShips added bug topic:gui cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Sep 28, 2024
@AThousandShips AThousandShips added this to the 4.4 milestone Sep 28, 2024
@shahriarlabib000 shahriarlabib000 marked this pull request as draft September 28, 2024 09:01
@shahriarlabib000 shahriarlabib000 marked this pull request as ready for review September 28, 2024 12:50
@shahriarlabib000

This comment was marked as outdated.

@shahriarlabib000 shahriarlabib000 marked this pull request as ready for review November 7, 2024 13:04
@shahriarlabib000
Copy link
Contributor Author

I think it's fixed now?

scene/gui/spin_box.cpp Outdated Show resolved Hide resolved
bool original_do_round = is_using_rounded_values();
double step = get_step();
double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
_rounded_values = false;
Copy link
Member

Choose a reason for hiding this comment

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

Why this? rounded should always make the value rounded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sorry, now that you mention it, I think it should be removed too. It's been awhile but I think the reasoning was the value was not updating if the arrow_step was too low. But I guess that logic is flawed. I'll remove it

Copy link
Contributor Author

@shahriarlabib000 shahriarlabib000 Nov 8, 2024

Choose a reason for hiding this comment

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

Oh ok, so if i set the step to 0.8 the value cannot get beyond 2.
Maybe the rounding logic is flawed somehow? Or is that not how I'm supposed to use it?

Copy link
Member

Choose a reason for hiding this comment

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

It's a pre-existing bug, so it can be fixed later.
Not sure what's the expected behavior here, maybe rounded could force the arrow step to be at least 1.
Then again, when both steps are 0, the arrows don't work either.

@shahriarlabib000
Copy link
Contributor Author

shahriarlabib000 commented Nov 8, 2024

I don't like how it partially duplicates set_value(), but if it works better then ok.

Maybe we could give set value () an optional custom_step parameter or maybe that's a bad idea

@shahriarlabib000
Copy link
Contributor Author

What about the exp_edit ?

@KoBeWi
Copy link
Member

KoBeWi commented Nov 8, 2024

exp_edit is irrelevant for SpinBox.

@shahriarlabib000
Copy link
Contributor Author

Is it possible to hide it from the inspector somehow?

@KoBeWi
Copy link
Member

KoBeWi commented Nov 8, 2024

Yes, by using _validate_property().

@shahriarlabib000
Copy link
Contributor Author

shahriarlabib000 commented Nov 8, 2024

Okay maybe for another pr if I can figure out how to use it 😅

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.

Works fine now.
You could maybe add some comments for the new code, on why is it like that.

scene/gui/spin_box.cpp Outdated Show resolved Hide resolved
@shahriarlabib000
Copy link
Contributor Author

shahriarlabib000 commented Nov 9, 2024

@KoBeWi
So if the step is 0, and the value is being typed, it seems that the displayed value's precision is affected.
What if we do something like this?
shahriarlabib000/godot@spinBox...shahriarlabib000:godot:spinThyBox

void SpinBox::_update_text(bool p_keep_line_edit) {
	String value = String::num(get_value(), Math::range_step_decimals(get_step()));
	double value_for_calculating_precision = get_value();
	int decimal = 0;
	while((int)value_for_calculating_precision != value_for_calculating_precision) {
		value_for_calculating_precision *= 10;
		++decimal;
		if(decimal >= 10) {
			break;
		}
	}

	String value = String::num(get_value(), decimal);

@KoBeWi
Copy link
Member

KoBeWi commented Nov 9, 2024

I think that's a separate issue.

@akien-mga akien-mga changed the title Fix Spinbox display does not round properly when using decimal custom… Fix Spinbox display does not round properly when using decimal custom arrow steps Nov 11, 2024
@Repiteo Repiteo merged commit 658b5d4 into godotengine:master Nov 12, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 12, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release topic:gui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spinbox display does not round properly when using decimal custom arrow steps
4 participants