Skip to content
forked from vizia/vizia

A declarative GUI library written in Rust

License

Notifications You must be signed in to change notification settings

robbert-vdh/vizia

 
 

Repository files navigation

Vizia


A declarative desktop GUI framework for the Rust programming language.



Features

  • Cross-platform (Windows, Linux, MacOS)

    Build desktop applications which look and behave the same for Windows, Mac, and Linux.
  • Declarative

    Write GUI code in a declarative way in pure Rust (no DSL macros).
  • Reactive

    Views derive from application state. Change the state and the views which bind to it update automatically.
  • Flexible layout

    Create flexible layouts which adapt to changes in size. Powered by morphorm.
  • Powerful styling

    Take advantage of CSS with hot-reloading to fully customize the style of your application.
  • Animations

    Bring your application to life with animatable style properties.
  • Built-in views and themes

    Utilize over 25 ready-made views as well as two built-in themes (light and dark) to get you started. Includes 4250+ icons, provided by Tabler Icons.
  • Accessibility

    Make you applications accessible to assistive technologies such as screen readers, powered by accesskit.
  • Localization

    Adapt your application to different locales, including translating text with fluent.
  • GPU accelerated rendering

    Vizia leverages the GPU for fast graphical updates, powered by femtovg.
  • Audio plugin development

    Vizia provides an alternative baseview windowing backend for audio plugin development, for example with the nih-plug framework.

At a Glance

A simple counter application. Run with cargo run --example counter.

use vizia::prelude::*;

// Define some model data
#[derive(Lens)]
pub struct AppData {
    count: i32,
}

// Define events to mutate the data
pub enum AppEvent {
    Increment,
}

// Describe how the data is mutated in response to events
impl Model for AppData {
    fn event(&mut self, _: &mut EventContext, event: &mut Event) {
        event.map(|app_event, _| match app_event {
            AppEvent::Increment => {
                self.count += 1;
            }
        });
    }
}

fn main() {
    // Create an application
    Application::new(|cx| {

        // Build the model data into the tree
        AppData { count: 0 }.build(cx);

        // Declare views which make up the UI
        HStack::new(cx, |cx| {
          
            // Declare a button which emits an event
            Button::new(cx, |cx| cx.emit(AppEvent::Increment), |cx| Label::new(cx, "Increment"));

            // Declare a label which is bound to part of the model, updating when it changes
            Label::new(cx, AppData::count).width(Pixels(50.0));
        })
        .child_space(Stretch(1.0))  // Apply style and layout modifiers
        .col_between(Pixels(50.0));
    })
    .title("Counter") // Configure window peoperties
    .inner_size((400, 100))
    .run();
}

Learning

Book

A quickstart guide for vizia is available here.

Docs

Auto-generated code documentation can be found here.

Examples

A list of examples is included in the repository.

To run an example with the winit (default) windowing backend:

cargo run --release --example name_of_example

Baseview

To run an example with the baseview windowing backend:

cargo run --release --example name_of_example --no-default-features --features baseview

Web

To run an example as a web application, first ensure that the wasm32-unknown-unknown toolchain is installed:

rustup target add wasm32-unknown-unknown

Then run an example with the following:

cargo run-wasm --release --example name_of_example

Note Some examples are not compatible with the web target and will intentionally panic if run on web.

Contributing and Community

For help with vizia, or to get involved with contributing to the project, come join us on our discord.

License and Attribution

Vizia is licensed under MIT.

Vizia logo designed by Lunae Somnia.

About

A declarative GUI library written in Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 97.5%
  • CSS 2.5%