diff --git a/comfy-core/src/global_state.rs b/comfy-core/src/global_state.rs index 849c1eb..796b7a3 100644 --- a/comfy-core/src/global_state.rs +++ b/comfy-core/src/global_state.rs @@ -103,6 +103,7 @@ pub struct GlobalState { pub mouse_world: Vec2, pub mouse_locked: bool, + pub cursor_hidden: bool, pub egui_scale_factor: f32, diff --git a/comfy-core/src/input.rs b/comfy-core/src/input.rs index 171b620..4062532 100644 --- a/comfy-core/src/input.rs +++ b/comfy-core/src/input.rs @@ -16,6 +16,14 @@ pub fn is_mouse_button_released(button: MouseButton) -> bool { GLOBAL_STATE.borrow().mouse_just_released.contains(&button) } +pub fn set_cursor_hidden(hidden: bool) { + GLOBAL_STATE.borrow_mut().cursor_hidden = hidden; +} + +pub fn set_mouse_locked(locked: bool) { + GLOBAL_STATE.borrow_mut().mouse_locked = locked; +} + pub fn is_key_pressed(keycode: KeyCode) -> bool { GLOBAL_STATE.borrow().just_pressed.contains(&keycode) } diff --git a/comfy-core/src/shaders.rs b/comfy-core/src/shaders.rs index e680b67..3062298 100644 --- a/comfy-core/src/shaders.rs +++ b/comfy-core/src/shaders.rs @@ -62,10 +62,10 @@ pub enum UniformDef { } impl UniformDef { - pub fn to_wgsl(&self) -> &'static str { + pub fn to_wgsl(&self) -> &str { match self { UniformDef::F32(_) => "f32", - UniformDef::Custom { .. } => "X", + UniformDef::Custom { wgsl_decl, .. } => &wgsl_decl, } } } diff --git a/comfy-core/src/text.rs b/comfy-core/src/text.rs index dd92233..0a9ee57 100644 --- a/comfy-core/src/text.rs +++ b/comfy-core/src/text.rs @@ -98,8 +98,10 @@ pub fn gen_font_handle() -> FontHandle { ) } +/// Opaque handle to a font. The ID is exposed for debugging purposes. +/// If you set it manually, you're on your own! #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -pub struct FontHandle(u64); +pub struct FontHandle(pub u64); fn draw_text_internal( text: TextData, diff --git a/comfy/src/game_loop.rs b/comfy/src/game_loop.rs index 3890e73..e4b974e 100644 --- a/comfy/src/game_loop.rs +++ b/comfy/src/game_loop.rs @@ -172,8 +172,16 @@ pub async fn run_comfy_main_async( global_state.mouse_just_pressed.clear(); global_state.mouse_just_released.clear(); global_state.mouse_wheel = (0.0, 0.0); + + engine + .renderer + .as_ref() + .unwrap() + .window + .set_cursor_visible(!global_state.cursor_hidden); } + set_frame_time(frame_start.elapsed().as_secs_f32()); inc_frame_num();