basic/
basic.rs

1#![allow(dead_code, unused_imports, unused_variables)]
2
3use pg_sdl::prelude::*;
4use pg_sdl::widgets::text_input::TextInput;
5use pg_sdl::widgets::Widgets;
6use pg_sdl::{get_button, get_button_mut, get_widget};
7use std::collections::HashMap;
8
9pub struct MyApp;
10
11impl App for MyApp {
12    fn update(&mut self, delta: f32, input: &Input, widgets: &mut Widgets) -> bool {
13        if get_button!(widgets, "button").state.is_pressed() {
14            println!("Button pressed !");
15        }
16        false
17    }
18
19    fn draw(&mut self, canvas: &mut Canvas<Window>, text_drawer: &mut TextDrawer) {
20        canvas.set_draw_color(Colors::VIOLET);
21        draw_circle(canvas, point!(500, 400), 100, 20);
22
23        canvas.set_draw_color(Colors::LIGHT_RED);
24        let width: u32 = 20;
25        let rect = rect!(650, 350, 150, 100);
26        let rects = (0..width)
27            .map(|i| {
28                rect!(
29                    rect.x as u32 + i,
30                    rect.y as u32 + i,
31                    rect.width() - 2 * i,
32                    rect.height() - 2 * i
33                )
34            })
35            .collect::<Vec<Rect>>();
36        canvas.draw_rects(&rects).unwrap();
37
38        canvas.set_draw_color(Colors::BLACK);
39        let center = point!(500, 400);
40    }
41}
42
43fn main() {
44    let mut my_app = MyApp;
45
46    let mut pd_sdl: PgSdl = PgSdl::init("Benday", 1200, 720, Some(60), true, Colors::SKY_BLUE);
47
48    pd_sdl
49        .add_widget(
50            "button",
51            Box::new(Button::new(
52                Colors::ROYAL_BLUE,
53                rect!(500, 500, 200, 100),
54                Some(9),
55                Some(Text::new("Auto !".to_string(), 16, None)),
56            )),
57        )
58        .add_widget(
59            "slider",
60            Box::new(Slider::new(
61                Colors::ROYAL_BLUE,
62                rect!(110, 220, 200, 100),
63                Some(9),
64                SliderType::Continuous {
65                    display: None,
66                    default_value: 0.5,
67                },
68            )),
69        )
70        .add_widget(
71            "text input",
72            Box::new(TextInput::new(
73                Colors::WHITE,
74                rect!(222, 295, 200, 100),
75                Some(9),
76                Some(Text::new("Auto !".to_string(), 16, None)),
77            )),
78        );
79
80    pd_sdl.run(&mut my_app);
81}