Introduce KeybindingHint (#24397)

- Implements scaling for `ui::Keybinding` and it's component parts
- Adds the `ui::KeybindingHint` component for creating keybinding hints
easily:

![CleanShot 2025-02-04 at 16 59
38@2x](https://github.com/user-attachments/assets/d781e401-8875-4edc-a4b0-5f8750777d86)

Release Notes:

- N/A
This commit is contained in:
Nate Butler 2025-02-06 16:45:03 -05:00 committed by GitHub
parent 9c132fece5
commit 00971fbe41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 390 additions and 16 deletions

View file

@ -2,7 +2,8 @@
use gpui::{AnyView, DefiniteLength};
use crate::{
prelude::*, Color, DynamicSpacing, ElevationIndex, IconPosition, KeyBinding, TintColor,
prelude::*, Color, DynamicSpacing, ElevationIndex, IconPosition, KeyBinding,
KeybindingPosition, TintColor,
};
use crate::{
ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, IconName, IconSize, Label, LineHeightStyle,
@ -92,6 +93,7 @@ pub struct Button {
selected_icon: Option<IconName>,
selected_icon_color: Option<Color>,
key_binding: Option<KeyBinding>,
keybinding_position: KeybindingPosition,
alpha: Option<f32>,
}
@ -117,6 +119,7 @@ impl Button {
selected_icon: None,
selected_icon_color: None,
key_binding: None,
keybinding_position: KeybindingPosition::default(),
alpha: None,
}
}
@ -187,6 +190,15 @@ impl Button {
self
}
/// Sets the position of the keybinding relative to the button label.
///
/// This method allows you to specify where the keybinding should be displayed
/// in relation to the button's label.
pub fn key_binding_position(mut self, position: KeybindingPosition) -> Self {
self.keybinding_position = position;
self
}
/// Sets the alpha property of the color of label.
pub fn alpha(mut self, alpha: f32) -> Self {
self.alpha = Some(alpha);
@ -412,6 +424,10 @@ impl RenderOnce for Button {
})
.child(
h_flex()
.when(
self.keybinding_position == KeybindingPosition::Start,
|this| this.flex_row_reverse(),
)
.gap(DynamicSpacing::Base06.rems(cx))
.justify_between()
.child(