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(
|
ui.add(
|
||||||
label!("NOTE: the position of this window cannot be reset from within itself.")
|
label!("NOTE: the position of this window cannot be reset from within itself."), // .auto_shrink(),
|
||||||
.auto_shrink(),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,6 +209,19 @@ impl Ui {
|
||||||
self.desired_rect.max.y = self.top_left().y + height;
|
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
|
/// Size of content
|
||||||
pub fn bounding_size(&self) -> Vec2 {
|
pub fn bounding_size(&self) -> Vec2 {
|
||||||
self.child_bounds.size()
|
self.child_bounds.size()
|
||||||
|
|
|
@ -33,7 +33,6 @@ pub struct Label {
|
||||||
// TODO: not pub
|
// TODO: not pub
|
||||||
pub(crate) text: String,
|
pub(crate) text: String,
|
||||||
pub(crate) multiline: bool,
|
pub(crate) multiline: bool,
|
||||||
auto_shrink: bool,
|
|
||||||
pub(crate) text_style: Option<TextStyle>,
|
pub(crate) text_style: Option<TextStyle>,
|
||||||
pub(crate) text_color: Option<Srgba>,
|
pub(crate) text_color: Option<Srgba>,
|
||||||
}
|
}
|
||||||
|
@ -43,7 +42,6 @@ impl Label {
|
||||||
Self {
|
Self {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
multiline: true,
|
multiline: true,
|
||||||
auto_shrink: false,
|
|
||||||
text_style: None,
|
text_style: None,
|
||||||
text_color: None,
|
text_color: None,
|
||||||
}
|
}
|
||||||
|
@ -58,14 +56,6 @@ impl Label {
|
||||||
self
|
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`.
|
/// If you do not set a `TextStyle`, the default `style.text_style`.
|
||||||
pub fn text_style(mut self, text_style: TextStyle) -> Self {
|
pub fn text_style(mut self, text_style: TextStyle) -> Self {
|
||||||
self.text_style = Some(text_style);
|
self.text_style = Some(text_style);
|
||||||
|
@ -82,11 +72,10 @@ impl Label {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layout(&self, ui: &Ui) -> font::Galley {
|
pub fn layout(&self, ui: &Ui) -> font::Galley {
|
||||||
let max_width = if self.auto_shrink {
|
let max_width = ui.available().width();
|
||||||
ui.available_finite().width()
|
// Prevent word-wrapping after a single letter, and other silly shit:
|
||||||
} else {
|
// TODO: general "don't force labels and similar to wrap so early"
|
||||||
ui.available().width()
|
// TODO: max_width = max_width.at_least(ui.spacing.first_wrap_width);
|
||||||
};
|
|
||||||
self.layout_width(ui, max_width)
|
self.layout_width(ui, max_width)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue