Skip to main content

simple/
simple.rs

1use floui::{enums::*, prelude::*, widgets::*};
2use std::cell::RefCell;
3use std::rc::Rc;
4
5fn mygui(vc: &ViewController) -> MainView {
6    let count = Rc::from(RefCell::from(0));
7    MainView::new(
8        &vc,
9        &[
10            &Button::new("Increment").foreground(Color::Blue).action({
11                let count = count.clone();
12                move |_| {
13                    log("Increment clicked");
14                    let mut c = count.borrow_mut();
15                    *c += 1;
16                    let t: Text = from_id("mytext").unwrap();
17                    t.text(&format!("{}", c));
18                }
19            }),
20            &Text::new("0").id("mytext").center().bold(),
21            &Button::new("Decrement")
22                .foreground(Color::Red)
23                .action(move |_| {
24                    log("Decrement clicked");
25                    let mut c = count.borrow_mut();
26                    *c -= 1;
27                    let t: Text = from_id("mytext").unwrap();
28                    t.text(&format!("{}", c));
29                }),
30        ],
31    )
32}
33
34use std::os::raw::c_void;
35
36#[no_mangle]
37extern "C" fn floui_main(arg1: *mut c_void, arg2: *mut c_void, arg3: *mut c_void) -> *mut c_void {
38    let vc = unsafe { ViewController::new(arg1, arg2, arg3) };
39    mygui(&vc).underlying() as _
40}
41
42#[no_mangle]
43extern "C" fn floui_handle_events(arg1: *mut c_void) {
44    unsafe { ViewController::handle_events(arg1); }
45}
46
47fn main() {}