Skip to content

Commit

Permalink
Merge branch 'main' into chore/bump-dx
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Apr 5, 2024
2 parents 2d3a47c + 0e05a3e commit 55f6046
Show file tree
Hide file tree
Showing 119 changed files with 1,915 additions and 1,085 deletions.
39 changes: 19 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.0"
edition = "2021"

[workspace]
members = ["crates/renderer", "crates/state", "crates/freya", "crates/elements", "crates/components", "crates/hooks", "crates/common", "crates/core", "crates/testing", "crates/devtools", "crates/dom", "crates/torin", "crates/engine", "./examples/installer", "crates/native-core", "crates/native-core-macro"]
members = ["crates/renderer", "crates/state", "crates/freya", "crates/elements", "crates/components", "crates/hooks", "crates/common", "crates/core", "crates/testing", "crates/devtools", "crates/torin", "crates/engine", "./examples/installer", "crates/native-core", "crates/native-core-macro"]

[features]
log = ["freya/log"]
Expand All @@ -13,14 +13,14 @@ use_camera = ["freya/use_camera"]
hot-reload = ["freya/hot-reload"]

[patch.crates-io]
dioxus = { git = "https://github.com/DioxusLabs/dioxus", rev = "fd21c971038840130f2961c7aa5c3541c0823446" }
dioxus-rsx = { git = "https://github.com/DioxusLabs/dioxus", rev = "fd21c971038840130f2961c7aa5c3541c0823446" }
dioxus-core-macro = { git = "https://github.com/DioxusLabs/dioxus", rev = "fd21c971038840130f2961c7aa5c3541c0823446" }
dioxus-hooks = { git = "https://github.com/DioxusLabs/dioxus", rev = "fd21c971038840130f2961c7aa5c3541c0823446" }
dioxus-signals = { git = "https://github.com/DioxusLabs/dioxus", rev = "fd21c971038840130f2961c7aa5c3541c0823446" }
dioxus-core = { git = "https://github.com/DioxusLabs/dioxus", rev = "fd21c971038840130f2961c7aa5c3541c0823446" }
dioxus-hot-reload = { git = "https://github.com/DioxusLabs/dioxus", rev = "fd21c971038840130f2961c7aa5c3541c0823446" }
dioxus-router = { git = "https://github.com/DioxusLabs/dioxus", rev = "fd21c971038840130f2961c7aa5c3541c0823446" }
# dioxus = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
# dioxus-rsx = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
# dioxus-core-macro = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
# dioxus-hooks = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
# dioxus-signals = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
# dioxus-core = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
# dioxus-hot-reload = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
# dioxus-router = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }

[workspace.dependencies]
freya = { path = "crates/freya", version = "0.1" }
Expand All @@ -32,25 +32,24 @@ freya-common = { path = "crates/common", version = "0.1" }
freya-hooks = { path = "crates/hooks", version = "0.1" }
freya-core = { path = "crates/core", version = "0.1" }
freya-components = { path = "crates/components", version = "0.1" }
freya-dom = { path = "crates/dom", version = "0.1" }
freya-testing = { path = "crates/testing", version = "0.1" }
freya-engine = { path = "crates/engine", version = "0.1" }
torin = { path = "crates/torin", version = "0.1" }

dioxus-native-core-macro = { path = "crates/native-core-macro", version = "0.1" }
dioxus-native-core = { path = "crates/native-core", version = "0.1" }

dioxus = { version = "0.5.0-alpha.0", default-features = false, features = ["macro", "signals", "hooks"]}
dioxus-rsx = { version = "0.5.0-alpha.0", features = ["hot_reload"] }
dioxus-core-macro = { version = "0.5.0-alpha.0" }
dioxus-hooks = { version = "0.5.0-alpha.0" }
dioxus-signals = { version = "0.5.0-alpha.0" }
dioxus-core = { version = "0.5.0-alpha.0" }
dioxus-hot-reload = { version = "0.5.0-alpha.0", features = ["file_watcher"], default-features = false }
dioxus-router = { version = "0.5.0-alpha.0", default-features = false }
dioxus-std = { git = "https://github.com/marc2332/dioxus-std", rev = "4d8ae33b94537d54471cd924c32f03c1d949430f", features = ["clipboard"]}
dioxus = { version = "0.5", default-features = false, features = ["macro", "signals", "hooks"]}
dioxus-rsx = { version = "0.5", features = ["hot_reload"] }
dioxus-core-macro = { version = "0.5" }
dioxus-hooks = { version = "0.5" }
dioxus-signals = { version = "0.5" }
dioxus-core = { version = "0.5" }
dioxus-hot-reload = { version = "0.5", features = ["file_watcher"], default-features = false }
dioxus-router = { version = "0.5", default-features = false }
dioxus-std = { version = "0.5", features = ["clipboard"]}

