Correctly align checkboxes and radiobuttons within justified layouts

This commit is contained in:
Emil Ernerfeldt 2020-12-09 01:02:33 +01:00
parent 807dafe91b
commit 9b72a14883
3 changed files with 16 additions and 9 deletions

View file

@ -5,7 +5,7 @@ TODO-list for the Egui project. If you looking for something to do, look here.
## Layout refactor
* Test `allocate_ui`
* Justified alignment of radio button and checkboxes
* Text wrapping
## Misc

View file

@ -389,16 +389,20 @@ impl LayoutDemo {
}
});
ui.checkbox(&mut self.main_wrap, "Main wrap")
.on_hover_text("Wrap when next widget doesn't fit the current row/column");
ui.horizontal(|ui| {
ui.checkbox(&mut self.main_wrap, "Main wrap")
.on_hover_text("Wrap when next widget doesn't fit the current row/column");
if self.main_wrap {
if self.main_dir.is_horizontal() {
ui.add(Slider::f32(&mut self.wrap_row_height, 0.0..=200.0).text("Row height"));
} else {
ui.add(Slider::f32(&mut self.wrap_column_width, 0.0..=200.0).text("Column width"));
if self.main_wrap {
if self.main_dir.is_horizontal() {
ui.add(Slider::f32(&mut self.wrap_row_height, 0.0..=200.0).text("Row height"));
} else {
ui.add(
Slider::f32(&mut self.wrap_column_width, 0.0..=200.0).text("Column width"),
);
}
}
}
});
ui.horizontal(|ui| {
ui.label("Cross Align:");

View file

@ -385,6 +385,7 @@ impl<'a> Widget for Checkbox<'a> {
desired_size = desired_size.at_least(spacing.interact_size);
desired_size.y = desired_size.y.max(icon_width);
let rect = ui.allocate_space(desired_size);
let rect = ui.layout().align_size_within_rect(desired_size, rect);
let id = ui.make_position_id();
let response = ui.interact(rect, id, Sense::click());
@ -473,6 +474,8 @@ impl Widget for RadioButton {
desired_size = desired_size.at_least(ui.style().spacing.interact_size);
desired_size.y = desired_size.y.max(icon_width);
let rect = ui.allocate_space(desired_size);
let rect = ui.layout().align_size_within_rect(desired_size, rect);
let id = ui.make_position_id();
let response = ui.interact(rect, id, Sense::click());