From c141d8fe8bb9115ccb953ed6ea5b0b04bc828125 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sun, 4 Aug 2024 16:18:24 +1200 Subject: Unify is_cursor_visible and cursor_icon callbacks It makes sense to handle all cursor icon state at once. --- src/window.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/window.rs') diff --git a/src/window.rs b/src/window.rs index b280a36..1b602c8 100644 --- a/src/window.rs +++ b/src/window.rs @@ -15,7 +15,7 @@ pub struct Window { #[allow(dead_code)] context: softbuffer::Context, render_request: RenderRequest, previous_cursor_position: Option, - previous_cursor_icon: CursorIcon, + previous_cursor: Option, previous_title: String, } @@ -57,7 +57,7 @@ impl Window { context, render_request: RenderRequest::REDRAW, previous_cursor_position: None, - previous_cursor_icon: CursorIcon::Default, + previous_cursor: Some(CursorIcon::Default), previous_title: String::new(), } } @@ -74,11 +74,14 @@ impl Window { } } - pub fn update_cursor_icon(&mut self) { - let icon = self.controller.cursor_icon().unwrap_or(CursorIcon::Default); - if icon != self.previous_cursor_icon { - self.window.set_cursor_icon(icon); - self.previous_cursor_icon = icon; + pub fn update_cursor(&mut self) { + let cursor = self.controller.cursor(); + if cursor != self.previous_cursor { + self.window.set_cursor_visible(cursor.is_some()); + if let Some(icon) = cursor { + self.window.set_cursor_icon(icon); + } + self.previous_cursor = cursor; } } @@ -132,10 +135,6 @@ impl Window { } } - pub fn update_cursor_visible(&mut self) { - self.window.set_cursor_visible(self.controller.is_cursor_visible()); - } - /// Resize the frame buffer and screen surface to the new size of the window. pub fn resize_buffer_and_surface(&mut self, physical_dimensions: Dimensions) { if let Some((width, height)) = dim_to_nonzero_size(physical_dimensions) { -- cgit v1.2.3-70-g09d2