-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
…ck request (line 250)
egui/src/widgets/button.rs
Outdated
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? |
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.
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.
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'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?
egui/src/widgets/button.rs
Outdated
@@ -242,26 +242,34 @@ impl<'a> Widget for Checkbox<'a> { | |||
let total_extra = button_padding + vec2(icon_width + icon_spacing, 0.0) + button_padding; |
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.
icon_spacing
should only be applied if there is text
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 tried to implement this, but I'm unsure about the second button padding.
As far as I can tell, this is fine.
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've implemented your feedback, but have some more questions.
Questions are responses to your feedback.
Any update on this? |
egui/src/widgets/button.rs
Outdated
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; |
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.
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.
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.
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.
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.