git_ui: Prevent button overflow due to long names (#25940)
- Fix component preview widths for git panel - Fix buttons getting pushed off the screen in git panel Release Notes: - N/A --------- Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
b2add8c803
commit
16ab8701a2
13 changed files with 283 additions and 148 deletions
|
@ -97,6 +97,7 @@ pub struct Button {
|
|||
key_binding: Option<KeyBinding>,
|
||||
key_binding_position: KeybindingPosition,
|
||||
alpha: Option<f32>,
|
||||
truncate: bool,
|
||||
}
|
||||
|
||||
impl Button {
|
||||
|
@ -123,6 +124,7 @@ impl Button {
|
|||
key_binding: None,
|
||||
key_binding_position: KeybindingPosition::default(),
|
||||
alpha: None,
|
||||
truncate: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,6 +208,15 @@ impl Button {
|
|||
self.alpha = Some(alpha);
|
||||
self
|
||||
}
|
||||
|
||||
/// Truncates overflowing labels with an ellipsis (`…`) if needed.
|
||||
///
|
||||
/// Buttons with static labels should _never_ be truncated, ensure
|
||||
/// this is only used when the label is dynamic and may overflow.
|
||||
pub fn truncate(mut self, truncate: bool) -> Self {
|
||||
self.truncate = truncate;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Toggleable for Button {
|
||||
|
@ -437,7 +448,8 @@ impl RenderOnce for Button {
|
|||
.color(label_color)
|
||||
.size(self.label_size.unwrap_or_default())
|
||||
.when_some(self.alpha, |this, alpha| this.alpha(alpha))
|
||||
.line_height_style(LineHeightStyle::UiLabel),
|
||||
.line_height_style(LineHeightStyle::UiLabel)
|
||||
.when(self.truncate, |this| this.truncate()),
|
||||
)
|
||||
.children(self.key_binding),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue