Skip to content

Commit

Permalink
feat: Prepare New Docs (#788)
Browse files Browse the repository at this point in the history
* feat: New book

* more

* more

* chore: wip async

* comps, hooks and  animation, wip

* router docs

* chore: Some notes about hooks and components

* chore: i18n and themes

* more

* clean up

* more docs

* clean up

* more

* tweaks

* more docs

* more docs

* clean up

* text input guide

* typo 'dynamically'

* rephrase native_router.md

* start moving book to rustdoc

* improvements

* revert book

* clean up

* clean up

* clean up

* clean up

* clean up

* clean up

* clean up

* clean up

* clean up

* clean up

* clean up

* fixes

* clean up

* add dioxus i18n to workspace crate
  • Loading branch information
marc2332 authored Dec 23, 2024
1 parent 10673cc commit 5c25de6
Show file tree
Hide file tree
Showing 39 changed files with 1,429 additions and 232 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
prefix-key: "3"

- name: cargo doc
run: cargo doc --no-deps --workspace
run: cargo doc --no-deps --workspace --features docs

- name: Upload to Deno Deploy
uses: denoland/deployctl@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
if: runner.os != 'Linux'
run: cargo nextest run --workspace --exclude examples
- name: Run doctests
run: cargo test --workspace --doc
run: cargo test --workspace --doc --features docs
- name: Run coverage
if: runner.os == 'Linux'
run: |
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ custom-tokio-rt = ["freya/custom-tokio-rt"]
performance-overlay = ["freya/performance-overlay"]
fade-cached-incremental-areas = ["freya/fade-cached-incremental-areas"]
disable-zoom-shortcuts = ["freya/disable-zoom-shortcuts"]
docs = ["freya/docs"]

[patch.crates-io]
# dioxus = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
Expand Down Expand Up @@ -52,6 +53,7 @@ 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-clipboard = "0.1"
dioxus-i18n = "0.3"

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

Expand Down Expand Up @@ -84,7 +86,7 @@ freya-core = { workspace = true }
freya-testing = { workspace = true }
reqwest = { version = "0.12.0", features = ["json"] }
serde = "1.0.189"
dioxus-i18n = "0.2"
dioxus-i18n = { workspace = true }
rand = "0.8.5"
dioxus-router = { workspace = true }
itertools = "0.13.0"
Expand Down
4 changes: 1 addition & 3 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Summary

# Introduction

- [Overview](./index.md)
Expand All @@ -14,4 +12,4 @@
# Other
- [Differences with Dioxus](differences_with_dioxus.md)
- [FAQ](./faq.md)
- [Contact](./contact.md)
- [Contact](./contact.md)
24 changes: 12 additions & 12 deletions book/src/guides/devtools.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Devtools

Devtools can be enabled by enabling the `devtools` to Freya.

```toml
// Cargo.toml

[dependencies]
freya = { version = "0.2", features = ["devtools"] }

```

# Devtools

Devtools can be enabled by enabling the `devtools` to Freya.

```toml
// Cargo.toml

[dependencies]
freya = { version = "0.2", features = ["devtools"] }

```

2 changes: 1 addition & 1 deletion crates/components/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Generate a Dioxus component rendering the specified image.
///
/// Example:
/// ### Example
///
/// ```no_run
/// # use freya::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/svg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Generate a Dioxus component rendering the specified SVG.
///
/// Example:
/// ### Example
///
/// ```no_run
/// # use freya::prelude::*;
Expand Down
4 changes: 2 additions & 2 deletions crates/components/src/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum TabStatus {
Hovering,
}

/// Clickable Tab. Usually used in combination with [`Tabsbar`], [`Link`] and [`ActivableRoute`].
/// Clickable Tab. Usually used in combination with [`Tabsbar`], [`crate::Link`] and [`crate::ActivableRoute`].
///
/// # Styling
/// Inherits the [`TabTheme`](freya_hooks::TabTheme) theme.
Expand Down Expand Up @@ -163,7 +163,7 @@ pub fn Tab(
}

/// Clickable BottomTab. Same thing as Tab but designed to be placed in the bottom of your app,
/// usually used in combination with [`Tabsbar`], [`Link`] and [`ActivableRoute`].
/// usually used in combination with [`Tabsbar`], [`crate::Link`] and [`crate::ActivableRoute`].
///
/// # Styling
/// Inherits the [`BottomTabTheme`](freya_hooks::BottomTabTheme) theme.
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/elements/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub trait ElementUtils {

/// Check if this element requires any kind of special caching.
/// Mainly used for text-like elements with shadows.
/// See [crate::compositor::CompositorCache].
/// See [crate::render::CompositorCache].
/// Default to `false`.
#[inline]
fn element_needs_cached_area(&self, _node_ref: &DioxusNode) -> bool {
Expand Down
8 changes: 7 additions & 1 deletion crates/freya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["gui", "ui", "desktop", "skia", "dioxus"]
categories = ["gui", "asynchronous"]

[package.metadata.docs.rs]
features = ["freya-engine/mocked-engine"]
features = ["freya-engine/mocked-engine", "docs"]
no-default-features = true

[features]
Expand All @@ -27,6 +27,7 @@ default = ["skia"]
performance-overlay = []
fade-cached-incremental-areas = ["freya-core/fade-cached-incremental-areas"]
disable-zoom-shortcuts = ["freya-renderer/disable-zoom-shortcuts"]
docs = ["dep:freya-testing", "dep:dioxus-i18n", "dep:dioxus-router"]

[dependencies]
freya-devtools = { workspace = true, optional = true }
Expand All @@ -40,6 +41,11 @@ freya-components = { workspace = true }
freya-engine = { workspace = true }
torin = { workspace = true }


freya-testing = { workspace = true, optional = true }
dioxus-i18n = { workspace = true, optional = true }
dioxus-router = { workspace = true, optional = true }

dioxus = { workspace = true }
dioxus-core-macro = { workspace = true }
dioxus-hooks = { workspace = true }
Expand Down
24 changes: 24 additions & 0 deletions crates/freya/src/_docs/accessibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! # Accessibility
//!
//! TODO
//!
//! ### `use_focus` hook
//!
//! ```rust
//! # use freya::prelude::*;
//! fn app() -> Element {
//! let mut my_focus = use_focus();
//!
//! rsx!(
//! rect {
//! width: "100%",
//! height: "100%",
//! a11y_id: my_focus.attribute(),
//! onclick: move |_| my_focus.focus(),
//! label {
//! "{my_focus.is_focused()}"
//! }
//! }
//! )
//! }
//! ```
33 changes: 33 additions & 0 deletions crates/freya/src/_docs/async_tasks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! # Async
//!
//! You may run asynchronous code through the different APIs Dioxus provide. You can use other libraries such as tokio to spawn tasks but it's not always the recommended approach as these will not work with the lifecycling of the components.
//!
//!
//! ### `spawn`
//!
//! Simple function to spawn an **async task**, this is primarily targeted for custom hooks or when you wanted to run some async code dynamically from an event listener.
//!
//! Important to know: Tasks spawned with `spawn` will be cancelled when the component their were created is dropped. If you want to have an async tasks not attached to the component you may use `spawn_forever`.
//!
//! ```rust
//! # use freya::prelude::*;
//! fn app() -> Element {
//! rsx!(Button {
//! onclick: |_| {
//! if 1 == 1 {
//! spawn(async move {
//! println!("Hello, World fom an async task!");
//! });
//! }
//! }
//! })
//! }
//! ```
//!
//! ### `use_future`
//!
//! TODO
//!
//! ### `use_resource`
//!
//! TODO
105 changes: 105 additions & 0 deletions crates/freya/src/_docs/components_and_props.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//! # Components
//!
//! Freya apps will usually be composed of different components.
//! Components are defined in the form functions that might receive some input as **Props** and return the UI as **Element**.
//!
//! > You can learn more about how the UI is defined in the [UI](./ui.md) chapter.
//!
//! This is how a simple root component looks like:
//!
//! ```rust
//! # use freya::prelude::*;
//! // Usually, the root component of a Freya app is named `app`,
//! // but it is not a requirement
//! fn app() -> Element {
//! rsx!(
//! label {
//! "Hello, World!"
//! }
//! )
//! }
//! ```
//!
//! This is obviously fine, but the moment our app grows in size and complexity we might want to split
//! things out in order to maintain a certain level of modularity and reusability. We can do this by spliting the UI in different components
//!
//! For example, lets create a reusable component:
//!
//! ```rust
//! # use freya::prelude::*;
//! fn app() -> Element {
//! rsx!(
//! // By declaring this element using `TextLabel`
//! // we are creating an instance of that component
//! TextLabel {
//! text: "Number 1"
//! }
//! label {
//! "Number 2"
//! }
//! // Another instance of the same component
//! TextLabel {
//! text: "Number 3"
//! }
//! )
//! }
//!
//! // Reusable component that we might call as many times we want
//! #[component]
//! fn TextLabel(text: String) -> Element {
//! rsx!(
//! label {
//! "{text}"
//! }
//! )
//! }
//! ```
//!
//! Notice how we anotate our `TextLabel` component with the macro `#[component]`, this will transform every argument of the function (just `text: String` in this case) to a component prop, so we can later use the component prop in a declarative way in the RSX.
//!
//! For more complex components you might want to put the props in an external struct intead of using the `#[components]` macro:
//!
//! ```rust
//! # use freya::prelude::*;
//! #[derive(Props, PartialEq, Clone)]
//! struct TextLabelProps {
//! text: String
//! }
//!
//! fn TextLabel(TextLabelProps { text }: TextLabelProps) -> Element {
//! rsx!(
//! label {
//! "{text}"
//! }
//! )
//! }
//! ```
//!
//! ## Renders
//!
//! Components renders are just when a component function runs, which might be because it is subscribed to a signal and that signal got mutated, or because its props changed.
//!
//! > Even though the naming might give you the impression that it means the app will effectively rerender again, it has nothing to do with it, in fact, a component might render a thousand times but it it doesn't generate a new UI Freya will not rerender it.
//!
//! Consider this simple component:
//!
//! ```rust
//! # use freya::prelude::*;
//! #[component]
//! fn CoolComp() -> Element {
//! let mut count = use_signal(|| 0);
//!
//! // 1 run of this function means 1 render of this component
//! // So, everytime the `count` signal is mutated, the component rerenders/is recalled.
//!
//! rsx!(
//! label {
//! // Update the signal value
//! onclick: move |_| count += 1,
//!
//! // By embedding the count in this text the component is subscried to any change in the `count` siganal
//! "Increase {count}"
//! }
//! )
//! }
//! ```
50 changes: 50 additions & 0 deletions crates/freya/src/_docs/development_setup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! # Setup
//!
//! Make sure you have [Rust](https://www.rust-lang.org/) and your OS dependencies installed.
//!
//! ### Windows
//!
//! You will need C++ build tools which you can get through Visual Studio 2022, learn more [here](https://learn.microsoft.com/en-us/windows/dev-environment/rust/setup#install-visual-studio-recommended-or-the-microsoft-c-build-tools).
//!
//! ### Linux
//!
//! #### Debian-based (Ubuntu, PopOS, etc)
//!
//! Install these packages:
//! ```sh
//! sudo apt install build-essential libssl-dev pkg-config cmake libgtk-3-dev libclang-dev
//! ```
//!
//! #### Arch Linux
//!
//! Install these packages:
//! ```sh
//! 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
//! ```
//!
//! #### NixOS
//!
//! Copy this [flake.nix](https://github.com/kuba375/freya-flake) into your project root. Then you can enter a dev shell by `nix develop`.
//!
//! Don't hesitate to contribute so other distros can be added here.
//!
//! ### MacOS
//!
//! No setup required. But feel free to add more if we miss something.
//!
//! ## Custom Linkers
//!
//! 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.
15 changes: 15 additions & 0 deletions crates/freya/src/_docs/dioxus_fundamentals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//!
//! # Dioxus Fundamentals
//!
//! As you should know by now, Freya runs on 🧬 [Dioxus](https://dioxuslabs.com), a renderer-agnostic UI library for Rust.
//!
//! - [UI](crate::_docs::ui)
//! - [Components](crate::_docs::components_and_props)
//! - [Hooks](crate::_docs::hooks)
//! - [State Management](crate::_docs::state_management)
//! - [Signals](crate::_docs::state_management::signals)
//! - [Global Signals](crate::_docs::state_management::global_signals)
//! - [Lifecycle](crate::_docs::state_management::lifecycle)
//! - [Context](crate::_docs::state_management::context)
//! - [Memoization](crate::_docs::state_management::memoization)
//! - [Async Tasks](crate::_docs::async_tasks)
Loading

0 comments on commit 5c25de6

Please sign in to comment.