summaryrefslogtreecommitdiffstats
path: root/examples/ggez/renderer/radio.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-07-23 12:07:00 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-07-23 12:07:00 +0200
commit8f6ea4bdc99ef5960316d2230676495f2d90c30e (patch)
tree6c5e6cfa28c91123840ae6117fc045e837d7238c /examples/ggez/renderer/radio.rs
parentf007929b9c68893cedbe6589b42fa4b21c5e54d6 (diff)
downloadiced-8f6ea4bdc99ef5960316d2230676495f2d90c30e.tar.gz
iced-8f6ea4bdc99ef5960316d2230676495f2d90c30e.tar.bz2
iced-8f6ea4bdc99ef5960316d2230676495f2d90c30e.zip
Implement `radio::Renderer` and `slider::Renderer` in `ggez` example
Diffstat (limited to '')
-rw-r--r--examples/ggez/renderer/radio.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/ggez/renderer/radio.rs b/examples/ggez/renderer/radio.rs
new file mode 100644
index 00000000..64310f9b
--- /dev/null
+++ b/examples/ggez/renderer/radio.rs
@@ -0,0 +1,63 @@
+use super::Renderer;
+
+use ggez::graphics::{DrawParam, Rect};
+use iced::{radio, MouseCursor, Point, Rectangle};
+
+const SPRITE: Rect = Rect {
+ x: 98.0,
+ y: 28.0,
+ w: 28.0,
+ h: 28.0,
+};
+
+impl radio::Renderer for Renderer<'_> {
+ fn draw(
+ &mut self,
+ cursor_position: Point,
+ bounds: Rectangle<f32>,
+ bounds_with_label: Rectangle<f32>,
+ is_selected: bool,
+ ) -> MouseCursor {
+ let mouse_over = bounds_with_label.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_selected {
+ 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
+ }
+ }
+}