Skip to content

Instantly share code, notes, and snippets.

@lf94
Created December 16, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lf94/900a1af9ca3ffa53a94751a3016af9d2 to your computer and use it in GitHub Desktop.
Save lf94/900a1af9ca3ffa53a94751a3016af9d2 to your computer and use it in GitHub Desktop.
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