Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #![allow(unused)]
  2.  
  3.  
  4.  
  5. pub mod sdl {
  6. pub struct Sdl2<'a> {
  7. pub version: &'a str
  8. }
  9.  
  10. impl<'a> Sdl2<'a> {
  11. pub fn new(ver: &str) -> Sdl2 {
  12. Sdl2 {
  13. version: ver
  14. }
  15. }
  16. }
  17. }
  18.  
  19.  
  20. pub mod ttf {
  21. use crate::sdl::Sdl2;
  22.  
  23. pub struct TextEngine<'a> {
  24. sdl: &'a Sdl2<'a>
  25. }
  26.  
  27. impl<'a> TextEngine<'a> {
  28. pub fn new(sdl: &'a Sdl2) -> Self {
  29. TextEngine {
  30. sdl: sdl
  31. }
  32. }
  33.  
  34. pub fn hello(&self) -> String {
  35. format!("Hello. I am a TextEngine. My SDL version is {}.", self.sdl.version)
  36. }
  37. }
  38. }
  39.  
  40.  
  41.  
  42. pub mod ux {
  43. use crate::ttf;
  44. use component::{Widget};
  45.  
  46. mod component {
  47. pub struct Widget {
  48. id: u32,
  49. }
  50.  
  51. impl Widget {
  52. pub fn new(id: u32) -> Widget {
  53. Widget {
  54. id: id
  55. }
  56. }
  57.  
  58. pub fn render(&self) {
  59. println!("I am a widget. My id is {}.", self.id);
  60. }
  61. }
  62. }
  63.  
  64. pub struct UI<'a> {
  65. pub texter: &'a ttf::TextEngine<'a>,
  66. widgets: Vec<Widget>,
  67. }
  68.  
  69. impl<'a> UI<'a> {
  70. pub fn new(engine: &'a ttf::TextEngine) -> Self {
  71. let mut v: Vec<Widget> = Vec::new();
  72. v.push(Widget::new(0));
  73. v.push(Widget::new(1));
  74. v.push(Widget::new(2));
  75. v.push(Widget::new(3));
  76. UI {
  77. texter: engine,
  78. widgets: v,
  79. }
  80. }
  81.  
  82. pub fn render(&self) {
  83. for w in &self.widgets {
  84. w.render();
  85. }
  86. }
  87. }
  88. }
  89.  
  90.  
  91. fn main() {
  92. let sdl2 = sdl::Sdl2::new("2.0.1");
  93. let te = ttf::TextEngine::new(&sdl2);
  94. let ui = ux::UI::new(&te);
  95. println!("{}", ui.texter.hello());
  96. ui.render();
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement