Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: no_std support for torin #1055

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ accesskit_winit = "0.22.0"
shipyard = { version = "0.6.2", features = ["proc", "std", "parallel"], default-features = false }
smallvec = "1.13.1"

euclid = "0.22.9"
euclid = { version = "0.22.9", default-features = false, features = ["libm"]}
uuid = { version = "1.4.1", features = ["v4"]}
futures-util = "0.3.30"
futures-task = "0.3.30"
Expand Down
31 changes: 27 additions & 4 deletions crates/common/src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
use std::ops::Div;
use std::{
ops::{
Deref,
Div,
},
sync::Arc,
};

use freya_engine::prelude::Paragraph;
use torin::geometry::{
Area,
Size2D,
use freya_native_core::SendAnyMap;
use torin::{
geometry::{
Area,
Size2D,
},
prelude::NodeData,
};

/// Layout info of a certain Node, used by `use_node`.
Expand Down Expand Up @@ -36,3 +46,16 @@ pub struct CachedParagraph(pub Paragraph, pub f32);
/// In the main thread when measuring the layout and painting.
unsafe impl Send for CachedParagraph {}
unsafe impl Sync for CachedParagraph {}

#[derive(Clone)]
pub struct LayoutNodeData(pub Arc<SendAnyMap>);

impl Deref for LayoutNodeData {
type Target = Arc<SendAnyMap>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl NodeData for LayoutNodeData {}
11 changes: 7 additions & 4 deletions crates/core/src/accessibility/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use accesskit::{
Tree,
TreeUpdate,
};
use freya_common::AccessibilityDirtyNodes;
use freya_common::{
AccessibilityDirtyNodes,
LayoutNodeData,
};
use freya_engine::prelude::{
Color,
Slant,
Expand Down Expand Up @@ -81,7 +84,7 @@ impl AccessibilityTree {
pub fn init(
&self,
rdom: &DioxusDOM,
layout: &Torin<NodeId>,
layout: &Torin<NodeId, LayoutNodeData>,
dirty_nodes: &mut AccessibilityDirtyNodes,
) -> TreeUpdate {
dirty_nodes.clear();
Expand Down Expand Up @@ -130,7 +133,7 @@ impl AccessibilityTree {
pub fn process_updates(
&mut self,
rdom: &DioxusDOM,
layout: &Torin<NodeId>,
layout: &Torin<NodeId, LayoutNodeData>,
dirty_nodes: &mut AccessibilityDirtyNodes,
) -> (TreeUpdate, NodeId) {
let requested_focus_id = dirty_nodes.requested_focus.take();
Expand Down Expand Up @@ -326,7 +329,7 @@ impl AccessibilityTree {
/// Create an accessibility node
pub fn create_node(
node_ref: &DioxusNode,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_accessibility: &AccessibilityNodeState,
) -> Node {
let font_style_state = &*node_ref.get::<FontStyleState>().unwrap();
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/dom/doms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use freya_common::{
AccessibilityGenerator,
CompositorDirtyNodes,
Layers,
LayoutNodeData,
ParagraphElements,
};
use freya_native_core::{
Expand Down Expand Up @@ -122,7 +123,7 @@ impl SafeDOM {
pub struct FreyaDOM {
rdom: DioxusDOM,
dioxus_integration_state: DioxusState,
torin: Arc<Mutex<Torin<NodeId>>>,
torin: Arc<Mutex<Torin<NodeId, LayoutNodeData>>>,
paragraphs: Arc<Mutex<ParagraphElements>>,
layers: Arc<Mutex<Layers>>,
compositor_dirty_nodes: Arc<Mutex<CompositorDirtyNodes>>,
Expand Down Expand Up @@ -162,7 +163,7 @@ impl Default for FreyaDOM {
}

impl FreyaDOM {
pub fn layout(&self) -> MutexGuard<Torin<NodeId>> {
pub fn layout(&self) -> MutexGuard<Torin<NodeId, LayoutNodeData>> {
self.torin.lock().unwrap()
}

Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/dom/mutations_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use freya_common::{
AccessibilityDirtyNodes,
CompositorDirtyNodes,
Layers,
LayoutNodeData,
ParagraphElements,
};
use freya_native_core::{
Expand Down Expand Up @@ -36,7 +37,7 @@ use crate::prelude::{

pub struct MutationsWriter<'a> {
pub native_writer: DioxusNativeCoreMutationWriter<'a, CustomAttributeValues>,
pub layout: &'a mut Torin<NodeId>,
pub layout: &'a mut Torin<NodeId, LayoutNodeData>,
pub layers: &'a mut Layers,
pub paragraphs: &'a mut ParagraphElements,
pub scale_factor: f32,
Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/elements/image.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use freya_common::LayoutNodeData;
use freya_engine::prelude::*;
use freya_native_core::real_dom::NodeImmutable;
use freya_node_state::{
Expand All @@ -13,7 +14,7 @@ pub struct ImageElement;
impl ElementUtils for ImageElement {
fn render(
self,
layout_node: &torin::prelude::LayoutNode,
layout_node: &torin::prelude::LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
_font_collection: &mut FontCollection,
Expand Down
9 changes: 6 additions & 3 deletions crates/core/src/elements/label.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use freya_common::CachedParagraph;
use freya_common::{
CachedParagraph,
LayoutNodeData,
};
use freya_engine::prelude::*;
use freya_native_core::prelude::NodeImmutable;
use freya_node_state::FontStyleState;
Expand All @@ -21,7 +24,7 @@ pub struct LabelElement;
impl ElementUtils for LabelElement {
fn render(
self,
layout_node: &torin::prelude::LayoutNode,
layout_node: &torin::prelude::LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
_font_collection: &mut FontCollection,
Expand Down Expand Up @@ -53,7 +56,7 @@ impl ElementUtils for LabelElement {

fn element_drawing_area(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
scale_factor: f32,
) -> Area {
Expand Down
7 changes: 4 additions & 3 deletions crates/core/src/elements/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ops::Mul;
use freya_common::{
CachedParagraph,
CursorLayoutResponse,
LayoutNodeData,
};
use freya_engine::prelude::*;
use freya_native_core::{
Expand Down Expand Up @@ -47,7 +48,7 @@ impl ParagraphElement {
/// Merasure the cursor positio and text selection and notify the subscribed component of the element.
pub fn measure_paragraph(
node: &DioxusNode,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
text_measurement: &TextGroupMeasurement,
scale_factor: f64,
) {
Expand Down Expand Up @@ -115,7 +116,7 @@ impl ParagraphElement {
impl ElementUtils for ParagraphElement {
fn render(
self,
layout_node: &torin::prelude::LayoutNode,
layout_node: &torin::prelude::LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
font_collection: &mut FontCollection,
Expand Down Expand Up @@ -180,7 +181,7 @@ impl ElementUtils for ParagraphElement {

fn element_drawing_area(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
scale_factor: f32,
) -> Area {
Expand Down
11 changes: 6 additions & 5 deletions crates/core/src/elements/rect.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use freya_common::LayoutNodeData;
use freya_engine::prelude::*;
use freya_native_core::real_dom::NodeImmutable;
use freya_node_state::{
Expand Down Expand Up @@ -34,7 +35,7 @@ pub struct RectElement;
impl RectElement {
fn get_rounded_rect(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
scale_factor: f32,
) -> RRect {
Expand All @@ -60,7 +61,7 @@ impl ElementUtils for RectElement {
&self,
point: &CursorPoint,
node_ref: &DioxusNode,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
scale_factor: f32,
) -> bool {
let rounded_rect = self.get_rounded_rect(layout_node, node_ref, scale_factor);
Expand All @@ -70,7 +71,7 @@ impl ElementUtils for RectElement {

fn clip(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
scale_factor: f32,
Expand All @@ -82,7 +83,7 @@ impl ElementUtils for RectElement {

fn render(
self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
font_collection: &mut FontCollection,
Expand Down Expand Up @@ -172,7 +173,7 @@ impl ElementUtils for RectElement {

fn element_drawing_area(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
scale_factor: f32,
) -> Area {
Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/elements/svg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use freya_common::LayoutNodeData;
use freya_engine::prelude::*;
use freya_native_core::real_dom::NodeImmutable;
use freya_node_state::{
Expand All @@ -14,7 +15,7 @@ pub struct SvgElement;
impl ElementUtils for SvgElement {
fn render(
self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
_font_collection: &mut FontCollection,
Expand Down
23 changes: 12 additions & 11 deletions crates/core/src/elements/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use freya_common::LayoutNodeData;
use freya_engine::prelude::{
Canvas,
FontCollection,
Expand Down Expand Up @@ -30,15 +31,15 @@ pub trait ElementUtils {
&self,
point: &CursorPoint,
_node_ref: &DioxusNode,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
_scale_factor: f32,
) -> bool {
layout_node.area.contains(point.to_f32())
}

fn clip(
&self,
_layout_node: &LayoutNode,
_layout_node: &LayoutNode<LayoutNodeData>,
_node_ref: &DioxusNode,
_canvas: &Canvas,
_scale_factor: f32,
Expand All @@ -48,7 +49,7 @@ pub trait ElementUtils {
#[allow(clippy::too_many_arguments)]
fn render(
self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
font_collection: &mut FontCollection,
Expand All @@ -59,7 +60,7 @@ pub trait ElementUtils {

fn element_drawing_area(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
_node_ref: &DioxusNode,
_scale_factor: f32,
) -> Area {
Expand All @@ -69,9 +70,9 @@ pub trait ElementUtils {

fn drawing_area_with_viewports(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
layout: &Torin<NodeId>,
layout: &Torin<NodeId, LayoutNodeData>,
scale_factor: f32,
) -> Option<Area> {
let mut drawing_area = self.drawing_area(layout_node, node_ref, scale_factor);
Expand All @@ -93,7 +94,7 @@ pub trait ElementUtils {
/// factors like shadows or borders, which are not part of the layout.
fn drawing_area(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
scale_factor: f32,
) -> Area {
Expand Down Expand Up @@ -157,7 +158,7 @@ pub enum ElementWithUtils {
impl ElementUtils for ElementWithUtils {
fn clip(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
scale_factor: f32,
Expand All @@ -175,7 +176,7 @@ impl ElementUtils for ElementWithUtils {
&self,
point: &CursorPoint,
node_ref: &DioxusNode,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
scale_factor: f32,
) -> bool {
match self {
Expand All @@ -191,7 +192,7 @@ impl ElementUtils for ElementWithUtils {

fn render(
self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
canvas: &Canvas,
font_collection: &mut FontCollection,
Expand Down Expand Up @@ -250,7 +251,7 @@ impl ElementUtils for ElementWithUtils {

fn drawing_area(
&self,
layout_node: &LayoutNode,
layout_node: &LayoutNode<LayoutNodeData>,
node_ref: &DioxusNode,
scale_factor: f32,
) -> Area {
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/plugins.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use freya_common::LayoutNodeData;
use freya_engine::prelude::{
Canvas,
FontCollection,
Expand Down Expand Up @@ -80,10 +81,10 @@ pub enum PluginEvent<'a> {
},

/// Before starting to measure the layout.
StartedLayout(&'a Torin<NodeId>),
StartedLayout(&'a Torin<NodeId, LayoutNodeData>),

/// After measuring the layout.
FinishedLayout(&'a Torin<NodeId>),
FinishedLayout(&'a Torin<NodeId, LayoutNodeData>),

StartedUpdatingDOM,

Expand Down
Loading
Loading