add age
This commit is contained in:
@@ -1,77 +1,73 @@
|
||||
#[allow(dead_code)]
|
||||
|
||||
use crate::{resources::Resources, widgets::*};
|
||||
use macroquad::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct IdTextInput {
|
||||
rect: Rect,
|
||||
text_rect: Rect,
|
||||
copy_box_rect: Rect,
|
||||
paste_box_rect: Rect,
|
||||
shadow_width: f32,
|
||||
color: UiColor,
|
||||
copy_color: UiColor,
|
||||
paste_color: UiColor,
|
||||
}
|
||||
|
||||
pub struct IdTextInputDrawParams<'a> {
|
||||
pub text: &'a str,
|
||||
pub color: UiColor,
|
||||
pub copy_color: UiColor,
|
||||
pub paste_color: UiColor,
|
||||
pub shadow_width: f32,
|
||||
}
|
||||
|
||||
impl IdTextInput {
|
||||
pub fn new(rect: Rect) -> Self {
|
||||
let copy_button_w = 0.25 * rect.w;
|
||||
let paste_button_h = 0.5 * rect.h;
|
||||
Self {
|
||||
rect,
|
||||
text_rect: Rect::new(rect.x, rect.y, rect.w - copy_button_w, rect.h),
|
||||
copy_box_rect: Rect::new(
|
||||
rect.x + (rect.w - copy_button_w),
|
||||
rect.y,
|
||||
copy_button_w,
|
||||
paste_button_h,
|
||||
),
|
||||
paste_box_rect: Rect::new(
|
||||
rect.x + (rect.w - copy_button_w),
|
||||
rect.y + paste_button_h,
|
||||
copy_button_w,
|
||||
paste_button_h,
|
||||
),
|
||||
shadow_width: 3.0,
|
||||
color: UiColor::Yellow,
|
||||
copy_color: UiColor::Blue,
|
||||
paste_color: UiColor::Pink,
|
||||
}
|
||||
pub fn initialize_state() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn draw(&self, resources: &Resources, text: &str) {
|
||||
draw_rect(&self.text_rect, self.color);
|
||||
draw_rect(&self.copy_box_rect, self.copy_color);
|
||||
draw_rect(&self.paste_box_rect, self.paste_color);
|
||||
draw_shadow(&self.rect, self.shadow_width);
|
||||
pub fn initialize_drawables(&mut self, rect: Rect) {
|
||||
let copy_button_w = 0.25 * rect.w;
|
||||
let paste_button_h = 0.5 * rect.h;
|
||||
self.rect = rect;
|
||||
self.text_rect = Rect::new(rect.x, rect.y, rect.w - copy_button_w, rect.h);
|
||||
self.copy_box_rect = Rect::new(
|
||||
rect.x + (rect.w - copy_button_w),
|
||||
rect.y,
|
||||
copy_button_w,
|
||||
paste_button_h,
|
||||
);
|
||||
self.paste_box_rect = Rect::new(
|
||||
rect.x + (rect.w - copy_button_w),
|
||||
rect.y + paste_button_h,
|
||||
copy_button_w,
|
||||
paste_button_h,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn draw(&self, params: &IdTextInputDrawParams, resources: &Resources) {
|
||||
draw_rect(&self.text_rect, params.color);
|
||||
draw_rect(&self.copy_box_rect, params.copy_color);
|
||||
draw_rect(&self.paste_box_rect, params.paste_color);
|
||||
draw_shadow(&self.rect, params.shadow_width);
|
||||
|
||||
let font = resources.font();
|
||||
let font_size = (0.15 * self.text_rect.w) as u16;
|
||||
let text_dims = measure_text(text, Some(font), font_size, 1.0);
|
||||
let text_dims = measure_text(params.text, Some(font), font_size, 1.0);
|
||||
draw_text_ex(
|
||||
&text,
|
||||
params.text,
|
||||
self.rect.x + (self.text_rect.w - text_dims.width) / 2.,
|
||||
self.rect.y + (self.text_rect.h - text_dims.height) / 2. + text_dims.offset_y,
|
||||
TextParams {
|
||||
font: Some(font),
|
||||
font_size: font_size,
|
||||
color: self.color.to_fg_color(),
|
||||
color: params.color.to_fg_color(),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for IdTextInput {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
rect: Default::default(),
|
||||
text_rect: Default::default(),
|
||||
copy_box_rect: Default::default(),
|
||||
paste_box_rect: Default::default(),
|
||||
shadow_width: Default::default(),
|
||||
color: UiColor::Grey,
|
||||
copy_color: UiColor::Grey,
|
||||
paste_color: UiColor::Grey,
|
||||
}
|
||||
pub fn handle_input(&self, _: &WidgetInput) -> IdTextInputInteraction {
|
||||
IdTextInputInteraction {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct IdTextInputInteraction {}
|
||||
|
||||
Reference in New Issue
Block a user