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

checkbox without a text label #1113

Closed
wants to merge 3 commits into from
Closed

Conversation

voelklmichael
Copy link
Contributor

This fixes the empty-space layout for a checkbox with empty label.
Note that the radio-button is NOT done, since I'm unsure about line 250:
What is the meaning of 'spacing.interact_size'?
If my adjustment is ok, I will be happy to do the same for radiobutton.

Closes #1047.

let text = if !text.text().is_empty() {
let text = text.into_galley(ui, None, wrap_width, TextStyle::Button);
desired_size += text.size();
desired_size = desired_size.at_least(spacing.interact_size); //Here I'm unsure - what is interacting size?
Copy link
Owner

Choose a reason for hiding this comment

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

From the docs:

Minimum size of a DragValue, color picker button, and other small widgets. interact_size.y is the default height of button, slider, etc. Anything clickable should be (at least) this size.

The original idea was that it is bad to have very small buttons, because they are difficult to click (especially on touch screens), but in this case you presumably want a small button.

desired_size = desired_size.at_least(Vec2::splat(spacing.interact_size.y)); could be a good workaround, and should be applied whether or not there is text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the original 'at_least' instruction, and replaced it with your suggestion. Is this what you had in your mind?
Or an if/else - if text is empty, then your suggestion, else original code?

@@ -242,26 +242,34 @@ impl<'a> Widget for Checkbox<'a> {
let total_extra = button_padding + vec2(icon_width + icon_spacing, 0.0) + button_padding;
Copy link
Owner

Choose a reason for hiding this comment

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

icon_spacing should only be applied if there is text

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to implement this, but I'm unsure about the second button padding.
As far as I can tell, this is fine.

Copy link
Contributor Author

@voelklmichael voelklmichael left a comment

Choose a reason for hiding this comment

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

I've implemented your feedback, but have some more questions.
Questions are responses to your feedback.

@HactarCE
Copy link
Contributor

HactarCE commented Mar 9, 2022

Any update on this?

let mut total_extra = button_padding;
if !text.is_empty() {
total_extra += vec2(icon_width + icon_spacing, 0.0) + button_padding;
}

let wrap_width = ui.available_width() - total_extra.x;
Copy link
Owner

Choose a reason for hiding this comment

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

You only need to calculate wrap_width if there is text to wrap, so you only need to calculate total_extra if there is text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, thank you for the feedback - I still would like to see this merged.
So, I have tried to implement it.
If this is OK, I would copy it to radio-button.

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

Successfully merging this pull request may close these issues.

Checkbox without label
3 participants