From 244090ddc5a6d6490ecd70420b3a3ba940d51571 Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Thu, 22 May 2025 14:38:43 +0800 Subject: [PATCH] number_input: Remove `InputEvent` from `NumberInputEvent` (#884) ## Break Change - Number input no longer emits `InputEvent`; you need an additional subscription for `InputEvent`. --- crates/story/src/number_input_story.rs | 58 ++++++++++++++++---------- crates/ui/src/input/number_input.rs | 5 +-- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/crates/story/src/number_input_story.rs b/crates/story/src/number_input_story.rs index 0d34c2ac..a855c718 100644 --- a/crates/story/src/number_input_story.rs +++ b/crates/story/src/number_input_story.rs @@ -79,8 +79,11 @@ impl NumberInputStory { }); let _subscriptions = vec![ + cx.subscribe_in(&number_input1, window, Self::on_input_event), cx.subscribe_in(&number_input1, window, Self::on_number_input_event), + cx.subscribe_in(&number_input2, window, Self::on_input_event), cx.subscribe_in(&number_input2, window, Self::on_number_input_event), + cx.subscribe_in(&number_input3, window, Self::on_input_event), cx.subscribe_in(&number_input3, window, Self::on_number_input_event), ]; @@ -103,6 +106,38 @@ impl NumberInputStory { self.cycle_focus(false, window, cx); } + fn on_input_event( + &mut self, + this: &Entity, + event: &InputEvent, + _: &mut Window, + _: &mut Context, + ) { + match event { + InputEvent::Change(text) => { + if this == &self.number_input1 { + if let Ok(value) = text.parse::() { + self.number_input1_value = value; + } + } else if this == &self.number_input2 { + if let Ok(value) = text.parse::() { + self.number_input2_value = value; + } + } else if this == &self.number_input3 { + if let Ok(value) = text.parse::() { + self.number_input3_value = value; + } + } + println!("Change: {}", text); + } + InputEvent::PressEnter { secondary } => { + println!("PressEnter secondary: {}", secondary) + } + InputEvent::Focus => println!("Focus"), + InputEvent::Blur => println!("Blur"), + } + } + fn on_number_input_event( &mut self, this: &Entity, @@ -111,29 +146,6 @@ impl NumberInputStory { cx: &mut Context, ) { match event { - NumberInputEvent::Input(input_event) => match input_event { - InputEvent::Change(text) => { - if this == &self.number_input1 { - if let Ok(value) = text.parse::() { - self.number_input1_value = value; - } - } else if this == &self.number_input2 { - if let Ok(value) = text.parse::() { - self.number_input2_value = value; - } - } else if this == &self.number_input3 { - if let Ok(value) = text.parse::() { - self.number_input3_value = value; - } - } - println!("Change: {}", text); - } - InputEvent::PressEnter { secondary } => { - println!("PressEnter secondary: {}", secondary) - } - InputEvent::Focus => println!("Focus"), - InputEvent::Blur => println!("Blur"), - }, NumberInputEvent::Step(step_action) => match step_action { StepAction::Decrement => { if this == &self.number_input1 { diff --git a/crates/ui/src/input/number_input.rs b/crates/ui/src/input/number_input.rs index f9b68c79..2b265823 100644 --- a/crates/ui/src/input/number_input.rs +++ b/crates/ui/src/input/number_input.rs @@ -6,9 +6,7 @@ use gpui::{ use crate::{ button::{Button, ButtonVariants as _}, - h_flex, - input::InputEvent, - ActiveTheme, IconName, Sizable, Size, StyleSized, StyledExt as _, + h_flex, ActiveTheme, IconName, Sizable, Size, StyleSized, StyledExt as _, }; use super::{InputState, TextInput}; @@ -90,7 +88,6 @@ pub enum StepAction { Increment, } pub enum NumberInputEvent { - Input(InputEvent), Step(StepAction), } impl EventEmitter for InputState {}