number_input: Fix button margin. (#634)

This commit is contained in:
Jason Lee 2025-02-17 14:29:33 +08:00 committed by GitHub
parent 231772ee4e
commit d96b4b44d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,7 @@
use gpui::{ use gpui::{
actions, prelude::FluentBuilder as _, px, App, AppContext as _, Context, Entity, EventEmitter, actions, prelude::FluentBuilder as _, px, App, AppContext as _, Context, Entity, EventEmitter,
FocusHandle, Focusable, InteractiveElement, IntoElement, KeyBinding, ParentElement, Pixels, FocusHandle, Focusable, InteractiveElement, IntoElement, KeyBinding, ParentElement, Render,
Render, SharedString, Styled, Subscription, Window, SharedString, Styled, Subscription, Window,
}; };
use regex::Regex; use regex::Regex;
@ -162,7 +162,6 @@ impl Render for NumberInput {
// Sync size to input at first. // Sync size to input at first.
self.sync_size_to_input_if_needed(window, cx); self.sync_size_to_input_if_needed(window, cx);
const BUTTON_OFFSET: Pixels = px(-3.);
let btn_size = match self.size { let btn_size = match self.size {
Size::XSmall | Size::Small => Size::XSmall, Size::XSmall | Size::Small => Size::XSmall,
_ => Size::Small, _ => Size::Small,
@ -174,6 +173,11 @@ impl Render for NumberInput {
.on_action(cx.listener(Self::on_action_decrement)) .on_action(cx.listener(Self::on_action_decrement))
.flex_1() .flex_1()
.input_size(self.size) .input_size(self.size)
.px(match self.size {
Size::XSmall => px(1.),
Size::Small => px(2.),
_ => px(3.),
})
.bg(cx.theme().background) .bg(cx.theme().background)
.border_color(cx.theme().input) .border_color(cx.theme().input)
.border_1() .border_1()
@ -183,7 +187,6 @@ impl Render for NumberInput {
Button::new("minus") Button::new("minus")
.ghost() .ghost()
.with_size(btn_size) .with_size(btn_size)
.ml(BUTTON_OFFSET)
.icon(IconName::Minus) .icon(IconName::Minus)
.on_click(cx.listener(|this, _, window, cx| { .on_click(cx.listener(|this, _, window, cx| {
this.on_step(StepAction::Decrement, window, cx) this.on_step(StepAction::Decrement, window, cx)
@ -194,7 +197,6 @@ impl Render for NumberInput {
Button::new("plus") Button::new("plus")
.ghost() .ghost()
.with_size(btn_size) .with_size(btn_size)
.mr(BUTTON_OFFSET)
.icon(IconName::Plus) .icon(IconName::Plus)
.on_click(cx.listener(|this, _, window, cx| { .on_click(cx.listener(|this, _, window, cx| {
this.on_step(StepAction::Increment, window, cx) this.on_step(StepAction::Increment, window, cx)