Add `Label::halign` (#4975)
Function to specify `Align` to `Label` There are cases where you want to display `Label` on the left or right regardless of other `Layout` specifications. Before : Note the part showing the rust source code.  After : Note the part showing the rust source code.  --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
parent
5a1ab9b2b8
commit
47c0aeb7b9
|
|
@ -26,6 +26,7 @@ pub struct Label {
|
||||||
wrap_mode: Option<TextWrapMode>,
|
wrap_mode: Option<TextWrapMode>,
|
||||||
sense: Option<Sense>,
|
sense: Option<Sense>,
|
||||||
selectable: Option<bool>,
|
selectable: Option<bool>,
|
||||||
|
halign: Option<Align>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Label {
|
impl Label {
|
||||||
|
|
@ -35,6 +36,7 @@ impl Label {
|
||||||
wrap_mode: None,
|
wrap_mode: None,
|
||||||
sense: None,
|
sense: None,
|
||||||
selectable: None,
|
selectable: None,
|
||||||
|
halign: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,6 +78,13 @@ impl Label {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the horizontal alignment of the Label to the given `Align` value.
|
||||||
|
#[inline]
|
||||||
|
pub fn halign(mut self, align: Align) -> Self {
|
||||||
|
self.halign = Some(align);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Can the user select the text with the mouse?
|
/// Can the user select the text with the mouse?
|
||||||
///
|
///
|
||||||
/// Overrides [`crate::style::Interaction::selectable_labels`].
|
/// Overrides [`crate::style::Interaction::selectable_labels`].
|
||||||
|
|
@ -211,7 +220,7 @@ impl Label {
|
||||||
layout_job.halign = Align::LEFT;
|
layout_job.halign = Align::LEFT;
|
||||||
layout_job.justify = false;
|
layout_job.justify = false;
|
||||||
} else {
|
} else {
|
||||||
layout_job.halign = ui.layout().horizontal_placement();
|
layout_job.halign = self.halign.unwrap_or(ui.layout().horizontal_placement());
|
||||||
layout_job.justify = ui.layout().horizontal_justify();
|
layout_job.justify = ui.layout().horizontal_justify();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue