Skip to content

Commit

Permalink
Merge branch 'main' into feat/support-incremental-rendering-in-use-ca…
Browse files Browse the repository at this point in the history
…mera-hook
  • Loading branch information
marc2332 authored Jan 8, 2025
2 parents 9c224ea + baab869 commit 31bede7
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 11 deletions.
22 changes: 11 additions & 11 deletions book/src/differences_with_dioxus.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# Differences with Dioxus

**Freya** is built on top of the **core** crates from Dioxus, this means that you will effectively be creating Dioxus components, using RSX and hooks.
**Freya** is built on top of the **core** crates from Dioxus. This means that you will effectively be creating Dioxus components using RSX and hooks.

**But**, thanks to Dioxus being a renderer-agnostic library you will **NOT** be using JavaScript, HTML, OR CSS, or any other abstraction that ends up using one of those or anything close to web.
However, thanks to Dioxus being a renderer-agnostic library, you will **NOT** be using JavaScript, HTML, CSS, or any other abstraction that ends up using one of those or other web technologies.

Freya does everything on its own when it comes to:
Freya does everything on its own when it comes to:
- Elements
- Styling
- Layout
- Events
- Rendering
- Testing
- Built-in components and hooks,
- Built-in components and hooks
- Editing
- Animating

And more. Dioxus only is only used to run the app components (hooks, lifecycle, state, rsx), **everything else is managed by Freya**.
...and more. Dioxus is only used for managing app components (hooks, lifecycle, state, RSX), while **everything else is managed by Freya**.

**Freya is not mean to be drop-in alternative to Dioxus renderers but as GUI library on its own.**
**Freya is not meant to be a drop-in alternative to Dioxus renderers but a GUI library on its own.**

Here is the list of the main differences between Freya and the official Dioxus renderers for Desktop (WebView and Blitz):
Below is a comparison of the main differences between Freya and the official Dioxus renderers for Desktop (WebView and Blitz):

| Category | Freya | Dioxus Renderers |
|--------------------------------------|------------------|---------------------------------|
| **Elements, attributes and events** | Custom | HTML |
| **Elements, attributes, and events** | Custom | HTML |
| **Layout** | Custom ([`Torin`](https://github.com/marc2332/freya/tree/main/crates/torin)) | CSS or [`Taffy`](https://github.com/DioxusLabs/taffy) |
| **Styling** | Custom | CSS |
| **Renderer** | Skia | WebView or WGPU |
| **Components library** | Custom ([`freya-comonents`](https://github.com/marc2332/freya/tree/main/crates/components)) | None, but can use HTML elements and CSS libraries |
| **Devtools** | Custom ([`freya-devtools`](https://github.com/marc2332/freya/tree/main/crates/devtools)) | Provided in Webview |
| **Headless testing runner** | Custom ([`freya-testing`](https://github.com/marc2332/freya/tree/main/crates/testing)) | None, but there is Playwright and similar |
| **Components library** | Custom ([`freya-components`](https://github.com/marc2332/freya/tree/main/crates/components)) | None, but can use HTML elements and CSS libraries |
| **Devtools** | Custom ([`freya-devtools`](https://github.com/marc2332/freya/tree/main/crates/devtools)) | Provided in WebView |
| **Headless testing runner** | Custom ([`freya-testing`](https://github.com/marc2332/freya/tree/main/crates/testing)) | None, but tools like Playwright and similar are available |
1 change: 1 addition & 0 deletions crates/torin/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl Node {
|| self.contains_text
|| self.cross_alignment.is_not_start()
|| self.main_alignment.is_not_start()
|| self.content.is_flex()
}

/// Has properties that make its children dependant on it?
Expand Down
103 changes: 103 additions & 0 deletions crates/torin/tests/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,106 @@ pub fn flex_with_inner_percentage() {
Rect::new(Point2D::new(0.0, 150.0), Size2D::new(100.0, 100.0)),
);
}

#[test]
pub fn flex_root_candidate_resolution() {
let (mut layout, mut measurer) = test_utils();

let mut mocked_dom = TestingDOM::default();
mocked_dom.add(
0,
None,
vec![1],
Node::from_size_and_direction(
Size::Pixels(Length::new(200.0)),
Size::Pixels(Length::new(200.0)),
DirectionMode::Vertical,
),
);
mocked_dom.add(
1,
Some(0),
vec![2, 3],
Node::from_size_and_content(
Size::Pixels(Length::new(200.0)),
Size::Pixels(Length::new(200.0)),
Content::Flex,
),
);
mocked_dom.add(
2,
Some(1),
vec![],
Node::from_size_and_direction(
Size::Pixels(Length::new(100.0)),
Size::Flex(Length::new(1.0)),
DirectionMode::Vertical,
),
);
mocked_dom.add(
3,
Some(1),
vec![],
Node::from_size_and_direction(
Size::Pixels(Length::new(100.0)),
Size::Flex(Length::new(1.0)),
DirectionMode::Vertical,
),
);

layout.measure(
0,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(1000.0, 1000.0)),
&mut measurer,
&mut mocked_dom,
);

assert_eq!(
layout.get(0).unwrap().area,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(200.0, 200.0)),
);

assert_eq!(
layout.get(1).unwrap().area,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(200.0, 200.0)),
);
assert_eq!(
layout.get(2).unwrap().area,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(100.0, 100.0)),
);
assert_eq!(
layout.get(3).unwrap().area.round(),
Rect::new(Point2D::new(0.0, 100.0), Size2D::new(100.0, 100.0)),
);

mocked_dom.set_node(
2,
Node::from_size_and_direction(
Size::Pixels(Length::new(100.0)),
Size::Flex(Length::new(3.0)),
DirectionMode::Vertical,
),
);
layout.invalidate(2);

layout.find_best_root(&mut mocked_dom);

// It is Node 1 because it has a `flex` content
assert_eq!(layout.get_root_candidate(), RootNodeCandidate::Valid(1));

layout.measure(
0,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(1000.0, 1000.0)),
&mut measurer,
&mut mocked_dom,
);

assert_eq!(
layout.get(2).unwrap().area,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(100.0, 150.0)),
);
assert_eq!(
layout.get(3).unwrap().area.round(),
Rect::new(Point2D::new(0.0, 150.0), Size2D::new(100.0, 50.0)),
);
}

0 comments on commit 31bede7

Please sign in to comment.