Function draw_rectf

Source
pub fn draw_rectf(x: i32, y: i32, w: i32, h: i32)
Expand description

Draws a filled rectangle

Examples found in repository?
examples/shapedwindow_taskbar.rs (line 133)
127fn prep_shape(w: i32, h: i32) -> image::RgbImage {
128    let surf = surface::ImageSurface::new(w, h, false);
129
130    surface::ImageSurface::push_current(&surf);
131
132    draw::set_draw_color(enums::Color::Black);
133    draw::draw_rectf(-1, -1, w + 2, h + 2);
134
135    draw::set_draw_color(enums::Color::White);
136    draw::draw_rounded_rectf(0, 0, w, h, 16);
137
138    let img = surf.image().unwrap();
139
140    surface::ImageSurface::pop_current();
141
142    img
143}
More examples
Hide additional examples
examples/table.rs (line 70)
63fn draw_data(txt: &str, x: i32, y: i32, w: i32, h: i32, selected: bool) {
64    draw::push_clip(x, y, w, h);
65    if selected {
66        draw::set_draw_color(enums::Color::from_u32(0x00D3_D3D3));
67    } else {
68        draw::set_draw_color(enums::Color::White);
69    }
70    draw::draw_rectf(x, y, w, h);
71    draw::set_draw_color(enums::Color::Gray0);
72    draw::set_font(enums::Font::Helvetica, 14);
73    draw::draw_text_boxed(txt, x, y, w, h, enums::Align::Center);
74    draw::draw_rect(x, y, w, h);
75    draw::pop_clip();
76}
examples/spreadsheet.rs (line 136)
129    fn draw_data(txt: &str, x: i32, y: i32, w: i32, h: i32, selected: bool) {
130        draw::push_clip(x, y, w, h);
131        if selected {
132            draw::set_draw_color(enums::Color::from_u32(0x00D3_D3D3));
133        } else {
134            draw::set_draw_color(enums::Color::White);
135        }
136        draw::draw_rectf(x, y, w, h);
137        draw::set_draw_color(enums::Color::Gray0);
138        draw::set_font(enums::Font::Helvetica, 14);
139        draw::draw_text_boxed(txt, x, y, w, h, enums::Align::Center);
140        draw::draw_rect(x, y, w, h);
141        draw::pop_clip();
142    }
examples/counter3.rs (line 54)
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}
examples/pong.rs (line 53)
34fn main() {
35    let app = app::App::default();
36    let mut wind = window::Window::default()
37        .with_size(800, 600)
38        .with_label("Pong!");
39    wind.set_center_screen();
40    let mut ball = Ball::new(40, 40);
41    ball.wid.set_color(Color::White);
42    wind.set_color(Color::Black);
43    wind.end();
44    wind.show();
45
46    let paddle_pos = Rc::from(RefCell::from(320)); // paddle's starting x position
47
48    // This is called whenever the window is drawn and redrawn (in the event loop)
49    wind.draw({
50        let paddle_pos = paddle_pos.clone();
51        move |_| {
52            draw::set_draw_color(Color::White);
53            draw::draw_rectf(*paddle_pos.borrow(), 540, 160, 20);
54        }
55    });
56
57    wind.handle({
58        let paddle_pos = paddle_pos.clone();
59        move |_, ev| {
60            match ev {
61                // we handle focus to be able to accept KeyDown events
62                Event::Focus => true,
63                Event::KeyDown => {
64                    let key = app::event_key();
65                    match key {
66                        Key::Left | KEY_A => *paddle_pos.borrow_mut() -= 30,
67                        Key::Right | KEY_D => *paddle_pos.borrow_mut() += 30,
68                        _ => return false,
69                    }
70                    true
71                }
72                Event::Move => {
73                    // Mouse's x position relative to the paddle's center
74                    *paddle_pos.borrow_mut() = app::event_coords().0 - 80;
75                    true
76                }
77                _ => false,
78            }
79        }
80    });
81
82    app::add_idle(move |_| {
83        ball.pos.0 += 10 * ball.dir.0 as i32; // The increment in x position
84        ball.pos.1 += 10 * ball.dir.1 as i32; // The increment in y position
85        if ball.pos.1 == 540 - 40
86            && (ball.pos.0 > *paddle_pos.borrow() - 40 && ball.pos.0 < *paddle_pos.borrow() + 160)
87        {
88            ball.dir.1 = Direction::Negative; // Reversal of motion when hitting the paddle
89        }
90        if ball.pos.1 == 0 {
91            ball.dir.1 = Direction::Positive; // Reversal of motion when hitting the top border
92        }
93        if ball.pos.0 == 800 - 40 {
94            ball.dir.0 = Direction::Negative; // Reversal of motion when hitting the right border
95        }
96        if ball.pos.0 == 0 {
97            ball.dir.0 = Direction::Positive; // Reversal of motion when hitting the left border
98        }
99        if ball.pos.1 > 600 {
100            // Resetting the ball position after it bypasses the paddle
101            ball.pos = (0, 0);
102            ball.dir = (Direction::Positive, Direction::Positive);
103        }
104        ball.wid.resize(ball.pos.0, ball.pos.1, 40, 40); // Moves the ball
105        wind.redraw();
106        // sleeps are necessary when calling redraw in the event loop
107        app::sleep(0.016);
108    });
109    app.run().unwrap();
110}