Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Sep 22, 2024
2 parents c633144 + 90f2bfb commit c27cf63
Show file tree
Hide file tree
Showing 257 changed files with 12,114 additions and 5,161 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @marc2332
2 changes: 2 additions & 0 deletions .github/workflows/deploy_book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v2
with:
mdbook-version: '0.4.32'

- run: mdbook build
working-directory: book
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.80.1"
- name: Install linux dependencies
if: runner.os == 'Linux'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt update && sudo apt install build-essential libssl-dev pkg-config libglib2.0-dev libgtk-3-dev
sudo apt update && sudo apt install build-essential libssl-dev pkg-config libglib2.0-dev libgtk-3-dev libudev-dev
- name: Check examples
run: cargo check --examples
- name: Lint
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ target
Cargo.lock
.idea
snapshot_before.png
snapshot_after.png
snapshot_after.png
documents_example
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"rust-analyzer.cargo.features": [
"devtools",
"log",
"use_camera"
"tracing-subscriber",
"use_camera",
"fade-cached-incremental-areas"
]
}
}
13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ members = [
]

[features]
log = ["freya/log"]
tracing-subscriber = ["freya/tracing-subscriber"]
devtools = ["freya/devtools"]
use_camera = ["freya/use_camera"]
hot-reload = ["freya/hot-reload"]
custom-tokio-rt = ["freya/custom-tokio-rt"]
performance-overlay = ["freya/performance-overlay"]
fade-cached-incremental-areas = ["freya/fade-cached-incremental-areas"]

[patch.crates-io]
# dioxus = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
Expand Down Expand Up @@ -111,12 +114,18 @@ freya-core = { workspace = true }
freya-testing = { workspace = true }
reqwest = { version = "0.12.0", features = ["json"] }
serde = "1.0.189"
dioxus-sdk = { version = "0.5", features = ["i18n"] }
dioxus-i18n = "0.2"
rand = "0.8.5"
dioxus-router = { workspace = true }
itertools = "0.13.0"
home = "0.5.9"
dioxus-query = "0.5.1"
gilrs = "0.10.8"
gl = { workspace = true }
tree-sitter-highlight = "0.23.0"
tree-sitter-rust = "0.23.0"
rfd = "0.14.1"
bytes = "1.5.0"

[profile.release]
lto = true
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

