Skip to content

Commit

Permalink
Merge branch 'main' into release/0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Apr 27, 2024
2 parents 6d1bdc7 + 2240155 commit 1081d46
Show file tree
Hide file tree
Showing 219 changed files with 4,635 additions and 4,055 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
uses: peaceiris/actions-mdbook@v2

- run: mdbook build
working-directory: book
Expand Down
45 changes: 20 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "46b0eeb12cf2b388d29a9061b74e9470a8487679" }
dioxus-rsx = { git = "https://github.com/DioxusLabs/dioxus", rev = "46b0eeb12cf2b388d29a9061b74e9470a8487679" }
dioxus-core-macro = { git = "https://github.com/DioxusLabs/dioxus", rev = "46b0eeb12cf2b388d29a9061b74e9470a8487679" }
dioxus-hooks = { git = "https://github.com/DioxusLabs/dioxus", rev = "46b0eeb12cf2b388d29a9061b74e9470a8487679" }
dioxus-signals = { git = "https://github.com/DioxusLabs/dioxus", rev = "46b0eeb12cf2b388d29a9061b74e9470a8487679" }
dioxus-core = { git = "https://github.com/DioxusLabs/dioxus", rev = "46b0eeb12cf2b388d29a9061b74e9470a8487679" }
dioxus-hot-reload = { git = "https://github.com/DioxusLabs/dioxus", rev = "46b0eeb12cf2b388d29a9061b74e9470a8487679" }
dioxus-router = { git = "https://github.com/DioxusLabs/dioxus", rev = "46b0eeb12cf2b388d29a9061b74e9470a8487679" }
# 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.2" }
Expand All @@ -36,18 +36,18 @@ freya-testing = { path = "crates/testing", version = "0.2" }
freya-engine = { path = "crates/engine", version = "0.2" }
torin = { path = "crates/torin", version = "0.2" }

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

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-sdk = { version = "0.5", features = ["clipboard"]}

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

Expand Down Expand Up @@ -78,16 +78,11 @@ freya = { workspace = true }
freya-core = { workspace = true }
reqwest = { version = "0.11.22", features = ["json"] }
serde = "1.0.189"
dioxus-std = { git = "https://github.com/marc2332/dioxus-std", rev = "4d8ae33b94537d54471cd924c32f03c1d949430f", features = ["i18n"] }
dioxus-sdk = { version = "0.5", features = ["i18n"] }
rand = "0.8.5"
dioxus-router = { workspace = true }
itertools = "0.11.0"

[profile.release]
lto = true
opt-level = 3


