Merge branch 'master' into get-parsed-values-for-form-values
This commit is contained in:
314 files changed
+13745
-4840
No files matched your search
+75
-54
@@ -2,6 +2,10 @@ use crossterm::event::{
|
||||
Event as TermEvent, KeyCode as TermKeyCode, KeyModifiers, ModifierKeyCode, MouseButton,
|
||||
MouseEventKind,
|
||||
};
|
||||
use dioxus_html::{
|
||||
HasFormData, HasKeyboardData, HasWheelData, SerializedFocusData, SerializedKeyboardData,
|
||||
SerializedMouseData, SerializedWheelData,
|
||||
};
|
||||
use dioxus_native_core::prelude::*;
|
||||
use dioxus_native_core::real_dom::NodeImmutable;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
@@ -11,9 +15,11 @@ use dioxus_html::geometry::{
|
||||
ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint, WheelDelta,
|
||||
};
|
||||
use dioxus_html::input_data::keyboard_types::{Code, Key, Location, Modifiers};
|
||||
use dioxus_html::input_data::MouseButtonSet as DioxusMouseButtons;
|
||||
use dioxus_html::input_data::{MouseButton as DioxusMouseButton, MouseButtonSet};
|
||||
use dioxus_html::{event_bubbles, FocusData, FormValue, KeyboardData, MouseData, WheelData};
|
||||
use dioxus_html::input_data::{
|
||||
MouseButton as DioxusMouseButton, MouseButtonSet as DioxusMouseButtons,
|
||||
};
|
||||
use dioxus_html::{event_bubbles, prelude::*};
|
||||
use dioxus_html::{FocusData, FormValue, KeyboardData, MouseData, WheelData};
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
use std::{
|
||||
@@ -38,10 +44,10 @@ pub struct Event {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum EventData {
|
||||
Mouse(MouseData),
|
||||
Keyboard(KeyboardData),
|
||||
Focus(FocusData),
|
||||
Wheel(WheelData),
|
||||
Mouse(SerializedMouseData),
|
||||
Keyboard(SerializedKeyboardData),
|
||||
Focus(SerializedFocusData),
|
||||
Wheel(SerializedWheelData),
|
||||
Form(FormData),
|
||||
}
|
||||
|
||||
@@ -52,27 +58,31 @@ impl EventData {
|
||||
EventData::Keyboard(k) => Rc::new(k),
|
||||
EventData::Focus(f) => Rc::new(f),
|
||||
EventData::Wheel(w) => Rc::new(w),
|
||||
EventData::Form(f) => Rc::new(f.into_html()),
|
||||
EventData::Form(f) => Rc::new(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct FormData {
|
||||
pub value: String,
|
||||
pub(crate) value: String,
|
||||
|
||||
pub values: HashMap<String, FormValue>,
|
||||
|
||||
pub files: Option<Files>,
|
||||
pub(crate) files: Option<Files>,
|
||||
}
|
||||
|
||||
impl FormData {
|
||||
fn into_html(self) -> dioxus_html::FormData {
|
||||
dioxus_html::FormData {
|
||||
value: self.value,
|
||||
values: self.values,
|
||||
files: None,
|
||||
}
|
||||
impl HasFormData for FormData {
|
||||
fn value(&self) -> String {
|
||||
self.value.clone()
|
||||
}
|
||||
|
||||
fn values(&self) -> HashMap<String, Vec<String>> {
|
||||
self.values.clone()
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,9 +99,9 @@ type EventCore = (&'static str, EventData);
|
||||
const MAX_REPEAT_TIME: Duration = Duration::from_millis(100);
|
||||
|
||||
pub struct InnerInputState {
|
||||
mouse: Option<MouseData>,
|
||||
wheel: Option<WheelData>,
|
||||
last_key_pressed: Option<(KeyboardData, Instant)>,
|
||||
mouse: Option<SerializedMouseData>,
|
||||
wheel: Option<SerializedWheelData>,
|
||||
last_key_pressed: Option<(SerializedKeyboardData, Instant)>,
|
||||
pub(crate) focus_state: FocusState,
|
||||
// subscribers: Vec<Rc<dyn Fn() + 'static>>,
|
||||
}
|
||||
@@ -114,7 +124,7 @@ impl InnerInputState {
|
||||
EventData::Mouse(ref mut m) => {
|
||||
let mut held_buttons = match &self.mouse {
|
||||
Some(previous_data) => previous_data.held_buttons(),
|
||||
None => MouseButtonSet::empty(),
|
||||
None => DioxusMouseButtons::empty(),
|
||||
};
|
||||
|
||||
match evt.0 {
|
||||
@@ -133,10 +143,16 @@ impl InnerInputState {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let new_mouse_data = MouseData::new(
|
||||
m.coordinates(),
|
||||
let coordinates = m.coordinates();
|
||||
let new_mouse_data = SerializedMouseData::new(
|
||||
m.trigger_button(),
|
||||
held_buttons,
|
||||
Coordinates::new(
|
||||
m.screen_coordinates(),
|
||||
m.client_coordinates(),
|
||||
coordinates.element(),
|
||||
m.page_coordinates(),
|
||||
),
|
||||
m.modifiers(),
|
||||
);
|
||||
|
||||
@@ -155,7 +171,13 @@ impl InnerInputState {
|
||||
.is_some();
|
||||
|
||||
if is_repeating {
|
||||
*k = KeyboardData::new(k.key(), k.code(), k.location(), true, k.modifiers());
|
||||
*k = SerializedKeyboardData::new(
|
||||
k.key(),
|
||||
k.code(),
|
||||
k.location(),
|
||||
is_repeating,
|
||||
k.modifiers(),
|
||||
);
|
||||
}
|
||||
|
||||
self.last_key_pressed = Some((k.clone(), Instant::now()));
|
||||
@@ -199,13 +221,13 @@ impl InnerInputState {
|
||||
resolved_events.push(Event {
|
||||
name: "focus",
|
||||
id,
|
||||
data: EventData::Focus(FocusData {}),
|
||||
data: EventData::Focus(SerializedFocusData::default()),
|
||||
bubbles: event_bubbles("focus"),
|
||||
});
|
||||
resolved_events.push(Event {
|
||||
name: "focusin",
|
||||
id,
|
||||
data: EventData::Focus(FocusData {}),
|
||||
data: EventData::Focus(SerializedFocusData::default()),
|
||||
bubbles: event_bubbles("focusin"),
|
||||
});
|
||||
}
|
||||
@@ -213,7 +235,7 @@ impl InnerInputState {
|
||||
resolved_events.push(Event {
|
||||
name: "focusout",
|
||||
id,
|
||||
data: EventData::Focus(FocusData {}),
|
||||
data: EventData::Focus(SerializedFocusData::default()),
|
||||
bubbles: event_bubbles("focusout"),
|
||||
});
|
||||
}
|
||||
@@ -226,7 +248,7 @@ impl InnerInputState {
|
||||
|
||||
fn resolve_mouse_events(
|
||||
&mut self,
|
||||
previous_mouse: Option<MouseData>,
|
||||
previous_mouse: Option<SerializedMouseData>,
|
||||
resolved_events: &mut Vec<Event>,
|
||||
layout: &Taffy,
|
||||
dom: &mut RealDom,
|
||||
@@ -273,7 +295,10 @@ impl InnerInputState {
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_mouse_data(mouse_data: &MouseData, layout: &Layout) -> MouseData {
|
||||
fn prepare_mouse_data(
|
||||
mouse_data: &SerializedMouseData,
|
||||
layout: &Layout,
|
||||
) -> SerializedMouseData {
|
||||
let Point { x, y } = layout.location;
|
||||
let node_origin = ClientPoint::new(
|
||||
layout_to_screen_space(x).into(),
|
||||
@@ -284,17 +309,15 @@ impl InnerInputState {
|
||||
.to_point()
|
||||
.cast_unit();
|
||||
|
||||
let coordinates = Coordinates::new(
|
||||
mouse_data.screen_coordinates(),
|
||||
mouse_data.client_coordinates(),
|
||||
new_client_coordinates,
|
||||
mouse_data.page_coordinates(),
|
||||
);
|
||||
|
||||
MouseData::new(
|
||||
coordinates,
|
||||
SerializedMouseData::new(
|
||||
mouse_data.trigger_button(),
|
||||
mouse_data.held_buttons(),
|
||||
Coordinates::new(
|
||||
mouse_data.screen_coordinates(),
|
||||
mouse_data.client_coordinates(),
|
||||
new_client_coordinates,
|
||||
mouse_data.page_coordinates(),
|
||||
),
|
||||
mouse_data.modifiers(),
|
||||
)
|
||||
}
|
||||
@@ -305,7 +328,7 @@ impl InnerInputState {
|
||||
|
||||
// a mouse button is pressed if a button was not down and is now down
|
||||
let previous_buttons = previous_mouse
|
||||
.map_or(MouseButtonSet::empty(), |previous_data| {
|
||||
.map_or(DioxusMouseButtons::empty(), |previous_data| {
|
||||
previous_data.held_buttons()
|
||||
});
|
||||
let was_pressed = !(mouse_data.held_buttons() - previous_buttons).is_empty();
|
||||
@@ -689,17 +712,6 @@ fn get_event(evt: TermEvent) -> Option<(&'static str, EventData)> {
|
||||
|
||||
// from https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
|
||||
|
||||
// The `page` and `screen` coordinates are inconsistent with the MDN definition, as they are relative to the viewport (client), not the target element/page/screen, respectively.
|
||||
// todo?
|
||||
// But then, MDN defines them in terms of pixels, yet crossterm provides only row/column, and it might not be possible to get pixels. So we can't get 100% consistency anyway.
|
||||
let coordinates = Coordinates::new(
|
||||
ScreenPoint::new(x, y),
|
||||
ClientPoint::new(x, y),
|
||||
// offset x/y are set when the origin of the event is assigned to an element
|
||||
ElementPoint::new(0., 0.),
|
||||
PagePoint::new(x, y),
|
||||
);
|
||||
|
||||
let mut modifiers = Modifiers::empty();
|
||||
if shift {
|
||||
modifiers.insert(Modifiers::SHIFT);
|
||||
@@ -715,17 +727,26 @@ fn get_event(evt: TermEvent) -> Option<(&'static str, EventData)> {
|
||||
}
|
||||
|
||||
// held mouse buttons get set later by maintaining state, as crossterm does not provide them
|
||||
EventData::Mouse(MouseData::new(
|
||||
coordinates,
|
||||
EventData::Mouse(SerializedMouseData::new(
|
||||
button,
|
||||
DioxusMouseButtons::empty(),
|
||||
Coordinates::new(
|
||||
// The `page` and `screen` coordinates are inconsistent with the MDN definition, as they are relative to the viewport (client), not the target element/page/screen, respectively.
|
||||
// todo?
|
||||
// But then, MDN defines them in terms of pixels, yet crossterm provides only row/column, and it might not be possible to get pixels. So we can't get 100% consistency anyway.
|
||||
ScreenPoint::new(x, y),
|
||||
ClientPoint::new(x, y),
|
||||
// offset x/y are set when the origin of the event is assigned to an element
|
||||
ElementPoint::new(0., 0.),
|
||||
PagePoint::new(x, y),
|
||||
),
|
||||
modifiers,
|
||||
))
|
||||
};
|
||||
|
||||
let get_wheel_data = |up| {
|
||||
let y = if up { -1.0 } else { 1.0 };
|
||||
EventData::Wheel(WheelData::new(WheelDelta::lines(0., y, 0.)))
|
||||
EventData::Wheel(SerializedWheelData::new(WheelDelta::lines(0., y, 0.)))
|
||||
};
|
||||
|
||||
match m.kind {
|
||||
@@ -750,7 +771,7 @@ fn translate_key_event(event: crossterm::event::KeyEvent) -> Option<EventData> {
|
||||
let code = guess_code_from_crossterm_key_code(event.code)?;
|
||||
let modifiers = modifiers_from_crossterm_modifiers(event.modifiers);
|
||||
|
||||
Some(EventData::Keyboard(KeyboardData::new(
|
||||
Some(EventData::Keyboard(SerializedKeyboardData::new(
|
||||
key,
|
||||
code,
|
||||
Location::Standard,
|
||||
|
||||
Reference in new issue
Block a user