skia-safe = { version = "0.70.0", features = ["gl", "textlayout", "svg"] }
skia-safe = { version = "0.72.0", features = ["gl", "textlayout", "svg"] }

gl = "0.14.0"
glutin = "0.31.2"
Expand Down
9 changes: 9 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ repository = "https://github.com/marc2332/freya"
keywords = ["gui", "ui", "desktop", "skia", "dioxus"]
categories = ["gui", "asynchronous"]

[package.metadata.docs.rs]
features = ["freya-engine/mocked-engine"]

[features]
skia-engine = ["freya-engine/skia-engine"]

[dependencies]
torin = { workspace = true }

Expand All @@ -19,5 +25,8 @@ dioxus-core = { workspace = true }
accesskit = { workspace = true }
accesskit_winit = { workspace = true }
winit = { workspace = true }
freya-engine = { workspace = true }
dioxus-native-core = { workspace = true }
rustc-hash= { workspace = true }

uuid = { workspace = true }
34 changes: 34 additions & 0 deletions crates/common/src/layers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use dioxus_native_core::NodeId;
use rustc_hash::FxHashMap;
use std::sync::{Arc, Mutex, MutexGuard};

#[derive(Default, Clone)]
pub struct Layers {
pub layers: Arc<Mutex<FxHashMap<i16, Vec<NodeId>>>>,
}

impl Layers {
pub fn insert_node_in_layer(&self, node_id: NodeId, layer_n: i16) {
let mut layers = self.layers.lock().unwrap();
let layer = layers.entry(layer_n).or_default();
layer.push(node_id);
}

pub fn remove_node_from_layer(&self, node_id: NodeId, layer_n: i16) {
let mut layers = self.layers.lock().unwrap();
let layer = layers.get_mut(&layer_n).unwrap();
layer.retain(|id| *id != node_id);

if layer.is_empty() {
layers.remove(&layer_n);
}
}

pub fn layers(&self) -> MutexGuard<FxHashMap<i16, Vec<NodeId>>> {
self.layers.lock().unwrap()
}

pub fn len_layers(&self) -> usize {
self.layers.lock().unwrap().len()
}
}
11 changes: 11 additions & 0 deletions crates/common/src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use freya_engine::prelude::Paragraph;
use std::ops::Div;
use torin::geometry::{Area, Size2D};

Expand All @@ -21,3 +22,13 @@ pub enum CursorLayoutResponse {
CursorPosition { position: usize, id: usize },
TextSelection { from: usize, to: usize, id: usize },
}

pub struct CachedParagraph(pub Paragraph);

/// # Safety
/// Skia `Paragraph` are neither Sync or Send, but in order to store them in the Associated
/// data of the Nodes in Torin (which will be used across threads when making the attributes diffing),
/// we must manually mark the Paragraph as Send and Sync, this is fine because `Paragraph`s will only be accessed and modified
/// In the main thread when measuring the layout and painting.
unsafe impl Send for CachedParagraph {}
unsafe impl Sync for CachedParagraph {}
4 changes: 4 additions & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
mod event_messages;
mod layers;
mod layout;
mod paragraphs;

pub use event_messages::*;
pub use layers::*;
pub use layout::*;
pub use paragraphs::*;
39 changes: 39 additions & 0 deletions crates/common/src/paragraphs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use dioxus_native_core::NodeId;
use rustc_hash::FxHashMap;
use std::sync::{Arc, Mutex, MutexGuard};
use uuid::Uuid;

#[derive(Default, Clone)]
pub struct ParagraphElements {
pub paragraphs: Arc<Mutex<FxHashMap<Uuid, Vec<NodeId>>>>,
}

