summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-08 23:42:50 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-08 23:42:50 -0500
commitb089bc20865a98be2f42dac7f5d35deff5efb33a (patch)
tree1ef9111cf1e16563f4cfd5554289827f10daf3eb
parentgraphics: set minimum window size (diff)
downloadDungeonCrawl-b089bc20865a98be2f42dac7f5d35deff5efb33a.tar.gz
DungeonCrawl-b089bc20865a98be2f42dac7f5d35deff5efb33a.tar.bz2
DungeonCrawl-b089bc20865a98be2f42dac7f5d35deff5efb33a.zip
graphics: have window default to minimum size
-rw-r--r--game/src/main.rs2
-rw-r--r--graphics/src/lib.rs16
-rw-r--r--graphics/src/render.rs4
3 files changed, 17 insertions, 5 deletions
diff --git a/game/src/main.rs b/game/src/main.rs
index 3764c6a..df94ea4 100644
--- a/game/src/main.rs
+++ b/game/src/main.rs
@@ -3,7 +3,7 @@ use graphics::*;
fn main() -> Result<()> {
// Load the window
- let mut window = Window::new(720, 480, "game")?;
+ let mut window = Window::new_default()?;
// Initial game state
let mut dungeon = Dungeon::new();
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index a9567eb..2051177 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -42,9 +42,9 @@ impl Window {
///
/// let window = Window::new(800, 600, "Dungeon Crawl").unwrap();
/// ```
- pub fn new(width: i32, height: i32, title: &str) -> crate::Result<Self> {
+ pub fn new(width: u16, height: u16, title: &str) -> crate::Result<Self> {
let (mut handle, thread) = raylib::init()
- .size(width, height)
+ .size(width.into(), height.into())
.title(title)
.resizable()
.log_level(TraceLogLevel::LOG_WARNING)
@@ -65,6 +65,18 @@ impl Window {
})
}
+ /// Instantiates a new window with a default tile and size
+ ///
+ /// # Examples
+ /// ```no_run
+ /// use graphics::Window;
+ ///
+ /// let window = Window::new_default().unwrap();
+ /// ```
+ pub fn new_default() -> crate::Result<Self> {
+ Self::new(render::RENDER_WIDTH, render::RENDER_HEIGHT, "Dungeon Crawl")
+ }
+
/// Returns if the window should be closed.
/// This usually means the 'x' button has been pressed.
pub fn is_open(&self) -> bool {
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 28631b2..18dc5e3 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -69,10 +69,10 @@ const UI_HEIGHT: u16 = (UI_PADDING + FONT_SIZE) * 3;
const TILE_SIZE: u16 = TEXTURE_SIZE * 3;
/// The render height of the screen
-const RENDER_HEIGHT: u16 = UI_HEIGHT + (TILE_SIZE * VIEW_DISTANCE);
+pub const RENDER_HEIGHT: u16 = UI_HEIGHT + (TILE_SIZE * VIEW_DISTANCE);
/// The render width of the screen
-const RENDER_WIDTH: u16 = RENDER_HEIGHT * 4 / 3;
+pub const RENDER_WIDTH: u16 = RENDER_HEIGHT * 4 / 3;
// Tile atlas.bmp textures
const ATLAS_WALL_SIDE: (u16, u16) = (0, 0);