Grokmoo / thyme

Themable Immediate Mode User Interface Toolkit in Rust
Apache License 2.0
96 stars 5 forks source link
gui immediate-gui opengl rust themable ui wgpu

Thyme - Themable Immediate Mode GUI

Crates.io Docs.rs

Thyme is a Graphical User Interface (GUI) library written in pure, safe, Rust. All widgets are rendered using image sources, instead of the line art more commonly used by other Immediate Mode GUIs. The image definitions, fonts, and style attributes are all specified in a unified theme. This is generally drawn from a file, but any Serde compatible source should work. Live Reload is supported for asset files for a more efficient workflow.

A composite image showcasing three different themes: Screenshot

Thyme produces a set of Draw Lists which are sent to a swappable graphics backend - currently Glium and wgpu are supported. The I/O backend is also swappable - although currently only winit is supported. Fonts are rendered to a texture on the GPU using rusttype.

Performance is acceptable or better for most use cases, with the complete cycle of generating the widget tree, creating the draw data, and rendering taking less than 1 ms for quite complex UIs.

Getting Started

Running the examples

The demo contains an example role playing game (RPG) character generator program that uses many of the features of Thyme.

git clone https://github.com/Grokmoo/thyme.git
cd thyme
cargo run --example demo_glium --features glium_backend # Run demo using glium
cargo run --example demo_wgpu --features wgpu_backend # Run demo using wgpu
cargo run --example demo_gl --features gl_backend # Run demo using OpenGL

Run the hello_world example with either Glium or wgpu:

cargo run --example hello_glium --features glium_backend
cargo run --example hello_wgpu --features wgpu_backend

Starting your own project

Add the following to your Cargo.toml file:

[dependencies]
thyme = { version = "0.7", features = ["wgpu_backend"] }

See hello_wgpu or hello_glium for the bare minimum to get started with your preferred renderer. As a starting point, you can copy the data folder into your own project and import the resources there, as in the example.

Documentation

See the docs for the full API reference as well as theme definition format.

Why Thyme?

At its core, Thyme is an immediate mode GUI library similar to other libraries such as Dear ImGui. However, unlike many of those libraries Thyme is focused on extreme customizability and flexibility needed for production applications, especially games.

With Thyme, you can customize exactly how you want your UI to look and operate. Thyme also focuses a great deal on being performant, while still retaining the benefits of a true immediate mode GUI.

This flexibility comes at the cost of needing to specify theme, font, and image files. But, Thyme comes with some such files as examples to help you get started. Separating assets out in this manner can also significantly improve your workflow, especially with Thyme's built in support for live reload. This strikes a balance, enabling very fast iteration on layout and appearance while still keeping your UI logic in compiled Rust code.

This flexibility does come at a cost, of course - There is quite a bit of overhead in getting started compared to similar libraries. Once you get up and running, though, the overhead is fairly minor. Performance is also very good and should be at least on-par with other immediate mode GUIs.

Thyme comes with a library of widgets similar to most UI libraries. However, Thyme's widgets are written entirely using the public API, so the source for these can serve as examples and templates for your own custom widgets.

It is also written from scratch in 100% Rust!

License

Licensed under Apache License, Version 2.0, (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).

Note that some of the sample theme images are licensed under a Creative Commons license, see attribution.

License of contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.