impl ParagraphElements {
pub fn insert_paragraph(&self, node_id: NodeId, text_id: Uuid) {
let mut paragraphs = self.paragraphs.lock().unwrap();
let text_group = paragraphs.entry(text_id).or_default();

text_group.push(node_id);
}

pub fn paragraphs(&self) -> MutexGuard<FxHashMap<Uuid, Vec<NodeId>>> {
self.paragraphs.lock().unwrap()
}

pub fn remove_paragraph(&self, node_id: NodeId, text_id: &Uuid) {
let mut paragraphs = self.paragraphs.lock().unwrap();
let text_group = paragraphs.get_mut(text_id);

if let Some(text_group) = text_group {
text_group.retain(|id| *id != node_id);

if text_group.is_empty() {
paragraphs.remove(text_id);
}
}
}

pub fn len_paragraphs(&self) -> usize {
self.paragraphs.lock().unwrap().len()
}
}
6 changes: 3 additions & 3 deletions crates/components/src/accordion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn Accordion(props: AccordionProps) -> Element {
let mut status = use_signal(AccordionStatus::default);
let platform = use_platform();

let animation_value = animation.read().get().read().as_f32();
let animation_value = animation.get().read().as_f32();
let AccordionTheme {
background,
color,
Expand All @@ -59,9 +59,9 @@ pub fn Accordion(props: AccordionProps) -> Element {
let onclick = move |_: MouseEvent| {
open.toggle();
if *open.read() {
animation.read().start();
animation.start();
} else {
animation.read().reverse();
animation.reverse();
}
};

Expand Down
22 changes: 22 additions & 0 deletions crates/components/src/activable_route.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use dioxus::prelude::*;
use dioxus_router::{hooks::use_route, prelude::Routable};
use freya_hooks::ActivableRouteContext;

#[allow(non_snake_case)]
#[component]
pub fn ActivableRoute<T: Clone + PartialEq + Routable + 'static>(
children: Element,
route: T,
) -> Element {
let current_route = use_route::<T>();
let is_active = current_route == route;
let mut ctx = use_context_provider::<ActivableRouteContext>(|| {
ActivableRouteContext(Signal::new(is_active))
});

if *ctx.0.read() != is_active {
*ctx.0.write() = is_active;
}

rsx!({ children })
}
4 changes: 4 additions & 0 deletions crates/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! A collection of basic components to be used in Freya.

mod accordion;
mod activable_route;
mod body;
mod button;
mod canvas;
Expand All @@ -16,6 +17,7 @@ mod input;
mod link;
mod loader;
mod menu;
mod native_router;
mod network_image;
mod popup;
mod progress_bar;
Expand All @@ -31,6 +33,7 @@ mod tile;
mod tooltip;

pub use accordion::*;
pub use activable_route::*;
pub use body::*;
pub use button::*;
pub use canvas::*;
Expand All @@ -45,6 +48,7 @@ pub use input::*;
pub use link::*;
pub use loader::*;
pub use menu::*;
pub use native_router::*;
pub use network_image::*;
pub use popup::*;
pub use progress_bar::*;
Expand Down
7 changes: 5 additions & 2 deletions crates/components/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use dioxus::prelude::*;
use freya_elements::elements as dioxus_elements;
use freya_hooks::{use_animation, use_applied_theme, AnimNum, LoaderTheme, LoaderThemeWith};
use freya_hooks::{
use_animation, use_applied_theme, AnimNum, LoaderTheme, LoaderThemeWith, OnFinish,
};

/// [`Loader`] component properties.
#[derive(Props, Clone, PartialEq)]
Expand All @@ -22,12 +24,13 @@ pub fn Loader(props: LoaderProps) -> Element {
let theme = use_applied_theme!(&props.theme, loader);
let anim = use_animation(|ctx| {
ctx.auto_start(true);
ctx.on_finish(OnFinish::Restart);
ctx.with(AnimNum::new(0.0, 360.0).time(650))
});

let LoaderTheme { primary_color } = theme;

let degrees = anim.read().get().read().as_f32();
let degrees = anim.get().read().as_f32();

rsx!(svg {
rotate: "{degrees}deg",
Expand Down
4 changes: 2 additions & 2 deletions crates/components/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ pub enum MenuItemStatus {
}

/// `MenuItem` component.
///
///
/// # Styling
/// Inherits the [`MenuItemTheme`](freya_hooks::MenuItemTheme) theme.
///
///
#[allow(non_snake_case)]
#[component]
pub fn MenuItem(
Expand Down
Loading

0 comments on commit 55f6046

Please sign in to comment.