add tooltips to selection options

This commit is contained in:
Crispy 2024-12-22 13:35:16 +01:00
parent 12b39467e3
commit 16e9049ceb
2 changed files with 18 additions and 14 deletions

View file

@ -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);

View file

@ -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,