Function draw_point

Source
pub fn draw_point(x: i32, y: i32)
Expand description

Draws a point

Examples found in repository?
examples/paint.rs (line 58)
20    pub fn new(w: i32, h: i32) -> Self {
21        let mut frame = Frame::default().with_size(w, h).center_of_parent();
22        frame.set_color(Color::White);
23        frame.set_frame(FrameType::DownBox);
24
25        let surf = ImageSurface::new(frame.w(), frame.h(), false);
26        ImageSurface::push_current(&surf);
27        draw_rect_fill(0, 0, w, h, Color::White);
28        ImageSurface::pop_current();
29
30        let surf = Rc::from(RefCell::from(surf));
31
32        frame.draw({
33            let surf = surf.clone();
34            move |f| {
35                let surf = surf.borrow();
36                let mut img = surf.image().unwrap();
37                img.draw(f.x(), f.y(), f.w(), f.h());
38            }
39        });
40
41        frame.handle({
42            let mut x = 0;
43            let mut y = 0;
44            let surf = surf.clone();
45            move |f, ev| {
46                // println!("{}", ev);
47                // println!("coords {:?}", app::event_coords());
48                // println!("get mouse {:?}", app::get_mouse());
49                let surf = surf.borrow_mut();
50                match ev {
51                    Event::Push => {
52                        ImageSurface::push_current(&surf);
53                        set_draw_color(Color::Red);
54                        set_line_style(LineStyle::Solid, 3);
55                        let coords = app::event_coords();
56                        x = coords.0;
57                        y = coords.1;
58                        draw_point(x, y);
59                        ImageSurface::pop_current();
60                        f.redraw();
61                        true
62                    }
63                    Event::Drag => {
64                        ImageSurface::push_current(&surf);
65                        set_draw_color(Color::Red);
66                        set_line_style(LineStyle::Solid, 3);
67                        let coords = app::event_coords();
68                        draw_line(x, y, coords.0, coords.1);
69                        x = coords.0;
70                        y = coords.1;
71                        ImageSurface::pop_current();
72                        f.redraw();
73                        true
74                    }
75                    _ => false,
76                }
77            }
78        });
79        Self { frame, surf }
80    }