ui: Give NumericSteppers an ID (#15344)

This PR gives the `NumericStepper` component an ID.

This prevents the UI and buffer font size settings controls from having
their increment/decrement buttons visually change when the other one is
pressed.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-27 13:02:27 -04:00 committed by GitHub
parent c7a78fafac
commit f1d777434b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 0 deletions

View file

@ -140,6 +140,7 @@ impl RenderOnce for BufferFontSizeControl {
.gap_2() .gap_2()
.child(Icon::new(IconName::FontSize)) .child(Icon::new(IconName::FontSize))
.child(NumericStepper::new( .child(NumericStepper::new(
"buffer-font-size",
value.to_string(), value.to_string(),
move |_, cx| { move |_, cx| {
Self::write(value - px(1.), cx); Self::write(value - px(1.), cx);

View file

@ -260,6 +260,7 @@ impl RenderOnce for UiFontSizeControl {
.gap_2() .gap_2()
.child(Icon::new(IconName::FontSize)) .child(Icon::new(IconName::FontSize))
.child(NumericStepper::new( .child(NumericStepper::new(
"ui-font-size",
value.to_string(), value.to_string(),
move |_, cx| { move |_, cx| {
Self::write(value - px(1.), cx); Self::write(value - px(1.), cx);

View file

@ -26,6 +26,7 @@ impl RenderOnce for ApplicationMenu {
.child(Label::new("Buffer Font Size")) .child(Label::new("Buffer Font Size"))
.child( .child(
NumericStepper::new( NumericStepper::new(
"buffer-font-size",
theme::get_buffer_font_size(cx).to_string(), theme::get_buffer_font_size(cx).to_string(),
|_, cx| { |_, cx| {
cx.dispatch_action(Box::new( cx.dispatch_action(Box::new(
@ -61,6 +62,7 @@ impl RenderOnce for ApplicationMenu {
.child(Label::new("UI Font Size")) .child(Label::new("UI Font Size"))
.child( .child(
NumericStepper::new( NumericStepper::new(
"ui-font-size",
theme::get_ui_font_size(cx).to_string(), theme::get_ui_font_size(cx).to_string(),
|_, cx| { |_, cx| {
cx.dispatch_action(Box::new( cx.dispatch_action(Box::new(

View file

@ -4,6 +4,7 @@ use crate::{prelude::*, IconButtonShape};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct NumericStepper { pub struct NumericStepper {
id: ElementId,
value: SharedString, value: SharedString,
on_decrement: Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>, on_decrement: Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>,
on_increment: Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>, on_increment: Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>,
@ -14,11 +15,13 @@ pub struct NumericStepper {
impl NumericStepper { impl NumericStepper {
pub fn new( pub fn new(
id: impl Into<ElementId>,
value: impl Into<SharedString>, value: impl Into<SharedString>,
on_decrement: impl Fn(&ClickEvent, &mut WindowContext) + 'static, on_decrement: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
on_increment: impl Fn(&ClickEvent, &mut WindowContext) + 'static, on_increment: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
) -> Self { ) -> Self {
Self { Self {
id: id.into(),
value: value.into(), value: value.into(),
on_decrement: Box::new(on_decrement), on_decrement: Box::new(on_decrement),
on_increment: Box::new(on_increment), on_increment: Box::new(on_increment),
@ -47,6 +50,7 @@ impl RenderOnce for NumericStepper {
let icon_size = IconSize::Small; let icon_size = IconSize::Small;
h_flex() h_flex()
.id(self.id)
.gap_1() .gap_1()
.map(|element| { .map(|element| {
if let Some(on_reset) = self.on_reset { if let Some(on_reset) = self.on_reset {