Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused)]
- pub mod sdl {
- pub struct Sdl2<'a> {
- pub version: &'a str
- }
- impl<'a> Sdl2<'a> {
- pub fn new(ver: &str) -> Sdl2 {
- Sdl2 {
- version: ver
- }
- }
- }
- }
- pub mod ttf {
- use crate::sdl::Sdl2;
- pub struct TextEngine<'a> {
- sdl: &'a Sdl2<'a>
- }
- impl<'a> TextEngine<'a> {
- pub fn new(sdl: &'a Sdl2) -> Self {
- TextEngine {
- sdl: sdl
- }
- }
- pub fn hello(&self) -> String {
- format!("Hello. I am a TextEngine. My SDL version is {}.", self.sdl.version)
- }
- }
- }
- pub mod ux {
- use crate::ttf;
- use component::{Widget};
- mod component {
- pub struct Widget {
- id: u32,
- }
- impl Widget {
- pub fn new(id: u32) -> Widget {
- Widget {
- id: id
- }
- }
- pub fn render(&self) {
- println!("I am a widget. My id is {}.", self.id);
- }
- }
- }
- pub struct UI<'a> {
- pub texter: &'a ttf::TextEngine<'a>,
- widgets: Vec<Widget>,
- }
- impl<'a> UI<'a> {
- pub fn new(engine: &'a ttf::TextEngine) -> Self {
- let mut v: Vec<Widget> = Vec::new();
- v.push(Widget::new(0));
- v.push(Widget::new(1));
- v.push(Widget::new(2));
- v.push(Widget::new(3));
- UI {
- texter: engine,
- widgets: v,
- }
- }
- pub fn render(&self) {
- for w in &self.widgets {
- w.render();
- }
- }
- }
- }
- fn main() {
- let sdl2 = sdl::Sdl2::new("2.0.1");
- let te = ttf::TextEngine::new(&sdl2);
- let ui = ux::UI::new(&te);
- println!("{}", ui.texter.hello());
- ui.render();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement