Created
December 16, 2017 21:50
-
-
Save lf94/900a1af9ca3ffa53a94751a3016af9d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Component { | |
fn draw(&self, ctx: &mut Context) -> (); | |
fn get_children(&self) -> Vec<Component>; | |
} | |
struct Label { | |
children: Vec<Component>, | |
text: graphics::Text, | |
color: graphics::Color, | |
position: graphics::Point, | |
rotation: f32 | |
} | |
impl Component for Label { | |
fn draw(&self, ctx: &mut Context) -> () { | |
graphics::set_color(ctx, self.color)?; | |
graphics::draw(ctx, &self.text, self.position, self.rotation); | |
for child in self.children { | |
child.draw(ctx) | |
} | |
} | |
fn set_color(&mut self, color: Color) -> () { | |
self.color = color; | |
} | |
fn set_text(&mut self, text: &str, font: &Font) -> () { | |
self.text = graphics::Text::new(ctx, text, font).unwrap(); | |
} | |
fn get_children(&self) -> Vec<Component> { | |
self.children | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment