Compare commits
2 commits
3906c76b13
...
74d142191c
Author | SHA1 | Date | |
---|---|---|---|
74d142191c | |||
f35ca28c02 |
2 changed files with 16 additions and 26 deletions
|
@ -884,15 +884,11 @@ impl Editor {
|
|||
self.tooltip.add(368, 4, 48, 32, "Speed");
|
||||
draw_usize(d, textures, 1 << self.sim_speed, (368, 4), SPEED_DIGITS, 1);
|
||||
slider(
|
||||
d,
|
||||
&self.mouse,
|
||||
(d, &self.mouse),
|
||||
rect(368, 24, 48, 12),
|
||||
&mut self.sim_speed,
|
||||
0,
|
||||
MAX_SPEED_POWER,
|
||||
368,
|
||||
24,
|
||||
48,
|
||||
12,
|
||||
);
|
||||
|
||||
self.tooltip.add(420, 4, 180, 32, "Steps");
|
||||
|
@ -1028,8 +1024,7 @@ impl Editor {
|
|||
|(row, col): (i32, i32), texture: &str, tooltip: &'static str, tool_option: Tool| {
|
||||
let border = 4.;
|
||||
let gap = 2.;
|
||||
let tex_size = 32.;
|
||||
let button_size = tex_size + border * 2.;
|
||||
let button_size = 32. + border * 2.;
|
||||
let grid_size = button_size + gap * 2.;
|
||||
let pos = Vector2 {
|
||||
x: 100. + col as f32 * grid_size - if col < 0 { 10. } else { 0. },
|
||||
|
@ -1040,13 +1035,11 @@ impl Editor {
|
|||
tooltip,
|
||||
);
|
||||
scrollable_texture_option_button(
|
||||
d,
|
||||
&self.mouse,
|
||||
(d, &self.mouse),
|
||||
pos,
|
||||
textures.get(texture),
|
||||
tool_option,
|
||||
&mut self.active_tool,
|
||||
tex_size,
|
||||
border,
|
||||
)
|
||||
};
|
||||
|
|
27
src/ui.rs
27
src/ui.rs
|
@ -299,13 +299,11 @@ pub fn text_input(
|
|||
}
|
||||
|
||||
pub fn scrollable_texture_option_button<T>(
|
||||
d: &mut RaylibDrawHandle,
|
||||
mouse: &MouseInput,
|
||||
(d, mouse): (&mut RaylibDrawHandle, &MouseInput),
|
||||
pos: Vector2,
|
||||
texture: &Texture2D,
|
||||
option: T,
|
||||
current: &mut T,
|
||||
tex_size: f32,
|
||||
border: f32,
|
||||
) -> Option<Scroll>
|
||||
where
|
||||
|
@ -314,8 +312,8 @@ where
|
|||
let bounds = Rectangle {
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
width: tex_size + border * 2.,
|
||||
height: tex_size + border * 2.,
|
||||
width: 32. + border * 2.,
|
||||
height: 32. + border * 2.,
|
||||
};
|
||||
d.draw_rectangle_rec(
|
||||
bounds,
|
||||
|
@ -329,7 +327,7 @@ where
|
|||
texture,
|
||||
pos + Vector2::new(border, border),
|
||||
0.,
|
||||
tex_size / texture.width as f32,
|
||||
32. / texture.width as f32,
|
||||
Color::WHITE,
|
||||
);
|
||||
if mouse.is_over(bounds) {
|
||||
|
@ -388,21 +386,20 @@ pub fn draw_usize_small(
|
|||
}
|
||||
|
||||
pub fn slider(
|
||||
d: &mut RaylibDrawHandle,
|
||||
mouse: &MouseInput,
|
||||
(d, mouse): (&mut RaylibDrawHandle, &MouseInput),
|
||||
bounds: Rectangle,
|
||||
value: &mut u8,
|
||||
min: u8,
|
||||
max: u8,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) -> bool {
|
||||
// draw state
|
||||
// the +1 makes the lowest state look slightly filled and the max state fully filled
|
||||
let percent = (*value - min + 1) as f32 / (max - min + 1) as f32;
|
||||
d.draw_rectangle(x, y, width, height, BG_WIDGET);
|
||||
d.draw_rectangle(x, y, (width as f32 * percent) as i32, height, Color::CYAN);
|
||||
let bounds = Rectangle::new(x as f32, y as f32, width as f32, height as f32);
|
||||
d.draw_rectangle_rec(bounds, BG_WIDGET);
|
||||
let mut filled_bounds = bounds;
|
||||
filled_bounds.width *= percent;
|
||||
d.draw_rectangle_rec(filled_bounds, Color::CYAN);
|
||||
// interaction
|
||||
if mouse.is_over(bounds) {
|
||||
if mouse.left_hold() {
|
||||
let percent = (mouse.pos().x - bounds.x) / bounds.width;
|
||||
|
|
Loading…
Add table
Reference in a new issue