[target."cfg(target_os = \"linux\")".dependencies.skia-safe]
workspace = true
features = ["gl", "textlayout", "svg", "x11", "wayland"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<td style="border:hidden;">

```rust, no_run
fn app(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
fn app() -> Element {
let mut count = use_signal(|| 0);
render!(
rsx!(
rect {
height: "20%",
width: "100%",
Expand All @@ -50,7 +50,7 @@ fn app(cx: Scope) -> Element {
</td>
<td style="border:hidden;">

![Freya](./demo.png)
![Freya Demo](https://github.com/marc2332/freya/assets/38158676/f81a95a2-7add-4dbe-9820-3d3b6b42f6e5)

</td>
</table>
Expand Down Expand Up @@ -92,7 +92,7 @@ dioxus = { version = "0.4", features = ["macro", "hooks"], default-features = fa
- 🔄️ Dioxus **Hot-reload** support
- 📒 Multi-line **text editing** (experimental ⚠️)
- 🦾 Basic **Accessibility** Support (experimental ⚠️)
- 🧩Compatible with dioxus-std and other Dioxus renderer-agnostic libraries
- 🧩Compatible with dioxus-sdk and other Dioxus renderer-agnostic libraries

### Goals 😁
- Performant and low memory usage
Expand Down
26 changes: 9 additions & 17 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@

# Introduction

- [Welcome](./index.md)
- [What is Freya?](./what_is_freya.md)
- [Differences with Dioxus](differences_with_dioxus.md)
- [Environment Setup](setup.md)
- [Getting started](./guides/getting_started.md)
- [Frequently Asked Questions](./faq.md)
- [Overview](./index.md)
- [Setup](setup.md)
- [Learn Dioxus](./dioxus.md)
- [Getting Started](./getting_started.md)

# Guides
- [Elements](./guides/elements.md)
- [Layout](./guides/layout.md)
- [Style](./guides/style.md)
- [Font Style](./guides/font_style.md)
- [Effects](./guides/effects.md)
- [Components](./guides/components.md)
- [Theming](./guides/theming.md)
- [Hot reload](./guides/hot_reload.md)
- [Testing](./guides/testing.md)
- [Animating](./guides/animating.md)
- [Virtualizing](./guides/virtualizing.md)
- [Devtools](./guides/devtools.md)
- [Publishing](./guides/publishing.md)

# Other
- [Differences with Dioxus](differences_with_dioxus.md)
- [FAQ](./faq.md)
- [Contact](./contact.md)
4 changes: 4 additions & 0 deletions book/src/contact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Contact

- [Discord](https://discord.gg/sYejxCdewG)
- [X](https://twitter.com/mkenzo_8)
11 changes: 6 additions & 5 deletions book/src/differences_with_dioxus.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Differences with Dioxus

**Freya** uses most of the core packages of Dioxus, but not all them.
**Freya** uses some of the core packages of Dioxus, but not all of them.

These are the main differences between Freya and the official Dioxus renderers for Desktop (webview and Blitz):
These are 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 |
| **Layout** | [`Torin`](https://github.com/marc2332/freya/tree/main/crates/torin) | WebView and [`Taffy`](https://github.com/DioxusLabs/taffy) |
| **Layout** | [`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 | None, but can use CSS libraries |
| **Components library** | Custom | None, but can use HTML elements and CSS libraries |
| **Devtools** | Custom | Provided in Webview |
| **Headless testing runner** | Custom | None |
| **Headless testing runner** | Custom | None, but there is Playwright and similar |
185 changes: 185 additions & 0 deletions book/src/dioxus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Learn Dioxus

This is a quick introduction to Dioxus in the world of Freya. For more examples or tips you can check the official [Dioxus Docs](https://dioxuslabs.com/learn/0.5/) or the [Dioxus Cheatsheet](https://github.com/marc2332/dioxus-cheatsheet)

## Components
Components in Dioxus are defined in the form of funtions that might receive some `props` and return an `Element`.

The Element is generated by the `rsx!()` macro.

```rs, no_run
fn MyComponent() -> Element {
rsx!(...)
}
```

## RSX

Dioxus uses a custom markup syntax called RSX, it's conceptually similar to React's JSX.

Syntax:

```rs
<Element Name> {
<Element Attribute Name>: <Element Attribute Value>,
<Element Children>
}
```

Example:

```rs, no_run
rsx!(
label {
onclick: |_| println!("Clicked"),
color: "red",
font_size: "50",
"Hello, World!"
}
)
```

Another Example:

```rs, no_run
rsx!(
rect {
color: "red",
onclick: |_| println!("Clicked rect"),
label {
onclick: |_| println!("Clicked label"),
font_size: "50",
"Hello, World!"
}
AnotherComponent {
some_value: 123
}
}
)
```

## Props

Use the `component` macro if you want to have inlined props:

```rs, no_run
#[component]
fn MyComponent(name: String, age: u8) -> Element {
rsx!(
label {
"{name} is {age} years old."
}
)
}
```

You can as well have a separate Struct for the props:
```rs, no_run
struct MyComponentProps {
name: String,
age: u8
}
fn MyComponent(props: MyComponentProps) -> Element {
rsx!(
label {
"{props.name} is {props.age} years old."
}
)
}
```


## State

Dioxus built-in state management uses **Signals**, and they are usually created with the `use_signal` hook.

```rs, no_run
fn MyComponent() -> Element {
// `use_signal` takes a callback that initializes the state
let mut state = use_signal(|| 0);
// Because signals are copy, we can move them into closures
let onclick = move |_| {
// Signals provide some shortcuts for certain types
state += 1;
// But we could do as well
*state.write() += 1;
};
// You can subscribe to a signal, by calling it (`signal()`),
// calling the `signal.read()` method, or just embedding it into the RSX.
// Everytime the signal is mutated the component function will rerun
// because it has been subscribed, and thus producing a
// new Element with the updated counter.
println!("{}", state());
rsx!(
label {
onclick,
"State is {value}"
}
)
}
```

## Shared State

Signals can be passed to other components so they can read/write to the same signal.


```rs, no_run
fn app() -> Element {
let state = use_signal(|| 0);
// We pass the signal through the context API
// So `ThirdComponent` can consume
use_context_provider(|| state);
rsx!(
SecondComponent {
state // We can pass the signal as a prop as well
}
ThirdComponent {}
)
}
#[component]
fn SecondComponent(mut state: Signal<usize>) -> Element {
let onclick = move |_| {
state += 1;
};
rsx!(
label {
onclick,
"Second component: {state}"
}
)
}
#[component]
fn ThirdComponent() -> Element {
// We consume the signal passed through `use_context_provider`
let mut state = use_context::<Signal<usize>>();
let onclick = move |_| {
state += 1;
};
rsx!(
label {
onclick,
"Third component: {state}"
}
)
}
```

## Alternative State Management

There are other state management libraries with more granular control or with other goals that are worth checking out.

- [`dioxus-radio`](https://github.com/dioxus-community/dioxus-radio)
- [`dioxus-query`](https://github.com/marc2332/dioxus-query)
10 changes: 5 additions & 5 deletions book/src/faq.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Frequently Asked Questions

## Will Freya have Mobile/Web support?
Freya current focus is on Desktop (Windows, Linux, MacOS), so there is no plans for either Mobile (Android/iOS) or Web support. But, this doesn't mean it won't happen in the future, who knows! From a technical point of view, it is possible to run Freya on these platforms with the right adjustements.
Freya's current focus is on Desktop (Windows, Linux, MacOS), so there are currently no plans to support either Mobile (Android/iOS) or Web platforms. But, this doesn't mean it won't happen in the future, who knows! From a technical point of view, it is possible to run Freya on these platforms with the right adjustments.

## Why Skia instead of Webview?
## Why choose Skia instead of Webview?
These are the main reasons for this:
- Ability to define the elements, attributes, styling, layout and events to my own criteria
- Apps UI look the same no matter the platform
- Because Freya has control over all the the pipeline it is easier to implement and use certain features such as headless testing runner
- Not relying on OS for new features or fixes
- App UIs look the same across platforms
- Because Freya has control over the entire pipeline, it is easier to implement and use certain features such as headless testing runners
- No reliance on OS for new features or fixes
Loading

0 comments on commit 1081d46

Please sign in to comment.