**Freya** is a cross-paltform GUI library for Rust powered by 🧬 [Dioxus](https://dioxuslabs.com) and 🎨 [Skia](https://skia.org/).

**It does not use any web tech**, check the [Differences with Dioxus](https://book.freyaui.dev/differences_with_dioxus.html).

⚠️ It's currently work in progress, but you can already play with it! You can join the [Discord](https://discord.gg/sYejxCdewG) server if you have any question or issue.

<br/>
Expand All @@ -19,7 +21,7 @@
<tr>
<td style="border:hidden;">

```rust, no_run
```rust
fn app() -> Element {
let mut count = use_signal(|| 0);

Expand Down Expand Up @@ -68,11 +70,13 @@ fn app() -> Element {

Thanks to my sponsors for supporting this project! 😄

<!-- sponsors --><a href="https://github.com/piny4man"><img src="https://github.com/piny4man.png" width="60px" alt="Alberto" /></a><!-- sponsors -->
<!-- sponsors --><a href="https://github.com/piny4man"><img src="https:&#x2F;&#x2F;avatars.githubusercontent.com&#x2F;u&#x2F;8446285?u&#x3D;fd37db4dd9b4ba94dabe0bccc3a95ef2a35376ab&amp;v&#x3D;4" width="60px" alt="" /></a><!-- sponsors -->

### Want to try it? 🤔

⚠️ First, see [Setup guide](https://book.freyaui.dev/setup.html).
👋 Make sure to check the [Setup guide](https://book.freyaui.dev/setup.html) first.

> ⚠️ If you happen to be on Windows using `windows-gnu` and get compile errors, maybe go check this [issue](https://github.com/marc2332/freya/issues/794).
Clone this repo and run:

Expand Down
33 changes: 25 additions & 8 deletions book/src/differences_with_dioxus.md
Original file line number Diff line number Diff line change
@@ -1,15 +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. But, you will **not** be using HTML, CSS, JS or any Web tech at all.
**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.

Here you can find a list of the main differences between Freya and the official Dioxus renderers for Desktop (WebView and Blitz):
**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.

Freya does everything on its own when it comes to:
- Elements
- Styling
- Layout
- Events
- Rendering
- Testing
- 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**.

**Freya is not mean to be drop-in alternative to Dioxus renderers but as 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):

| Category | Freya | Dioxus Renderers |
|--------------------------------------|------------------|---------------------------------|
| **Elements, attributes and events** | Custom | HTML |
| **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 HTML elements and CSS libraries |
| **Devtools** | Custom | Provided in Webview |
| **Headless testing runner** | Custom | None, but there is Playwright and similar |
| **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 |
11 changes: 10 additions & 1 deletion book/src/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ Install these packages:
sudo pacman -S base-devel openssl cmake gtk3 clang
```

#### Fedora

Install these packages:

```sh
sudo dnf install openssl-devel pkgconf cmake gtk3-devel clang-devel -y
sudo dnf groupinstall "Development Tools" "C Development Tools and Libraries" -y
```

Don't hesitate to contribute so other distros can be added here.

### MacOS
Expand All @@ -34,4 +43,4 @@ The following custom linkers are not supported at the moment:

- `mold`

If there is another one not supported don't hesitate to add it here.
If there is another one not supported don't hesitate to add it here.
9 changes: 8 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ torin = { workspace = true }
dioxus-core = { workspace = true }

accesskit = { workspace = true }
accesskit_winit = { workspace = true }
winit = { workspace = true }
freya-engine = { workspace = true }
freya-native-core = { workspace = true }
rustc-hash= { workspace = true }

itertools = "0.13.0"
uuid = { workspace = true }


[dev-dependencies]
dioxus = { workspace = true }
freya = { path = "../freya" }
freya-testing = { path = "../testing" }
tokio = { workspace = true }
55 changes: 55 additions & 0 deletions crates/common/src/accessibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::sync::atomic::{
AtomicU64,
Ordering,
};

use freya_native_core::NodeId;
use rustc_hash::{
FxHashMap,
FxHashSet,
};

#[derive(Default)]
pub struct AccessibilityDirtyNodes {
pub requested_focus: Option<NodeId>,
pub added_or_updated: FxHashSet<NodeId>,
pub removed: FxHashMap<NodeId, NodeId>,
}

impl AccessibilityDirtyNodes {
pub fn request_focus(&mut self, node_id: NodeId) {
self.requested_focus = Some(node_id);
}

pub fn add_or_update(&mut self, node_id: NodeId) {
self.added_or_updated.insert(node_id);
}

pub fn remove(&mut self, node_id: NodeId, ancestor_node_id: NodeId) {
self.removed.insert(node_id, ancestor_node_id);
}

pub fn clear(&mut self) {
self.requested_focus.take();
self.added_or_updated.clear();
self.removed.clear();
}
}

pub struct AccessibilityGenerator {
counter: AtomicU64,
}

impl Default for AccessibilityGenerator {
fn default() -> Self {
Self {
counter: AtomicU64::new(1), // Must start at 1 because 0 is reserved for the Root
}
}
}

impl AccessibilityGenerator {
pub fn new_id(&self) -> u64 {
self.counter.fetch_add(1, Ordering::Relaxed)
}
}
31 changes: 31 additions & 0 deletions crates/common/src/compositor_dirty_nodes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::ops::{
Deref,
DerefMut,
};

use freya_native_core::NodeId;
use rustc_hash::FxHashSet;

#[derive(Clone, Default, Debug)]
pub struct CompositorDirtyNodes(FxHashSet<NodeId>);

impl Deref for CompositorDirtyNodes {
type Target = FxHashSet<NodeId>;

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

impl DerefMut for CompositorDirtyNodes {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl CompositorDirtyNodes {
/// Mark a certain node as invalidated.
pub fn invalidate(&mut self, node_id: NodeId) {
self.0.insert(node_id);
}
}
47 changes: 28 additions & 19 deletions crates/common/src/layers.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
use std::sync::{
Arc,
Mutex,
MutexGuard,
use std::{
self,
ops::{
Deref,
DerefMut,
},
};

use freya_native_core::NodeId;
use rustc_hash::FxHashMap;

#[derive(Default, Clone)]
pub struct Layers {
pub layers: Arc<Mutex<FxHashMap<i16, Vec<NodeId>>>>,
}
#[derive(Default, Clone, Debug, PartialEq)]
pub struct Layers(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();
/// Insert the given [NodeId] in the given layer. Will create an entry for the layer if missing.
pub fn insert_node_in_layer(&mut self, node_id: NodeId, layer_n: i16) {
let layer = self.0.entry(layer_n).or_default();
if layer.contains(&node_id) {
return;
}
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();
/// Remove the [NodeId] from the given layer. Will remove the entry of the layer if it becomes empty.
pub fn remove_node_from_layer(&mut self, node_id: NodeId, layer_n: i16) {
let layer = self.0.get_mut(&layer_n).unwrap();
layer.retain(|id| *id != node_id);

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

pub fn layers(&self) -> MutexGuard<FxHashMap<i16, Vec<NodeId>>> {
self.layers.lock().unwrap()
impl Deref for Layers {
type Target = FxHashMap<i16, Vec<NodeId>>;

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

pub fn len_layers(&self) -> usize {
self.layers.lock().unwrap().len()
impl DerefMut for Layers {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
2 changes: 1 addition & 1 deletion crates/common/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum CursorLayoutResponse {
TextSelection { from: usize, to: usize, id: usize },
}

pub struct CachedParagraph(pub Paragraph);
pub struct CachedParagraph(pub Paragraph, pub f32);

/// # Safety
/// Skia `Paragraph` are neither Sync or Send, but in order to store them in the Associated
Expand Down
6 changes: 4 additions & 2 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod event_messages;
mod accessibility;
mod compositor_dirty_nodes;
mod layers;
mod layout;
mod paragraphs;

pub use event_messages::*;
pub use accessibility::*;
pub use compositor_dirty_nodes::*;
pub use layers::*;
pub use layout::*;
pub use paragraphs::*;
Loading

0 comments on commit c27cf63

Please sign in to comment.