input: Implement styled for number input (#1333)

This commit is contained in:
Floyd Wang 2025-10-08 10:36:28 +08:00 committed by GitHub
parent c579db975f
commit c3954b0455
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,7 @@
use gpui::{
actions, prelude::FluentBuilder as _, px, AnyElement, App, Context, Entity, EventEmitter,
FocusHandle, Focusable, InteractiveElement, IntoElement, KeyBinding, ParentElement, RenderOnce,
SharedString, Styled, Window,
SharedString, StyleRefinement, Styled, Window,
};
use crate::{
@ -31,6 +31,7 @@ pub struct NumberInput {
suffix: Option<AnyElement>,
appearance: bool,
disabled: bool,
style: StyleRefinement,
}
impl NumberInput {
@ -44,6 +45,7 @@ impl NumberInput {
suffix: None,
appearance: true,
disabled: false,
style: StyleRefinement::default(),
}
}
@ -133,6 +135,13 @@ impl Sizable for NumberInput {
self
}
}
impl Styled for NumberInput {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for NumberInput {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let focused = self.state.focus_handle(cx).is_focused(window);
@ -150,6 +159,7 @@ impl RenderOnce for NumberInput {
.border_color(cx.theme().input)
.border_1()
.rounded(cx.theme().radius)
.refine_style(&self.style)
})
.when(self.disabled, |this| this.bg(cx.theme().muted))
.when(focused, |this| this.focused_border(cx))