counter3/
counter3.rs

1use fltk::{
2    enums::{Align, Color, Font, FrameType},
3    prelude::*,
4    *,
5};
6
7const BLUE: Color = Color::from_hex(0x42A5F5);
8const SEL_BLUE: Color = Color::from_hex(0x3f51b5);
9const GRAY: Color = Color::from_hex(0x757575);
10const WIDTH: i32 = 600;
11const HEIGHT: i32 = 400;
12
13fn main() {
14    let app = app::App::default();
15    let mut win = window::Window::default()
16        .with_size(WIDTH, HEIGHT)
17        .with_label("Flutter-like!");
18    let mut col = group::Flex::default_fill().column();
19    let mut bar = frame::Frame::default()
20        .with_label("  FLTK App!")
21        .with_align(Align::Left | Align::Inside);
22    col.fixed(&bar, 60);
23    let mut text = frame::Frame::default()
24        .with_label("You have pushed the button this many times:")
25        .with_align(Align::Bottom | Align::Inside);
26    let mut count = frame::Frame::default()
27        .with_label("0")
28        .with_align(Align::Top | Align::Inside);
29    let mut row = group::Flex::default();
30    col.fixed(&row, 60);
31    frame::Frame::default();
32    let mut but = button::Button::default().with_label("@+6plus");
33    row.fixed(&but, 60);
34    let spacing = frame::Frame::default();
35    row.fixed(&spacing, 20);
36    row.end();
37    let spacing = frame::Frame::default();
38    col.fixed(&spacing, 20);
39    col.end();
40    win.end();
41    win.make_resizable(true);
42    win.show();
43
44    // Theming
45    app::background(255, 255, 255);
46    app::set_visible_focus(false);
47
48    bar.set_frame(FrameType::FlatBox);
49    bar.set_label_size(22);
50    bar.set_label_color(Color::White);
51    bar.set_color(BLUE);
52    bar.draw(|b| {
53        draw::set_draw_rgb_color(211, 211, 211);
54        draw::draw_rectf(0, b.h(), b.w(), 3);
55    });
56
57    text.set_label_size(18);
58    text.set_label_font(Font::Times);
59
60    count.set_label_size(36);
61    count.set_label_color(GRAY);
62
63    but.set_color(BLUE);
64    but.set_selection_color(SEL_BLUE);
65    but.set_label_color(Color::White);
66    but.set_frame(FrameType::OFlatBox);
67    // End theming
68
69    but.set_callback(move |_| {
70        let label = (count.label().unwrap().parse::<i32>().unwrap() + 1).to_string();
71        count.set_label(&label);
72    });
73
74    app.run().unwrap();
75}