diff --git a/docs/reference/src/platforms/tui.md b/docs/reference/src/platforms/tui.md index 82e9c1f2a..2b5a3ef96 100644 --- a/docs/reference/src/platforms/tui.md +++ b/docs/reference/src/platforms/tui.md @@ -50,7 +50,7 @@ To run our app: $ cargo run ``` -Press "ctrl-c" to close the app. To switch from "ctrl-c" to just "q" to quit you can launch the app with a Configeration to disable the default quit and use the root TuiContext to quit on your own. +Press "ctrl-c" to close the app. To switch from "ctrl-c" to just "q" to quit you can launch the app with a configuration to disable the default quit and use the root TuiContext to quit on your own. ```rust // main diff --git a/packages/html/src/events.rs b/packages/html/src/events.rs index 7e95375cf..d564fbbec 100644 --- a/packages/html/src/events.rs +++ b/packages/html/src/events.rs @@ -398,21 +398,21 @@ pub mod on { pub type ClipboardEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct ClipboardData { // DOMDataTransfer clipboardData } pub type CompositionEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct CompositionData { pub data: String, } pub type KeyboardEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct KeyboardData { pub char_code: u32, @@ -481,12 +481,12 @@ pub mod on { pub type FocusEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct FocusData {/* DOMEventInner: Send + SyncTarget relatedTarget */} pub type FormEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct FormData { pub value: String, pub values: HashMap, @@ -495,7 +495,7 @@ pub mod on { pub type MouseEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct MouseData { pub alt_key: bool, pub button: i16, @@ -514,7 +514,7 @@ pub mod on { pub type PointerEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct PointerData { // Mouse only pub alt_key: bool, @@ -544,12 +544,12 @@ pub mod on { pub type SelectionEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct SelectionData {} pub type TouchEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct TouchData { pub alt_key: bool, pub ctrl_key: bool, @@ -563,7 +563,7 @@ pub mod on { pub type WheelEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct WheelData { pub delta_mode: u32, pub delta_x: f64, @@ -573,19 +573,19 @@ pub mod on { pub type MediaEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct MediaData {} pub type ImageEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct ImageData { pub load_error: bool, } pub type AnimationEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct AnimationData { pub animation_name: String, pub pseudo_element: String, @@ -594,7 +594,7 @@ pub mod on { pub type TransitionEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct TransitionData { pub property_name: String, pub pseudo_element: String, @@ -603,7 +603,7 @@ pub mod on { pub type ToggleEvent = UiEvent; #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] - #[derive(Debug)] + #[derive(Debug, Clone)] pub struct ToggleData {} } diff --git a/packages/tui/src/hooks.rs b/packages/tui/src/hooks.rs index c09eed50b..63b71139a 100644 --- a/packages/tui/src/hooks.rs +++ b/packages/tui/src/hooks.rs @@ -30,12 +30,12 @@ use crate::{Dom, Node}; // pub fn mouse(&self) -> Option { // let data = (**self.0).borrow(); -// data.mouse.as_ref().map(|m| clone_mouse_data(m)) +// data.mouse.as_ref().map(|m| m.clone()) // } // pub fn wheel(&self) -> Option { // let data = (**self.0).borrow(); -// data.wheel.as_ref().map(|w| clone_wheel_data(w)) +// data.wheel.as_ref().map(|w| w.clone()) // } // pub fn screen(&self) -> Option<(u16, u16)> { @@ -47,7 +47,7 @@ use crate::{Dom, Node}; // let data = (**self.0).borrow(); // data.last_key_pressed // .as_ref() -// .map(|k| clone_keyboard_data(&k.0)) +// .map(|k| &k.0.clone()) // } // } @@ -99,7 +99,7 @@ impl InnerInputState { EventData::Mouse(ref mut m) => match &mut self.mouse { Some(state) => { let mut buttons = state.0.buttons; - state.0 = clone_mouse_data(m); + state.0 = m.clone(); match evt.0 { // this code only runs when there are no buttons down "mouseup" => { @@ -135,7 +135,7 @@ impl InnerInputState { } None => { self.mouse = Some(( - clone_mouse_data(m), + m.clone(), if m.buttons == 0 { Vec::new() } else { @@ -144,7 +144,7 @@ impl InnerInputState { )); } }, - EventData::Wheel(ref w) => self.wheel = Some(clone_wheel_data(w)), + EventData::Wheel(ref w) => self.wheel = Some(w.clone()), EventData::Screen(ref s) => self.screen = Some(*s), EventData::Keyboard(ref mut k) => { let repeat = self @@ -153,7 +153,7 @@ impl InnerInputState { .filter(|k2| k2.0.key == k.key && k2.1.elapsed() < MAX_REPEAT_TIME) .is_some(); k.repeat = repeat; - let new = clone_keyboard_data(k); + let new = k.clone(); self.last_key_pressed = Some((new, Instant::now())); } } @@ -166,10 +166,7 @@ impl InnerInputState { layout: &Stretch, dom: &mut Dom, ) { - let previous_mouse = self - .mouse - .as_ref() - .map(|m| (clone_mouse_data(&m.0), m.1.clone())); + let previous_mouse = self.mouse.as_ref().map(|m| (m.0.clone(), m.1.clone())); self.wheel = None; @@ -269,7 +266,7 @@ impl InnerInputState { if currently_contains && previously_contained { try_create_event( "mousemove", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -293,7 +290,7 @@ impl InnerInputState { if currently_contains && !previously_contained { try_create_event( "mouseenter", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -317,7 +314,7 @@ impl InnerInputState { if currently_contains && !previously_contained { try_create_event( "mouseover", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -337,7 +334,7 @@ impl InnerInputState { if currently_contains && data.clicked { try_create_event( "mousedown", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -357,7 +354,7 @@ impl InnerInputState { if currently_contains && data.released { try_create_event( "mouseup", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -377,7 +374,7 @@ impl InnerInputState { if currently_contains && data.released && data.mouse_data.button == 0 { try_create_event( "click", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -397,7 +394,7 @@ impl InnerInputState { if currently_contains && data.released && data.mouse_data.button == 2 { try_create_event( "contextmenu", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -418,7 +415,7 @@ impl InnerInputState { if currently_contains && data.wheel_delta != 0.0 { try_create_event( "wheel", - Arc::new(clone_wheel_data(w)), + Arc::new(w.clone()), &mut will_bubble, resolved_events, node, @@ -443,7 +440,7 @@ impl InnerInputState { if !currently_contains && previously_contained { try_create_event( "mouseleave", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -467,7 +464,7 @@ impl InnerInputState { if !currently_contains && previously_contained { try_create_event( "mouseout", - Arc::new(clone_mouse_data(data.mouse_data)), + Arc::new(data.mouse_data.clone()), &mut will_bubble, resolved_events, node, @@ -786,45 +783,3 @@ fn translate_key_event(event: crossterm::event::KeyEvent) -> Option { which: Default::default(), })) } - -fn clone_mouse_data(m: &MouseData) -> MouseData { - MouseData { - client_x: m.client_x, - client_y: m.client_y, - page_x: m.page_x, - page_y: m.page_y, - screen_x: m.screen_x, - screen_y: m.screen_y, - alt_key: m.alt_key, - ctrl_key: m.ctrl_key, - meta_key: m.meta_key, - shift_key: m.shift_key, - button: m.button, - buttons: m.buttons, - } -} - -fn clone_keyboard_data(k: &KeyboardData) -> KeyboardData { - KeyboardData { - char_code: k.char_code, - key: k.key.clone(), - key_code: k.key_code, - alt_key: k.alt_key, - ctrl_key: k.ctrl_key, - meta_key: k.meta_key, - shift_key: k.shift_key, - locale: k.locale.clone(), - location: k.location, - repeat: k.repeat, - which: k.which, - } -} - -fn clone_wheel_data(w: &WheelData) -> WheelData { - WheelData { - delta_mode: w.delta_mode, - delta_x: w.delta_x, - delta_y: w.delta_y, - delta_z: w.delta_x, - } -} diff --git a/packages/tui/src/render.rs b/packages/tui/src/render.rs index e3f03f0d8..3e75f3a5e 100644 --- a/packages/tui/src/render.rs +++ b/packages/tui/src/render.rs @@ -55,7 +55,7 @@ pub(crate) fn render_vnode( let label = Label { text, - style: node.state.style.style, + style: node.state.style.core, }; let area = Rect::new(*x as u16, *y as u16, *width as u16, *height as u16); @@ -264,7 +264,7 @@ impl RinkWidget for &Node { for x in area.left()..area.right() { for y in area.top()..area.bottom() { let mut new_cell = RinkCell::default(); - if let Some(c) = self.state.style.style.bg { + if let Some(c) = self.state.style.core.bg { new_cell.bg = c; } buf.set(x, y, new_cell); @@ -288,7 +288,7 @@ impl RinkWidget for &Node { (last_r * RADIUS_MULTIPLIER[0]) as u16, (last_r * RADIUS_MULTIPLIER[1]) as u16, ]; - let color = current_edge.color.or(self.state.style.style.fg); + let color = current_edge.color.or(self.state.style.core.fg); let mut new_cell = RinkCell::default(); if let Some(c) = color { new_cell.fg = c; @@ -323,7 +323,7 @@ impl RinkWidget for &Node { (last_r * RADIUS_MULTIPLIER[0]) as u16, (last_r * RADIUS_MULTIPLIER[1]) as u16, ]; - let color = current_edge.color.or(self.state.style.style.fg); + let color = current_edge.color.or(self.state.style.core.fg); let mut new_cell = RinkCell::default(); if let Some(c) = color { new_cell.fg = c; @@ -358,7 +358,7 @@ impl RinkWidget for &Node { (last_r * RADIUS_MULTIPLIER[0]) as u16, (last_r * RADIUS_MULTIPLIER[1]) as u16, ]; - let color = current_edge.color.or(self.state.style.style.fg); + let color = current_edge.color.or(self.state.style.core.fg); let mut new_cell = RinkCell::default(); if let Some(c) = color { new_cell.fg = c; @@ -393,7 +393,7 @@ impl RinkWidget for &Node { (last_r * RADIUS_MULTIPLIER[0]) as u16, (last_r * RADIUS_MULTIPLIER[1]) as u16, ]; - let color = current_edge.color.or(self.state.style.style.fg); + let color = current_edge.color.or(self.state.style.core.fg); let mut new_cell = RinkCell::default(); if let Some(c) = color { new_cell.fg = c; diff --git a/packages/tui/src/style_attributes.rs b/packages/tui/src/style_attributes.rs index 87353bbe0..c2e0db3fd 100644 --- a/packages/tui/src/style_attributes.rs +++ b/packages/tui/src/style_attributes.rs @@ -41,7 +41,7 @@ use crate::style::{RinkColor, RinkStyle}; #[derive(Default, Clone, PartialEq, Debug)] pub struct StyleModifier { - pub style: RinkStyle, + pub core: RinkStyle, pub modifier: TuiModifier, } @@ -55,7 +55,7 @@ impl ParentDepState for StyleModifier { fn reduce(&mut self, node: NodeView, parent: Option<&Self::DepState>, _: &Self::Ctx) -> bool { let mut new = StyleModifier::default(); if parent.is_some() { - new.style.fg = None; + new.core.fg = None; } // handle text modifier elements @@ -84,9 +84,9 @@ impl ParentDepState for StyleModifier { // keep the text styling from the parent element if let Some(parent) = parent { - let mut new_style = new.style.merge(parent.style); - new_style.bg = new.style.bg; - new.style = new_style; + let mut new_style = new.core.merge(parent.core); + new_style.bg = new.core.bg; + new.core = new_style; } if &mut new != self { *self = new; @@ -255,7 +255,7 @@ pub fn apply_style_attributes( "color" => { if let Ok(c) = value.parse() { - style.style.fg.replace(c); + style.core.fg.replace(c); } } @@ -324,7 +324,7 @@ fn apply_background(name: &str, value: &str, style: &mut StyleModifier) { match name { "background-color" => { if let Ok(c) = value.parse() { - style.style.bg.replace(c); + style.core.bg.replace(c); } } "background" => {} @@ -546,14 +546,14 @@ fn apply_font(name: &str, value: &str, style: &mut StyleModifier) { "font-size-adjust" => (), "font-stretch" => (), "font-style" => match value { - "italic" => style.style = style.style.add_modifier(Modifier::ITALIC), - "oblique" => style.style = style.style.add_modifier(Modifier::ITALIC), + "italic" => style.core = style.core.add_modifier(Modifier::ITALIC), + "oblique" => style.core = style.core.add_modifier(Modifier::ITALIC), _ => (), }, "font-variant" => todo!(), "font-weight" => match value { - "bold" => style.style = style.style.add_modifier(Modifier::BOLD), - "normal" => style.style = style.style.remove_modifier(Modifier::BOLD), + "bold" => style.core = style.core.add_modifier(Modifier::BOLD), + "normal" => style.core = style.core.remove_modifier(Modifier::BOLD), _ => (), }, _ => (), @@ -569,8 +569,8 @@ fn apply_text(name: &str, value: &str, style: &mut StyleModifier) { "text-decoration" | "text-decoration-line" => { for v in value.split(' ') { match v { - "line-through" => style.style = style.style.add_modifier(Modifier::CROSSED_OUT), - "underline" => style.style = style.style.add_modifier(Modifier::UNDERLINED), + "line-through" => style.core = style.core.add_modifier(Modifier::CROSSED_OUT), + "underline" => style.core = style.core.add_modifier(Modifier::UNDERLINED), _ => (), } } diff --git a/packages/tui/tests/margin.rs b/packages/tui/tests/margin.rs index 44f909d69..53e8978e5 100644 --- a/packages/tui/tests/margin.rs +++ b/packages/tui/tests/margin.rs @@ -90,11 +90,4 @@ fn margin_and_flex_row2() { assert_eq!(stretch.layout(node).unwrap().size.height, 100f32); assert_eq!(stretch.layout(node).unwrap().location.x, 0f32); assert_eq!(stretch.layout(node).unwrap().location.y, 0f32); - - dbg!(stretch.layout(node0)).unwrap(); - - // assert_eq!(stretch.layout(node0).unwrap().size.width, 80f32); - // assert_eq!(stretch.layout(node0).unwrap().size.height, 100f32); - // assert_eq!(stretch.layout(node0).unwrap().location.x, 10f32); - // assert_eq!(stretch.layout(node0).unwrap().location.y, 0f32); } diff --git a/src/lib.rs b/src/lib.rs index 008769177..6f034cea6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,8 @@ pub use dioxus_tui as tui; #[cfg(feature = "native-core")] pub use dioxus_native_core as native_core; +#[cfg(feature = "native-core")] +pub use dioxus_native_core_macro as native_core_macro; #[cfg(feature = "fermi")] pub use fermi;