Expand description
cpux is a retained-mode GUI framework. It is meant to be simple to use and lightweight, using very little CPU when idle.
§Example
It might seem a bit complex, but the crate is quite well documented
use cpux::app::{App, AppContext};
use cpux::button::Button;
use cpux::layouts::Column;
use cpux::text::Text;
use cpux::load_font;
fn main() {
let font = load_font("assets/arial.ttf");
let mut app = App::new("cpux counter example", 600, 400);
let mut counter = 0;
let text1 = Text::new("Hello, GUI!", font.clone()).with_size(32.0);
let text2 = Text::new("Count: 0", font.clone())
.with_id("counter_text");
let button = Button::new("Click Me", font.clone())
.with_id("add_button");
let column = Column::new()
.at(50, 50)
.with_spacing(25)
.add(text1)
.add(text2)
.add(button);
app.set_root(column);
app.run(move |ui: &mut AppContext| {
if ui.was_clicked("add_button") {
counter += 1;
if let Some(text_widget) = ui.find_widget_mut::<Text>("counter_text") {
text_widget.content = format!("Count: {}", counter);
}
}
});
}Modules§
- app
- Core of the GUI framework
- button
- A simple button widget
- layouts
- Contains the
RowandColumnlayout containers, which are used to arrange child widgets in a horizontal or vertical line, respectively. - text
- A simple text label widget for displaying text on the screen.
- widget
- Core widget trait, implemented by layouts and widgets.
Functions§
- load_
font - Helper utility to load raw TrueType Font (
.ttf) files into vector memory.