1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
use crate::graphics::{Point, Rectangle, Sprite}; use crate::ui::core::MouseCursor; use crate::ui::widget::checkbox; use crate::ui::Renderer; const SPRITE: Rectangle<u16> = Rectangle { x: 98, y: 0, width: 28, height: 28, }; impl checkbox::Renderer for Renderer { fn draw( &mut self, cursor_position: Point, bounds: Rectangle<f32>, text_bounds: Rectangle<f32>, is_checked: bool, ) -> MouseCursor { let mouse_over = bounds.contains(cursor_position) || text_bounds.contains(cursor_position); self.sprites.add(Sprite { source: Rectangle { x: SPRITE.x + (if mouse_over { SPRITE.width } else { 0 }), ..SPRITE }, position: Point::new(bounds.x, bounds.y), scale: (1.0, 1.0), }); if is_checked { self.sprites.add(Sprite { source: Rectangle { x: SPRITE.x + SPRITE.width * 2, ..SPRITE }, position: Point::new(bounds.x, bounds.y), scale: (1.0, 1.0), }); } if mouse_over { MouseCursor::Pointer } else { MouseCursor::OutOfBounds } } }