remove Label::auto_shrink and replace with ui.shrink_width_to_current()
This commit is contained in:
parent
1069ad8496
commit
814121903a
3 changed files with 19 additions and 17 deletions
|
@ -600,9 +600,9 @@ impl Context {
|
|||
}
|
||||
});
|
||||
|
||||
ui.shrink_width_to_current(); // don't let the text below grow this window wider
|
||||
ui.add(
|
||||
label!("NOTE: the position of this window cannot be reset from within itself.")
|
||||
.auto_shrink(),
|
||||
label!("NOTE: the position of this window cannot be reset from within itself."), // .auto_shrink(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,6 +209,19 @@ impl Ui {
|
|||
self.desired_rect.max.y = self.top_left().y + height;
|
||||
}
|
||||
|
||||
/// Helper: shrinks the max/desired width to the current width,
|
||||
/// so further widgets will try not to be wider than previous widgets.
|
||||
/// Useful for normal vertical layouts.
|
||||
pub fn shrink_width_to_current(&mut self) {
|
||||
self.set_desired_width(self.child_bounds().width())
|
||||
}
|
||||
|
||||
/// Helper: shrinks the max/desired height to the current height,
|
||||
/// so further widgets will try not to be wider than previous widgets.
|
||||
pub fn shrink_height_to_current(&mut self) {
|
||||
self.set_desired_height(self.child_bounds().height())
|
||||
}
|
||||
|
||||
/// Size of content
|
||||
pub fn bounding_size(&self) -> Vec2 {
|
||||
self.child_bounds.size()
|
||||
|
|
|
@ -33,7 +33,6 @@ pub struct Label {
|
|||
// TODO: not pub
|
||||
pub(crate) text: String,
|
||||
pub(crate) multiline: bool,
|
||||
auto_shrink: bool,
|
||||
pub(crate) text_style: Option<TextStyle>,
|
||||
pub(crate) text_color: Option<Srgba>,
|
||||
}
|
||||
|
@ -43,7 +42,6 @@ impl Label {
|
|||
Self {
|
||||
text: text.into(),
|
||||
multiline: true,
|
||||
auto_shrink: false,
|
||||
text_style: None,
|
||||
text_color: None,
|
||||
}
|
||||
|
@ -58,14 +56,6 @@ impl Label {
|
|||
self
|
||||
}
|
||||
|
||||
/// If true, will word wrap to `ui.available_finite().width()`.
|
||||
/// If false (default), will word wrap to `ui.available().width()`.
|
||||
/// This only makes a difference for auto-sized parents.
|
||||
pub fn auto_shrink(mut self) -> Self {
|
||||
self.auto_shrink = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// If you do not set a `TextStyle`, the default `style.text_style`.
|
||||
pub fn text_style(mut self, text_style: TextStyle) -> Self {
|
||||
self.text_style = Some(text_style);
|
||||
|
@ -82,11 +72,10 @@ impl Label {
|
|||
}
|
||||
|
||||
pub fn layout(&self, ui: &Ui) -> font::Galley {
|
||||
let max_width = if self.auto_shrink {
|
||||
ui.available_finite().width()
|
||||
} else {
|
||||
ui.available().width()
|
||||
};
|
||||
let max_width = ui.available().width();
|
||||
// Prevent word-wrapping after a single letter, and other silly shit:
|
||||
// TODO: general "don't force labels and similar to wrap so early"
|
||||
// TODO: max_width = max_width.at_least(ui.spacing.first_wrap_width);
|
||||
self.layout_width(ui, max_width)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue