2018-12-23 23:15:18 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
2018-12-23 19:06:40 +00:00
|
|
|
pub struct Vec2 {
|
|
|
|
pub x: f32,
|
|
|
|
pub y: f32,
|
|
|
|
}
|
|
|
|
|
2018-12-23 23:15:18 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
2018-12-23 19:06:40 +00:00
|
|
|
pub struct Rect {
|
|
|
|
pub pos: Vec2,
|
|
|
|
pub size: Vec2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Rect {
|
|
|
|
pub fn contains(&self, p: &Vec2) -> bool {
|
|
|
|
self.pos.x <= p.x
|
|
|
|
&& p.x <= self.pos.x + self.size.x
|
|
|
|
&& self.pos.y <= p.y
|
|
|
|
&& p.y <= self.pos.y + self.size.y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-23 23:15:18 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Deserialize)]
|
2018-12-23 19:06:40 +00:00
|
|
|
pub struct Input {
|
|
|
|
pub screen_size: Vec2,
|
|
|
|
pub mouse_pos: Vec2,
|
|
|
|
}
|
|
|
|
|
2018-12-23 23:15:18 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Serialize)]
|
2018-12-23 19:06:40 +00:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub enum TextAlign {
|
2018-12-23 23:15:18 +00:00
|
|
|
Start, // Test with arabic text
|
2018-12-23 19:06:40 +00:00
|
|
|
Center,
|
|
|
|
End,
|
|
|
|
}
|
|
|
|
|
2018-12-23 23:15:18 +00:00
|
|
|
#[derive(Clone, Debug, Serialize)] // TODOcopy
|
2018-12-23 19:06:40 +00:00
|
|
|
#[serde(rename_all = "snake_case", tag = "kind")]
|
|
|
|
pub enum PaintCmd {
|
|
|
|
Clear {
|
|
|
|
fill_style: String,
|
|
|
|
},
|
|
|
|
RoundedRect {
|
|
|
|
fill_style: String,
|
|
|
|
pos: Vec2,
|
|
|
|
size: Vec2,
|
|
|
|
corner_radius: f32,
|
|
|
|
},
|
|
|
|
Text {
|
|
|
|
fill_style: String,
|
|
|
|
font: String,
|
|
|
|
pos: Vec2,
|
|
|
|
text: String,
|
|
|
|
text_align: TextAlign,
|
|
|
|
},
|
|
|
|
}
|