git_ui: Update git panel commit editor, start on quick commit
- Fixes commit editor issues & updates style - Starts on quick commit (not hooked up to anything) - Updates some panel styles - Adds SwitchWithLabel - Release Notes: - N/A
This commit is contained in:
parent
69d415c8d0
commit
de8d4d00ce
10 changed files with 586 additions and 120 deletions
|
@ -95,7 +95,7 @@ pub struct Button {
|
|||
selected_icon: Option<IconName>,
|
||||
selected_icon_color: Option<Color>,
|
||||
key_binding: Option<KeyBinding>,
|
||||
keybinding_position: KeybindingPosition,
|
||||
key_binding_position: KeybindingPosition,
|
||||
alpha: Option<f32>,
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ impl Button {
|
|||
selected_icon: None,
|
||||
selected_icon_color: None,
|
||||
key_binding: None,
|
||||
keybinding_position: KeybindingPosition::default(),
|
||||
key_binding_position: KeybindingPosition::default(),
|
||||
alpha: None,
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ impl Button {
|
|||
/// 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.key_binding_position = position;
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ impl RenderOnce for Button {
|
|||
.child(
|
||||
h_flex()
|
||||
.when(
|
||||
self.keybinding_position == KeybindingPosition::Start,
|
||||
self.key_binding_position == KeybindingPosition::Start,
|
||||
|this| this.flex_row_reverse(),
|
||||
)
|
||||
.gap(DynamicSpacing::Base06.rems(cx))
|
||||
|
|
|
@ -506,7 +506,9 @@ impl RenderOnce for ButtonLike {
|
|||
.group("")
|
||||
.flex_none()
|
||||
.h(self.height.unwrap_or(self.size.rems().into()))
|
||||
.when_some(self.width, |this, width| this.w(width).justify_center())
|
||||
.when_some(self.width, |this, width| {
|
||||
this.w(width).justify_center().text_center()
|
||||
})
|
||||
.when_some(self.rounding, |this, rounding| match rounding {
|
||||
ButtonLikeRounding::All => this.rounded_md(),
|
||||
ButtonLikeRounding::Left => this.rounded_l_md(),
|
||||
|
|
|
@ -22,6 +22,7 @@ pub struct IconButton {
|
|||
icon_size: IconSize,
|
||||
icon_color: Color,
|
||||
selected_icon: Option<IconName>,
|
||||
selected_icon_color: Option<Color>,
|
||||
indicator: Option<Indicator>,
|
||||
indicator_border_color: Option<Hsla>,
|
||||
alpha: Option<f32>,
|
||||
|
@ -36,6 +37,7 @@ impl IconButton {
|
|||
icon_size: IconSize::default(),
|
||||
icon_color: Color::Default,
|
||||
selected_icon: None,
|
||||
selected_icon_color: None,
|
||||
indicator: None,
|
||||
indicator_border_color: None,
|
||||
alpha: None,
|
||||
|
@ -69,6 +71,12 @@ impl IconButton {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the icon color used when the button is in a selected state.
|
||||
pub fn selected_icon_color(mut self, color: impl Into<Option<Color>>) -> Self {
|
||||
self.selected_icon_color = color.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn indicator(mut self, indicator: Indicator) -> Self {
|
||||
self.indicator = Some(indicator);
|
||||
self
|
||||
|
@ -181,6 +189,7 @@ impl RenderOnce for IconButton {
|
|||
.disabled(is_disabled)
|
||||
.toggle_state(is_selected)
|
||||
.selected_icon(self.selected_icon)
|
||||
.selected_icon_color(self.selected_icon_color)
|
||||
.when_some(selected_style, |this, style| this.selected_style(style))
|
||||
.when_some(self.indicator, |this, indicator| {
|
||||
this.indicator(indicator)
|
||||
|
|
|
@ -450,6 +450,64 @@ impl RenderOnce for Switch {
|
|||
}
|
||||
}
|
||||
|
||||
/// A [`Switch`] that has a [`Label`].
|
||||
#[derive(IntoElement)]
|
||||
// #[component(scope = "input")]
|
||||
pub struct SwitchWithLabel {
|
||||
id: ElementId,
|
||||
label: Label,
|
||||
toggle_state: ToggleState,
|
||||
on_click: Arc<dyn Fn(&ToggleState, &mut Window, &mut App) + 'static>,
|
||||
disabled: bool,
|
||||
}
|
||||
|
||||
impl SwitchWithLabel {
|
||||
/// Creates a switch with an attached label.
|
||||
pub fn new(
|
||||
id: impl Into<ElementId>,
|
||||
label: Label,
|
||||
toggle_state: impl Into<ToggleState>,
|
||||
on_click: impl Fn(&ToggleState, &mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
label,
|
||||
toggle_state: toggle_state.into(),
|
||||
on_click: Arc::new(on_click),
|
||||
disabled: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the disabled state of the [`SwitchWithLabel`].
|
||||
pub fn disabled(mut self, disabled: bool) -> Self {
|
||||
self.disabled = disabled;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for SwitchWithLabel {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
h_flex()
|
||||
.id(SharedString::from(format!("{}-container", self.id)))
|
||||
.gap(DynamicSpacing::Base08.rems(cx))
|
||||
.child(
|
||||
Switch::new(self.id.clone(), self.toggle_state)
|
||||
.disabled(self.disabled)
|
||||
.on_click({
|
||||
let on_click = self.on_click.clone();
|
||||
move |checked, window, cx| {
|
||||
(on_click)(checked, window, cx);
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.id(SharedString::from(format!("{}-label", self.id)))
|
||||
.child(self.label),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ComponentPreview for Checkbox {
|
||||
fn preview(_window: &mut Window, _cx: &App) -> AnyElement {
|
||||
v_flex()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue