DEV Community

Cover image for Testing Freya - Rust desktop GUI
artydev
artydev

Posted on

Testing Freya - Rust desktop GUI

I runned the demo from Freya's site on WSL and intalled a X11 server on windows with the followings settings in WSL:

python:/tmp/demo/freya$ export DISPLAY=:0
python:/tmp/demo/freya$ unset WAYLAND_DISPLAY
python:/tmp/demo/freya$ export QT_QPA_PLATFORM=xcb
pytho:/tmp/demo/freya$ cargo run

file: Cargo.toml

[package]
name = "counter"
version = "1.0.0"
edition = "2026"

[dependencies]
freya = "0.4.0"
Enter fullscreen mode Exit fullscreen mode

file: main.rs

use freya::prelude::*;

fn main() {
    launch(LaunchConfig::new().with_window(WindowConfig::new(app)));
}



fn app() -> impl IntoElement {
    let mut count = use_state(|| 4);

    let counter = rect()
        .width(Size::fill())
        .height(Size::percent(50.))
        .center()
        .color((255, 255, 255))
        .background((15, 163, 242))
        .font_weight(FontWeight::BOLD)
        .font_size(75.)
        .shadow((0., 4., 20., 4., (0, 0, 0, 80)))
        .child(count.read().to_string());

    let actions = rect()
        .horizontal()
        .width(Size::fill())
        .height(Size::percent(50.))
        .center()
        .spacing(8.0)
        .child(
            Button::new()
                .on_press(move |_| {
                    *count.write() += 1;
                })
                .child("Increase"),
        )
        .child(
            Button::new()
                .on_press(move |_| {
                    *count.write() -= 1;
                })
                .child("Decrease"),
        );

    rect().child(counter).child(actions)
}
Enter fullscreen mode Exit fullscreen mode

Here is the result :

Top comments (0)