From 16e9049ceb2c61475a6518ec17d18459eb369793 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sun, 22 Dec 2024 13:35:16 +0100 Subject: [PATCH] add tooltips to selection options --- src/editor.rs | 4 ++++ src/ui.rs | 28 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 7c20934..73c8ca5 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -849,16 +849,19 @@ impl Editor { ); let y = footer_top as i32 + 49; + self.tooltip.add(100, y, 40, 40, "Cancel"); if simple_button(d, 100, y, 40, 40) || d.is_key_pressed(KeyboardKey::KEY_ESCAPE) { self.active_tool = Tool::SelectArea(Selection::default()); } draw_scaled_texture(d, textures.get("cancel"), 104, y + 4, 2.); + self.tooltip.add(144, y, 40, 40, "Save blueprint"); if simple_button(d, 144, y, 40, 40) { self.save_blueprint(selection); } draw_scaled_texture(d, textures.get("save"), 148, y + 4, 2.); + self.tooltip.add(188, y, 40, 40, "Copy"); if simple_button(d, 188, y, 40, 40) || (d.is_key_pressed(KeyboardKey::KEY_C) && d.is_key_down(KeyboardKey::KEY_LEFT_CONTROL)) @@ -868,6 +871,7 @@ impl Editor { } draw_scaled_texture(d, textures.get("copy"), 192, y + 4, 2.); + self.tooltip.add(232, y, 40, 40, "Delete"); if simple_button(d, 232, y, 40, 40) { let min = selection.0.min(selection.1); let max = selection.0.max(selection.1); diff --git a/src/ui.rs b/src/ui.rs index 6579185..4186304 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -3,20 +3,6 @@ use std::ops::Range; use crate::{draw_scaled_texture, theme::*, Textures}; use raylib::prelude::*; -pub fn simple_button(d: &mut RaylibDrawHandle, x: i32, y: i32, width: i32, height: i32) -> bool { - let mouse_pos = d.get_mouse_position(); - let bounds = Rectangle { - x: x as f32, - y: y as f32, - width: width as f32, - height: height as f32, - }; - let hover = bounds.check_collision_point_rec(mouse_pos); - let pressed = hover && d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT); - d.draw_rectangle(x, y, width, height, widget_bg(hover)); - pressed -} - #[derive(Debug)] pub struct ShapedText { text: String, @@ -167,6 +153,20 @@ impl Tooltip { } } +pub fn simple_button(d: &mut RaylibDrawHandle, x: i32, y: i32, width: i32, height: i32) -> bool { + let mouse_pos = d.get_mouse_position(); + let bounds = Rectangle { + x: x as f32, + y: y as f32, + width: width as f32, + height: height as f32, + }; + let hover = bounds.check_collision_point_rec(mouse_pos); + let pressed = hover && d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT); + d.draw_rectangle(x, y, width, height, widget_bg(hover)); + pressed +} + pub fn simple_toggle_button( d: &mut RaylibDrawHandle, state: &mut bool,