mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-24 21:32:15 +08:00
28 lines
421 B
Rust
Executable File
28 lines
421 B
Rust
Executable File
pub trait Draw {
|
|
fn draw(&self);
|
|
}
|
|
|
|
pub struct Screen {
|
|
pub components: Vec<Box<dyn Draw>>,
|
|
}
|
|
|
|
impl Screen {
|
|
pub fn run(&self) {
|
|
for component in self.components.iter() {
|
|
component.draw();
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct Button {
|
|
pub width: u32,
|
|
pub height: u32,
|
|
pub label: String,
|
|
}
|
|
|
|
impl Draw for Button {
|
|
fn draw(&self) {
|
|
// code to actually draw a button
|
|
}
|
|
}
|