summaryrefslogtreecommitdiffstats
path: root/examples/tour/renderer/checkbox.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-09-05 07:23:03 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-09-05 07:23:03 +0200
commitced3ffc22570048711fefba638782a31d0e06035 (patch)
treec3c3f29be40ec348f15205a3dd920088edb52ace /examples/tour/renderer/checkbox.rs
parent3440ba3cb44bfc9a2b67708b683958a97d8c5e23 (diff)
downloadiced-ced3ffc22570048711fefba638782a31d0e06035.tar.gz
iced-ced3ffc22570048711fefba638782a31d0e06035.tar.bz2
iced-ced3ffc22570048711fefba638782a31d0e06035.zip
Move `ggez` example to `tour`
Diffstat (limited to 'examples/tour/renderer/checkbox.rs')
-rw-r--r--examples/tour/renderer/checkbox.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/examples/tour/renderer/checkbox.rs b/examples/tour/renderer/checkbox.rs
new file mode 100644
index 00000000..20a91be5
--- /dev/null
+++ b/examples/tour/renderer/checkbox.rs
@@ -0,0 +1,64 @@
+use super::Renderer;
+
+use ggez::graphics::{DrawParam, Rect};
+use iced::{checkbox, MouseCursor};
+
+const SPRITE: Rect = Rect {
+ x: 98.0,
+ y: 0.0,
+ w: 28.0,
+ h: 28.0,
+};
+
+impl checkbox::Renderer for Renderer<'_> {
+ fn draw(
+ &mut self,
+ cursor_position: iced::Point,
+ bounds: iced::Rectangle,
+ text_bounds: iced::Rectangle,
+ is_checked: bool,
+ ) -> MouseCursor {
+ let mouse_over = bounds.contains(cursor_position)
+ || text_bounds.contains(cursor_position);
+
+ let width = self.spritesheet.width() as f32;
+ let height = self.spritesheet.height() as f32;
+
+ self.sprites.add(DrawParam {
+ src: Rect {
+ x: (SPRITE.x + (if mouse_over { SPRITE.w } else { 0.0 }))
+ / width,
+ y: SPRITE.y / height,
+ w: SPRITE.w / width,
+ h: SPRITE.h / height,
+ },
+ dest: ggez::mint::Point2 {
+ x: bounds.x,
+ y: bounds.y,
+ },
+ ..DrawParam::default()
+ });
+
+ if is_checked {
+ self.sprites.add(DrawParam {
+ src: Rect {
+ x: (SPRITE.x + SPRITE.w * 2.0) / width,
+ y: SPRITE.y / height,
+ w: SPRITE.w / width,
+ h: SPRITE.h / height,
+ },
+ dest: ggez::mint::Point2 {
+ x: bounds.x,
+ y: bounds.y,
+ },
+ ..DrawParam::default()
+ });
+ }
+
+ if mouse_over {
+ MouseCursor::Pointer
+ } else {
+ MouseCursor::OutOfBounds
+ }
+ }
+}