Finish, mudinji pochi
This commit is contained in:
+8
-70
@@ -1,45 +1,19 @@
|
||||
use macroquad::prelude::*;
|
||||
|
||||
use super::{color::UiColor, shadow::draw_shadow};
|
||||
|
||||
pub struct Button {
|
||||
pub is_active: bool,
|
||||
text: String,
|
||||
pub text: String,
|
||||
is_down: bool,
|
||||
is_clicked: bool,
|
||||
rect: Rect,
|
||||
shadow_width: f32,
|
||||
color: ButtonColor,
|
||||
}
|
||||
|
||||
pub enum ButtonColor {
|
||||
Grey,
|
||||
Green,
|
||||
Red,
|
||||
Blue,
|
||||
}
|
||||
|
||||
impl ButtonColor {
|
||||
fn to_bg_color(&self) -> Color {
|
||||
match self {
|
||||
ButtonColor::Grey => Color::from_rgba(140, 140, 140, 200),
|
||||
ButtonColor::Green => Color::from_rgba(112, 140, 141, 200),
|
||||
ButtonColor::Red => Color::from_rgba(123, 70, 85, 200),
|
||||
ButtonColor::Blue => Color::from_rgba(140, 120, 250, 200),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_shadow_color(&self) -> Color {
|
||||
let bg_color = self.to_bg_color();
|
||||
Color::from_rgba(
|
||||
(bg_color.r * 255.) as u8,
|
||||
(bg_color.g * 255.) as u8,
|
||||
(bg_color.b * 255.) as u8,
|
||||
100,
|
||||
)
|
||||
}
|
||||
pub color: UiColor,
|
||||
}
|
||||
|
||||
impl Button {
|
||||
pub fn new(text: &str, rect: Rect, color: ButtonColor) -> Self {
|
||||
pub fn new(text: &str, rect: Rect, color: UiColor) -> Self {
|
||||
Self {
|
||||
text: text.to_string(),
|
||||
is_down: false,
|
||||
@@ -68,9 +42,8 @@ impl Button {
|
||||
fn draw_button(&self) {
|
||||
let bg_color = match self.is_active {
|
||||
true => self.color.to_bg_color(),
|
||||
false => ButtonColor::Grey.to_bg_color(),
|
||||
false => self.color.to_shadow_color(),
|
||||
};
|
||||
|
||||
let button_draw_offset = self.get_button_draw_offset();
|
||||
draw_rectangle(
|
||||
self.rect.x + button_draw_offset,
|
||||
@@ -92,47 +65,12 @@ impl Button {
|
||||
return;
|
||||
}
|
||||
|
||||
let color = self.color.to_shadow_color();
|
||||
draw_rectangle(
|
||||
self.rect.x + self.rect.w,
|
||||
self.rect.y + self.shadow_width,
|
||||
self.shadow_width,
|
||||
self.rect.h,
|
||||
color,
|
||||
);
|
||||
|
||||
draw_rectangle(
|
||||
self.rect.x + self.shadow_width,
|
||||
self.rect.y + self.rect.h,
|
||||
self.rect.w - self.shadow_width,
|
||||
self.shadow_width,
|
||||
color,
|
||||
);
|
||||
|
||||
draw_triangle(
|
||||
vec2(self.rect.x + self.rect.w, self.rect.y),
|
||||
vec2(
|
||||
self.rect.x + self.rect.w + self.shadow_width,
|
||||
self.rect.y + self.shadow_width,
|
||||
),
|
||||
vec2(self.rect.x + self.rect.w, self.rect.y + self.shadow_width),
|
||||
color,
|
||||
);
|
||||
|
||||
draw_triangle(
|
||||
vec2(self.rect.x, self.rect.y + self.rect.h),
|
||||
vec2(
|
||||
self.rect.x + self.shadow_width,
|
||||
self.rect.y + self.rect.h + self.shadow_width,
|
||||
),
|
||||
vec2(self.rect.x + self.shadow_width, self.rect.y + self.rect.h),
|
||||
color,
|
||||
);
|
||||
draw_shadow(self.rect, self.shadow_width);
|
||||
}
|
||||
|
||||
fn draw_label(&self) {
|
||||
let font_color = match self.is_active {
|
||||
true => Color::from_rgba(0, 0, 0, 255),
|
||||
true => self.color.to_fg_color(),
|
||||
false => Color::from_rgba(100, 100, 100, 255),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user