use super::super::*;
pub struct WindowWidget {
pub font: Option<Font>,
}
impl WindowWidget {
pub fn new() -> Self {
Self { font: None }
}
pub async fn set_font(&mut self, font_path: &str) -> &mut Self {
self.font = Some(load_ttf_font(font_path).await.unwrap());
self
}
pub fn Text(&self, win: &mut Window, text: &str, color: Color) -> (usize, Text) {
let mut x = Widget::Text(Text::new(text, self.font.clone(), color, None));
win.push(&mut x.clone());
(win.widgets.len() - 1, x.as_text().clone())
}
pub fn Button(&self, win: &mut Window, text: &str) -> (usize, Button) {
let mut x = Widget::Button(Button::new(text, self.font.clone(), None, None));
win.push(&mut x);
(win.widgets.len() - 1, x.as_button().clone())
}
pub fn Slider(
&self,
win: &mut Window,
min: f32,
max: f32,
default: Option<f32>,
size: Vec2,
) -> (usize, Slider) {
let mut x = Widget::Slider(Slider::new(
self.font.clone(),
min,
max,
default,
size,
true,
None,
));
let idx = win.push(&mut x.clone());
(win.widgets.len() - 1, win.get(idx).as_slider().clone())
}
pub fn DisplayImage(
&self,
win: &mut Window,
texture: Option<Texture2D>,
size: Vec2,
) -> (usize, DisplayImage) {
let mut x = Widget::DisplayImage(DisplayImage::new(texture, size, None, None));
win.push(&mut x.clone());
(win.widgets.len() - 1, x.as_image().clone())
}
pub fn WidgetRow(&self, win: &mut Window) -> (usize, Option<WidgetRow>) {
let mut x = Widget::WidgetRow(WidgetRow::new(self.font.clone(), None, win.rect.w));
win.push(&mut x.clone());
(win.widgets.len() - 1, Some(x.as_widget_row().clone()))
}
pub fn Checkbox(&self, win: &mut Window, text: &str, ticked: bool) -> (usize, Checkbox) {
let mut x = Widget::Checkbox(Checkbox::new(
text,
self.font.clone(),
Some(ticked),
None,
None,
));
win.push(&mut x);
(win.widgets.len() - 1, x.as_checkbox().clone())
}
pub fn TextBox(&self, win: &mut Window, text: &str, size: (f32, f32), placeholder: &str) -> (usize, TextBox) {
let mut x = Widget::TextBox(TextBox::new(
text,
placeholder,
size,
self.font.clone(),
None,
));
win.push(&mut x);
(win.widgets.len() - 1, x.as_textbox().clone())
}
}