ui.horizontal_for_text: Size and spacing made for text
This commit is contained in:
parent
b15bd76596
commit
5880c95158
2 changed files with 27 additions and 5 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -15,11 +15,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
* Works in any text.
|
* Works in any text.
|
||||||
* Great for button icons.
|
* Great for button icons.
|
||||||
* The Demo app comes with a Font Book to explore the available glyphs.
|
* The Demo app comes with a Font Book to explore the available glyphs.
|
||||||
* Wrapping layouts:
|
* `ui.horizontal_wrapped(|ui| ...)`: Add widgets on a row but wrap at `max_size`.
|
||||||
* `ui.horizontal_wrapped(|ui| ...)`: Add widgets on a row but wrap at `max_size`.
|
* `ui.horizontal_wrapped_for_text`: Like `ui.horizontal_wrapped`, but with spacing made for embedding text.
|
||||||
* `ui.horizontal_wrapped_for_text`: Like `horizontal_wrapped`, but with spacing made for embedding text.
|
* `ui.horizontal_for_text`: Like `ui.horizontal`, but with spacing made for embedding text.
|
||||||
* `egui::Layout` now supports justified layouts where contents is _also_ centered, right-aligned, etc.
|
* `egui::Layout` now supports justified layouts where contents is _also_ centered, right-aligned, etc.
|
||||||
* `ui.allocate_ui(size, |ui| ...)`: Easily created a sized child-`Ui`.
|
* `ui.allocate_ui(size, |ui| ...)`: Easily created child-`Ui` of a given size.
|
||||||
* `SelectableLabel` (`ui.selectable_label` and `ui.selectable_value`): A text-button that can be selected.
|
* `SelectableLabel` (`ui.selectable_label` and `ui.selectable_value`): A text-button that can be selected.
|
||||||
* `ui.small_button`: A smaller button that looks good embedded in text.
|
* `ui.small_button`: A smaller button that looks good embedded in text.
|
||||||
* Add `Resize::id_source` and `ScrollArea::id_source` to let the user avoid Id clashes.
|
* Add `Resize::id_source` and `ScrollArea::id_source` to let the user avoid Id clashes.
|
||||||
|
@ -29,7 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
* Changed default font to [Ubuntu-Light](https://fonts.google.com/specimen/Ubuntu).
|
* Changed default font to [Ubuntu-Light](https://fonts.google.com/specimen/Ubuntu).
|
||||||
* Remove minimum button width
|
* Remove minimum button width
|
||||||
* Refactored `egui::Layout` substantially, changing its interface.
|
* Refactored `egui::Layout` substantially, changing its interface.
|
||||||
* Calling ``on_hover_text`/`on_hover_ui` multiple times will stack tooltips underneath the previous ones.
|
* Calling `on_hover_text`/`on_hover_ui` multiple times will stack tooltips underneath the previous ones.
|
||||||
* Text wrapping on labels, buttons, checkboxes and radio buttons is now based on the layout.
|
* Text wrapping on labels, buttons, checkboxes and radio buttons is now based on the layout.
|
||||||
|
|
||||||
### Removed 🔥
|
### Removed 🔥
|
||||||
|
|
|
@ -850,6 +850,28 @@ impl Ui {
|
||||||
self.horizontal_with_main_wrap(false, add_contents)
|
self.horizontal_with_main_wrap(false, add_contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Like `horizontal`, but will set up the spacing to match that of a normal label.
|
||||||
|
///
|
||||||
|
/// In particular, the space between widgets is the same width as the space character.
|
||||||
|
///
|
||||||
|
/// You can still add any widgets to the layout (not only Labels).
|
||||||
|
pub fn horizontal_for_text<R>(
|
||||||
|
&mut self,
|
||||||
|
text_style: TextStyle,
|
||||||
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
|
) -> (R, Response) {
|
||||||
|
self.wrap(|ui| {
|
||||||
|
let font = &ui.fonts()[text_style];
|
||||||
|
let row_height = font.row_height();
|
||||||
|
let space_width = font.glyph_width(' ');
|
||||||
|
let style = ui.style_mut();
|
||||||
|
style.spacing.interact_size.y = row_height;
|
||||||
|
style.spacing.item_spacing.x = space_width;
|
||||||
|
style.spacing.item_spacing.y = 0.0;
|
||||||
|
ui.horizontal(add_contents).0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Start a ui with horizontal layout that wraps to a new row
|
/// Start a ui with horizontal layout that wraps to a new row
|
||||||
/// when it reaches the right edge of the `max_size`.
|
/// when it reaches the right edge of the `max_size`.
|
||||||
/// After you have called this, the function registers the contents as any other widget.
|
/// After you have called this, the function registers the contents as any other widget.
|
||||||
|
|
Loading…
Reference in a new issue