number_input: Remove InputEvent from NumberInputEvent (#884)
## Break Change - Number input no longer emits `InputEvent`; you need an additional subscription for `InputEvent`.
This commit is contained in:
parent
119d348e4a
commit
244090ddc5
2 changed files with 36 additions and 27 deletions
|
|
@ -79,8 +79,11 @@ impl NumberInputStory {
|
||||||
});
|
});
|
||||||
|
|
||||||
let _subscriptions = vec![
|
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_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_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),
|
cx.subscribe_in(&number_input3, window, Self::on_number_input_event),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -103,6 +106,38 @@ impl NumberInputStory {
|
||||||
self.cycle_focus(false, window, cx);
|
self.cycle_focus(false, window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_input_event(
|
||||||
|
&mut self,
|
||||||
|
this: &Entity<InputState>,
|
||||||
|
event: &InputEvent,
|
||||||
|
_: &mut Window,
|
||||||
|
_: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
match event {
|
||||||
|
InputEvent::Change(text) => {
|
||||||
|
if this == &self.number_input1 {
|
||||||
|
if let Ok(value) = text.parse::<i64>() {
|
||||||
|
self.number_input1_value = value;
|
||||||
|
}
|
||||||
|
} else if this == &self.number_input2 {
|
||||||
|
if let Ok(value) = text.parse::<u64>() {
|
||||||
|
self.number_input2_value = value;
|
||||||
|
}
|
||||||
|
} else if this == &self.number_input3 {
|
||||||
|
if let Ok(value) = text.parse::<f64>() {
|
||||||
|
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(
|
fn on_number_input_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
this: &Entity<InputState>,
|
this: &Entity<InputState>,
|
||||||
|
|
@ -111,29 +146,6 @@ impl NumberInputStory {
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
NumberInputEvent::Input(input_event) => match input_event {
|
|
||||||
InputEvent::Change(text) => {
|
|
||||||
if this == &self.number_input1 {
|
|
||||||
if let Ok(value) = text.parse::<i64>() {
|
|
||||||
self.number_input1_value = value;
|
|
||||||
}
|
|
||||||
} else if this == &self.number_input2 {
|
|
||||||
if let Ok(value) = text.parse::<u64>() {
|
|
||||||
self.number_input2_value = value;
|
|
||||||
}
|
|
||||||
} else if this == &self.number_input3 {
|
|
||||||
if let Ok(value) = text.parse::<f64>() {
|
|
||||||
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 {
|
NumberInputEvent::Step(step_action) => match step_action {
|
||||||
StepAction::Decrement => {
|
StepAction::Decrement => {
|
||||||
if this == &self.number_input1 {
|
if this == &self.number_input1 {
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@ use gpui::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
button::{Button, ButtonVariants as _},
|
button::{Button, ButtonVariants as _},
|
||||||
h_flex,
|
h_flex, ActiveTheme, IconName, Sizable, Size, StyleSized, StyledExt as _,
|
||||||
input::InputEvent,
|
|
||||||
ActiveTheme, IconName, Sizable, Size, StyleSized, StyledExt as _,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{InputState, TextInput};
|
use super::{InputState, TextInput};
|
||||||
|
|
@ -90,7 +88,6 @@ pub enum StepAction {
|
||||||
Increment,
|
Increment,
|
||||||
}
|
}
|
||||||
pub enum NumberInputEvent {
|
pub enum NumberInputEvent {
|
||||||
Input(InputEvent),
|
|
||||||
Step(StepAction),
|
Step(StepAction),
|
||||||
}
|
}
|
||||||
impl EventEmitter<NumberInputEvent> for InputState {}
|
impl EventEmitter<NumberInputEvent> for InputState {}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue