Getting Started with Freya
Welcome to the first tutorial in my Rust Freya series! In this tutorial, I’ll show you how to set up your development environment and create your first Freya application.
Prerequisites
Before starting, make sure you have:
- Rust installed (latest stable version)
- A code editor (VS Code recommended)
- Basic familiarity with Rust
Setting Up a New Freya Project
Create a new Freya project from scratch.
cargo new my-freya-app
cd my-freya-app
You can add Freya to your Cargo.toml in two ways:
Option 1: Using Crates.io (Standard)
For most users, simply adding the version from Crates.io is sufficient:
[dependencies]
freya = "0.4"
Option 2: Local Development Setup (Recommended for Contributors)
If you want to modify Freya itself or explore the source code easily, I recommend cloning the repo locally. This allows for smooth code navigation (Go to Definition) directly into Freya’s source.
-
Clone Freya next to your project:
git clone https://github.com/marc2332/freya.git -
Update your
Cargo.tomlto point to the local workspace:[dependencies] # Point to the local version freya = { path = "../freya", features = ["devtools", "router"] } freya-router = { path = "../freya/crates/router" }
[!TIP] Why use a local clone?
Setting up a local path dependency makes it incredibly easy to inspect how specific components work. You can Ctrl+Click (or Cmd+Click) on any Freya function in your IDE to jump straight to its implementation. This is exactly how I established the setup for
UtilitiesPro.
Your First Freya App
Here’s a simple “Hello, World!” example:
use freya::prelude::*;
fn main() {
launch(LaunchConfig::builder()
.with_window(
WindowConfig::builder()
.with_title("My App")
.with_size(800.0, 600.0)
.build()
)
.build());
}
fn app() -> impl IntoElement {
rect()
.width(Size::fill())
.height(Size::fill())
.background(Color::from_rgb(30, 30, 30))
.padding(20.0)
.child(
label()
.font_size(24.0)
.color(Color::WHITE)
.text("Hello, Freya!")
)
}
Run it with:
cargo run
What’s Next
In the next tutorial, I’ll explore Freya’s basic components and how to compose them into more complex UIs.
Summary
- Set up a new Rust project with Freya dependency
- Created a basic “Hello, World!” app
- Learned about
rect()andlabel()builders for UI definition