♻️ Refactor render options (wasm)

This commit is contained in:
Belén Albeza
2026-03-18 13:16:13 +01:00
parent 0597eef750
commit 619842152d
5 changed files with 16 additions and 21 deletions

View File

@@ -1401,9 +1401,9 @@
(dbg/enabled? :wasm-viewbox)
(bit-or 2r00000000000000000000000000000001)
(text-editor-wasm?)
(bit-or 2r00000000000000000000000000001000)
(bit-or 2r00000000000000000000000000000100)
(contains? cf/flags :render-wasm-info)
(bit-or 2r00000000000000000000000000010000)))
(bit-or 2r00000000000000000000000000001000)))
(defn set-canvas-size
[canvas]

View File

@@ -3,7 +3,6 @@ mod emscripten;
mod error;
mod math;
mod mem;
mod options;
mod performance;
mod render;
mod shapes;

View File

@@ -1,5 +0,0 @@
pub const DEBUG_VISIBLE: u32 = 0x01;
pub const PROFILE_REBUILD_TILES: u32 = 0x02;
pub const FAST_MODE: u32 = 0x04;
pub const TEXT_EDITOR_V3: u32 = 0x08;
pub const SHOW_WASM_INFO: u32 = 0x10;

View File

@@ -61,7 +61,7 @@ pub fn render_wasm_label(render_state: &mut RenderState) {
let debug_font = render_state.fonts.debug_font();
canvas.draw_str(str, p, debug_font, &paint);
if render_state.options.show_info_text() {
if render_state.options.is_text_editor_v3() {
str = "TEXT EDITOR / V3";
let (scalar, _) = render_state.fonts.debug_font().measure_str(str, None);

View File

@@ -1,42 +1,43 @@
use crate::options;
// Render options flags
const DEBUG_VISIBLE: u32 = 0x01;
const PROFILE_REBUILD_TILES: u32 = 0x02;
const TEXT_EDITOR_V3: u32 = 0x04;
const SHOW_WASM_INFO: u32 = 0x08;
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub struct RenderOptions {
pub flags: u32,
pub dpr: Option<f32>,
fast_mode: bool,
}
impl RenderOptions {
pub fn is_debug_visible(&self) -> bool {
self.flags & options::DEBUG_VISIBLE == options::DEBUG_VISIBLE
self.flags & DEBUG_VISIBLE == DEBUG_VISIBLE
}
pub fn is_profile_rebuild_tiles(&self) -> bool {
self.flags & options::PROFILE_REBUILD_TILES == options::PROFILE_REBUILD_TILES
self.flags & PROFILE_REBUILD_TILES == PROFILE_REBUILD_TILES
}
/// Use fast mode to enable / disable expensive operations
pub fn is_fast_mode(&self) -> bool {
self.flags & options::FAST_MODE == options::FAST_MODE
self.fast_mode
}
pub fn set_fast_mode(&mut self, enabled: bool) {
if enabled {
self.flags |= options::FAST_MODE;
} else {
self.flags &= !options::FAST_MODE;
}
self.fast_mode = enabled;
}
pub fn dpr(&self) -> f32 {
self.dpr.unwrap_or(1.0)
}
pub fn show_info_text(&self) -> bool {
self.flags & options::TEXT_EDITOR_V3 == options::TEXT_EDITOR_V3
pub fn is_text_editor_v3(&self) -> bool {
self.flags & TEXT_EDITOR_V3 == TEXT_EDITOR_V3
}
pub fn show_wasm_info(&self) -> bool {
self.flags & options::SHOW_WASM_INFO == options::SHOW_WASM_INFO
self.flags & SHOW_WASM_INFO == SHOW_WASM_INFO
}
}