From cc77ee4f19f887bbc91f9ffb2cc9ef46698f9350 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 31 Oct 2023 18:58:39 +0100 Subject: [PATCH 1/3] chore: run fmt and clippy --- crates/core/src/events_processor.rs | 2 +- crates/core/src/layers.rs | 2 +- crates/layout/src/layers.rs | 2 +- crates/torin/src/measure_mode.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/core/src/events_processor.rs b/crates/core/src/events_processor.rs index cc9fca92c..753dddee8 100644 --- a/crates/core/src/events_processor.rs +++ b/crates/core/src/events_processor.rs @@ -79,7 +79,7 @@ impl EventsProcessor { // All these events will mark the node as being hovered // "mouseover" "mouseenter" "pointerover" "pointerenter" - // We clone this here so events emitted in the same batch that mark an element as hovered will not affect the other events + // We clone this here so events emitted in the same batch that mark an element as hovered will not affect the other events let hovered_elements = self.hovered_elements.clone(); // Emit valid events diff --git a/crates/core/src/layers.rs b/crates/core/src/layers.rs index 3d0da7b6f..76d3970fd 100644 --- a/crates/core/src/layers.rs +++ b/crates/core/src/layers.rs @@ -53,7 +53,7 @@ pub fn process_layers( let text_group = layers .paragraph_elements .entry(cursor_ref.text_id) - .or_insert_with(Vec::default); + .or_default(); text_group.push(node.id()); } diff --git a/crates/layout/src/layers.rs b/crates/layout/src/layers.rs index 11ab1d003..cff9364a4 100644 --- a/crates/layout/src/layers.rs +++ b/crates/layout/src/layers.rs @@ -77,7 +77,7 @@ impl Layers { /// Insert a Node into a layer pub fn add_element(&mut self, node_id: NodeId, node_layer: i16) { - let layer = self.layers.entry(node_layer).or_insert_with(Vec::default); + let layer = self.layers.entry(node_layer).or_default(); layer.push(node_id); } diff --git a/crates/torin/src/measure_mode.rs b/crates/torin/src/measure_mode.rs index d320077ad..78cd6c464 100644 --- a/crates/torin/src/measure_mode.rs +++ b/crates/torin/src/measure_mode.rs @@ -31,8 +31,8 @@ impl<'a> MeasureMode<'a> { }, MeasureMode::ParentIsNotCached { area, inner_area } => { OwnedMeasureMode::ParentIsNotCached { - area: **area.clone(), - inner_area: **inner_area.clone(), + area: **area, + inner_area: **inner_area, } } } From bfd10baf46f81b7726dd1b0d9c6458d750bdf03d Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 31 Oct 2023 18:59:46 +0100 Subject: [PATCH 2/3] fix: Use `text_align` in `Table` example --- examples/table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/table.rs b/examples/table.rs index 929a0c5b9..3497f4381 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -118,7 +118,7 @@ fn app(cx: Scope) -> Element { divider: n > 0, label { width: "100%", - align: "right", + text_align: "right", "{item}" } } From dacf9fc03c6618a0afbf39b2302f60cc835ec711 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Wed, 1 Nov 2023 23:46:01 +0100 Subject: [PATCH 3/3] chore: Update i18n example --- Cargo.toml | 2 +- examples/shader.rs | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d76472d74..d723bf01f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ freya-node-state = { workspace = true } reqwest = { version = "0.11.22", features = ["json"] } serde = "1.0.189" tracing-subscriber = "0.3.17" -dioxus-std = { version = "0.4", features = ["utils", "i18n"] } +dioxus-std = { version = "0.4", features = ["i18n"] } rand = "0.8.5" dioxus-router = { workspace = true } itertools = "0.11.0" diff --git a/examples/shader.rs b/examples/shader.rs index ed113e9a0..b08ef73c1 100644 --- a/examples/shader.rs +++ b/examples/shader.rs @@ -5,13 +5,11 @@ use std::{ sync::{Arc, Mutex}, - time::{Duration, Instant}, + time::Instant, }; -use dioxus_std::utils::channel::{use_channel, use_listen_channel}; -use freya::{common::EventMessage, prelude::*}; +use freya::prelude::*; use skia_safe::{Color, Data, Paint, Rect, RuntimeEffect}; -use tokio::time::sleep; fn main() { launch(app); @@ -36,14 +34,16 @@ const SHADER: &str = " fn app(cx: Scope) -> Element { let platform = use_platform(cx); - let render_channel = use_channel::<()>(cx, 1); - use_listen_channel(cx, &render_channel, move |_| { - to_owned![platform]; - async move { - sleep(Duration::from_millis(25)).await; - platform.send(EventMessage::RequestRerender).unwrap(); - } + cx.use_hook(|| { + let mut ticker = platform.new_ticker(); + + cx.spawn(async move { + loop { + ticker.tick().await; + platform.request_animation_frame(); + } + }); }); let canvas = use_canvas(cx, (), |_| { @@ -51,7 +51,7 @@ fn app(cx: Scope) -> Element { let shader_wrapper = Arc::new(Mutex::new(ShaderWrapper(shader))); let instant = Instant::now(); - to_owned![render_channel, shader_wrapper]; + to_owned![shader_wrapper]; Box::new(move |canvas, _, region| { let shader = shader_wrapper.lock().unwrap(); @@ -83,8 +83,6 @@ fn app(cx: Scope) -> Element { ), &paint, ); - - render_channel.try_send(()).ok(); }) });