Move renderer code into a struct (ADT)

This commit is contained in:
2026-04-21 08:08:27 +01:00
parent dc0581c8cc
commit 81c5b5a1af
2 changed files with 27 additions and 3 deletions
+8 -2
View File
@@ -1,16 +1,21 @@
pub mod structs;
use sdl3::{pixels::Color, rect::Rect, render::Canvas, sys::metadata::render, ttf::Font, video::Window};
use sdl3::{Sdl, pixels::Color, rect::Rect, render::Canvas, sys::metadata::render, ttf::Font, video::Window};
use structs::{Prefs};
pub struct Screen<'a> {
canvas: Box<Canvas<Window>>,
font: Box<Font<'a>>
font: Box<Font<'a>>,
context: Box<Sdl>
}
impl Screen<'_> {
pub fn get_context(&self) -> &Sdl {
return &self.context;
}
pub fn print(&mut self, line: u32, text: &str) {
let rendered_text = self.font.render(text).solid(Color::RED).unwrap();
let texture_creator = self.canvas.texture_creator();
@@ -49,6 +54,7 @@ impl Screen<'_> {
let mut screen: Screen = Screen {
canvas: Box::new(window.into_canvas()),
font: Box::new(font),
context: Box::new(sdl_context),
};
screen.clear();