Skip to content

Commit

Permalink
Merge branch 'feat/updated-dioxus' into feat/memoized-focused-node
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Jan 26, 2024
2 parents cd568f8 + b9b3705 commit 6cb222f
Show file tree
Hide file tree
Showing 37 changed files with 109 additions and 155 deletions.
34 changes: 13 additions & 21 deletions crates/components/src/accordion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use freya_elements::elements as dioxus_elements;
use freya_elements::events::MouseEvent;

use freya_hooks::{
use_animation, use_applied_theme, use_node, use_platform, AccordionTheme, AccordionThemeWith,
Animation,
use_animation, use_applied_theme, use_node_signal, use_platform, AccordionTheme,
AccordionThemeWith, Animation,
};
use winit::window::CursorIcon;

Expand All @@ -22,7 +22,6 @@ pub enum AccordionStatus {
#[derive(Props, Clone, PartialEq)]
pub struct AccordionProps {
/// Theme override.
#[props(optional)]
pub theme: Option<AccordionThemeWith>,
/// Inner children for the Accordion.
pub children: Element,
Expand All @@ -42,8 +41,8 @@ pub struct AccordionProps {
pub fn Accordion(props: AccordionProps) -> Element {
let theme = use_applied_theme!(&props.theme, accordion);
let mut animation = use_animation(|| 0.0);
let open = use_signal(|| false);
let (node_ref, size) = use_node();
let mut open = use_signal(|| false);
let (node_ref, size) = use_node_signal();
let mut status = use_signal(AccordionStatus::default);
let platform = use_platform();

Expand All @@ -55,30 +54,23 @@ pub fn Accordion(props: AccordionProps) -> Element {
} = theme;

// Adapt the accordion if the body size changes
let _ = use_memo_with_dependencies(
&(
size.area.width(),
size.area.height(),
animation.is_animating(),
),
{
to_owned![animation];
move |(_, height, animating)| {
if (height as f64) < animation.value() && !animating {
animation.set_value(size.area.height() as f64);
}
use_memo({
to_owned![animation];
move || {
if (size().area.height() as f64) < animation.value() && !animation.is_animating() {
animation.set_value(size().area.height() as f64);
}
},
);
}
});

let onclick = move |_: MouseEvent| {
let bodyHeight = size.area.height() as f64;
let bodyHeight = size.peek().area.height() as f64;
if *open.read() {
animation.start(Animation::new_sine_in_out(bodyHeight..=0.0, 200));
} else {
animation.start(Animation::new_sine_in_out(0.0..=bodyHeight, 200));
}
open.with_mut(|o| *o = !*o);
open.toggle();
};

use_drop({
Expand Down
2 changes: 0 additions & 2 deletions crates/components/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ use winit::window::CursorIcon;
#[derive(Props, Clone, PartialEq)]
pub struct ButtonProps {
/// Theme override.
#[props(optional)]
pub theme: Option<ButtonThemeWith>,
/// Inner children for the Button.
pub children: Element,
/// Handler for the `onclick` event.
#[props(optional)]
pub onclick: Option<EventHandler<Option<MouseEvent>>>,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/components/src/drag_drop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
use freya_elements::elements as dioxus_elements;
use freya_elements::events::MouseEvent;
use freya_hooks::use_node_ref;
use freya_hooks::use_node_signal;
use torin::prelude::CursorPoint;

/// [`DragProvider`] component properties.
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn DragZone<T: 'static + Clone>(
let drags = use_context::<Signal<Option<T>>>();
let mut dragging = use_signal(|| false);
let mut pos = use_signal(CursorPoint::default);
let (node_reference, size) = use_node_ref();
let (node_reference, size) = use_node_signal();

let onglobalmouseover = move |e: MouseEvent| {
if *dragging.read() {
Expand Down
1 change: 0 additions & 1 deletion crates/components/src/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub struct DropdownItemProps<T: 'static + Clone> {
/// Selected value.
pub value: T,
/// Handler for the `onclick` event.
#[props(optional)]
pub onclick: Option<EventHandler<()>>,
}

Expand Down
6 changes: 2 additions & 4 deletions crates/components/src/external_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ use crate::Tooltip;
#[derive(Props, Clone, PartialEq)]
pub struct ExternalLinkProps {
/// Theme override.
#[props(optional)]
pub theme: Option<ExternalLinkThemeWith>,
/// Inner children for the ExternalLink.
pub children: Element,
/// Handler for the `onerror` event.
#[props(optional)]
pub onerror: Option<EventHandler<()>>,
/// Whether to show a tooltip with the URL or not.
#[props(optional, default = true)]
Expand Down Expand Up @@ -55,11 +53,11 @@ pub fn ExternalLink(props: ExternalLinkProps) -> Element {
let is_hovering = use_signal(|| false);

let onmouseover = move |_: MouseEvent| {
is_hovering.with_mut(|v| *v = true);
*is_hovering.write() = true;
};

let onmouseleave = move |_: MouseEvent| {
is_hovering.with_mut(|v| *v = false);
*is_hovering.write() = false;
};

let onclick = {
Expand Down
1 change: 0 additions & 1 deletion crates/components/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl GraphLine {
#[derive(Debug, Props, PartialEq, Clone)]
pub struct GraphProps {
/// Theme override.
#[props(optional)]
pub theme: Option<GraphThemeWith>,
/// X axis labels.
labels: Vec<String>,
Expand Down
1 change: 0 additions & 1 deletion crates/components/src/icons/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use freya_hooks::{use_applied_theme, ArrowIconTheme, ArrowIconThemeWith};
#[derive(Props, Clone, PartialEq)]
pub struct ArrowIconProps {
/// Theme override.
#[props(optional)]
pub theme: Option<ArrowIconThemeWith>,
#[props(into)]
pub rotate: String,
Expand Down
4 changes: 1 addition & 3 deletions crates/components/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ pub fn Input(
let focus = use_focus();

if &value != editable.editor().read().rope() {
editable.editor_mut().with_mut(|editor| {
editor.set(&value);
});
editable.editor_mut().write().set(&value);
}

let text = match mode {
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/network_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn NetworkImage(props: NetworkImageProps) -> Element {
} else {
rsx!({
image_bytes.as_ref().map(|bytes| {
let image_data = bytes_to_data(&*bytes);
let image_data = bytes_to_data(&bytes);
rsx!(image {
height: "{height}",
width: "{width}",
Expand Down
1 change: 0 additions & 1 deletion crates/components/src/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use freya_hooks::{use_applied_theme, ProgressBarTheme, ProgressBarThemeWith};
#[derive(Props, Clone, PartialEq)]
pub struct ProgressBarProps {
/// Theme override.
#[props(optional)]
pub theme: Option<ProgressBarThemeWith>,
/// Show a label with the current progress. Default to false.
#[props(default = false)]
Expand Down
1 change: 0 additions & 1 deletion crates/components/src/scroll_views/scroll_thumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use freya_hooks::{use_applied_theme, ScrollBarThemeWith};
#[derive(Props, Clone, PartialEq)]
pub struct ScrollThumbProps {
/// Theme override.
#[props(optional)]
pub theme: Option<ScrollBarThemeWith>,
pub clicking_scrollbar: bool,
pub onmousedown: EventHandler<MouseEvent>,
Expand Down
8 changes: 4 additions & 4 deletions crates/components/src/scroll_views/scroll_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn ScrollView(props: ScrollViewProps) -> Element {
corrected_scrolled_y,
);

scrolled_y.with_mut(|y| *y = scroll_position_y);
*scrolled_y.write() = scroll_position_y;
}

let wheel_x = if *clicking_shift.read() {
Expand All @@ -132,7 +132,7 @@ pub fn ScrollView(props: ScrollViewProps) -> Element {
corrected_scrolled_x,
);

scrolled_x.with_mut(|x| *x = scroll_position_x);
*scrolled_x.write() = scroll_position_x;

focus.focus();
}
Expand All @@ -154,7 +154,7 @@ pub fn ScrollView(props: ScrollViewProps) -> Element {
size.area.height(),
);

scrolled_y.with_mut(|y| *y = scroll_position);
*scrolled_y.write() = scroll_position;
} else if let Some((Axis::X, x)) = *clicking_scrollbar {
let coordinates = e.get_element_coordinates();
let cursor_x = coordinates.x - x - size.area.min_x() as f64;
Expand All @@ -165,7 +165,7 @@ pub fn ScrollView(props: ScrollViewProps) -> Element {
size.area.width(),
);

scrolled_x.with_mut(|x| *x = scroll_position);
*scrolled_x.write() = scroll_position;
}

if clicking_scrollbar.is_some() {
Expand Down
8 changes: 4 additions & 4 deletions crates/components/src/scroll_views/virtual_scroll_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn VirtualScrollView<T: Clone>(props: VirtualScrollViewProps<T>) -> Element
corrected_scrolled_y,
);

scrolled_y.with_mut(|y| *y = scroll_position_y);
*scrolled_y.write() = scroll_position_y;
}

let wheel_x = if *clicking_shift.peek() {
Expand All @@ -165,7 +165,7 @@ pub fn VirtualScrollView<T: Clone>(props: VirtualScrollViewProps<T>) -> Element
corrected_scrolled_x,
);

scrolled_x.with_mut(|x| *x = scroll_position_x);
*scrolled_x.write() = scroll_position_x;

focus.focus();
}
Expand All @@ -187,15 +187,15 @@ pub fn VirtualScrollView<T: Clone>(props: VirtualScrollViewProps<T>) -> Element
size.area.height(),
);

scrolled_y.with_mut(|y| *y = scroll_position);
*scrolled_y.write() = scroll_position;
} else if let Some((Axis::X, x)) = *clicking_scrollbar {
let coordinates = e.get_element_coordinates();
let cursor_x = coordinates.x - x - size.area.min_x() as f64;

let scroll_position =
get_scroll_position_from_cursor(cursor_x as f32, inner_size, size.area.width());

scrolled_x.with_mut(|x| *x = scroll_position);
*scrolled_x.write() = scroll_position;
}

if clicking_scrollbar.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub fn Slider(
let border = if focus.is_selected() {
format!("2 solid {}", theme.border_fill)
} else {
format!("none")
"none".to_string()
};

rsx!(
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum SwitchStatus {
/// Switch {
/// enabled: *enabled.read(),
/// ontoggled: move |_| {
/// enabled.with_mut(|v| *v = !*v);
/// enabled.toggle();
/// }
/// }
/// )
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct TableRowProps {
/// Inherits the [`TableTheme`](freya_hooks::TableTheme) theme.
///
#[allow(non_snake_case)]
pub fn TableRow<'a>(
pub fn TableRow(
TableRowProps {
theme,
children,
Expand Down
23 changes: 11 additions & 12 deletions crates/core/tests/pointer_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ use winit::event::TouchPhase;
#[tokio::test]
pub async fn pointer_events_from_mouse() {
fn pointer_events_app() -> Element {
let state = use_signal(|| vec![]);
let mut state = use_signal(|| vec![]);

let onpointerdown = move |_| state.with_mut(|v| v.push("down".to_string()));
let onpointerdown = move |_| state.push("down".to_string());

let onpointerup = move |_| state.with_mut(|v| v.push("up".to_string()));
let onpointerup = move |_| state.push("up".to_string());

let onpointerover = move |_| state.with_mut(|v| v.push("over".to_string()));
let onpointerover = move |_| state.push("over".to_string());

let onpointerenter = move |_| state.with_mut(|v| v.push("enter".to_string()));
let onpointerenter = move |_| state.push("enter".to_string());

let onpointerleave = move |_| state.with_mut(|v| v.push("leave".to_string()));
let onpointerleave = move |_| state.push("leave".to_string());

rsx!(
rect {
Expand Down Expand Up @@ -96,15 +96,15 @@ pub async fn pointer_events_from_mouse() {
#[tokio::test]
pub async fn pointer_events_from_touch() {
fn pointer_events_app() -> Element {
let state = use_signal(|| vec![]);
let mut state = use_signal(|| vec![]);

let onpointerdown = move |_| state.with_mut(|v| v.push("down".to_string()));
let onpointerdown = move |_| state.push("down".to_string());

let onpointerup = move |_| state.with_mut(|v| v.push("up".to_string()));
let onpointerup = move |_| state.push("up".to_string());

let onpointerover = move |_| state.with_mut(|v| v.push("over".to_string()));
let onpointerover = move |_| state.push("over".to_string());

let onpointerenter = move |_| state.with_mut(|v| v.push("enter".to_string()));
let onpointerenter = move |_| state.push("enter".to_string());

rsx!(
rect {
Expand All @@ -118,7 +118,6 @@ pub async fn pointer_events_from_touch() {
onpointerup: onpointerup,
onpointerover: onpointerover,
onpointerenter: onpointerenter,

label { "{state:?}" }
}
}
Expand Down
2 changes: 0 additions & 2 deletions crates/devtools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ pub fn DevTools(props: DevToolsProps) -> Element {
let theme = theme.read();
let color = &theme.body.color;

#[allow(clippy::await_holding_lock)]
use_effect(move || {
let rdom = props.rdom.clone();
let mutations_notifier = props.mutations_notifier.clone();
let children = children.clone();
spawn(async move {
loop {
mutations_notifier.notified().await;
Expand Down
4 changes: 2 additions & 2 deletions crates/dom/src/mutations_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a> WriteMutations for MutationsWriter<'a> {

fn replace_node_with(&mut self, id: dioxus_core::ElementId, m: usize) {
if m > 0 {
let mut dom_adapter = DioxusDOMAdapter::new_with_cache(&self.native_writer.rdom);
let mut dom_adapter = DioxusDOMAdapter::new_with_cache(self.native_writer.rdom);
self.layout.remove(
self.native_writer.state.element_to_node_id(id),
&mut dom_adapter,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'a> WriteMutations for MutationsWriter<'a> {
}

fn remove_node(&mut self, id: dioxus_core::ElementId) {
let mut dom_adapter = DioxusDOMAdapter::new_with_cache(&self.native_writer.rdom);
let mut dom_adapter = DioxusDOMAdapter::new_with_cache(self.native_writer.rdom);
self.layout.remove(
self.native_writer.state.element_to_node_id(id),
&mut dom_adapter,
Expand Down
8 changes: 0 additions & 8 deletions crates/elements/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ macro_rules! impl_element {
pub const $fil: AttributeDescription = (stringify!($fil), None, false);
)*
}

impl GlobalAttributes for $name {}
)*
};
}
Expand Down Expand Up @@ -631,9 +629,3 @@ pub mod events {
onpointerleave
];
}

#[doc(hidden)]
pub trait GlobalAttributes {}

#[doc(hidden)]
pub trait SvgAttributes {}
2 changes: 1 addition & 1 deletion crates/elements/src/events/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,6 @@ impl KeyboardData {

impl From<&PlatformEventData> for KeyboardData {
fn from(val: &PlatformEventData) -> Self {
val.downcast::<KeyboardData>().cloned().unwrap().into()
val.downcast::<KeyboardData>().cloned().unwrap()
}
}
Loading

0 comments on commit 6cb222f

Please sign in to comment.