windows: Remove more todos (#13818)

Release Notes:

- N/A
This commit is contained in:
张小白
2024-07-09 10:44:42 -07:00
committed by GitHub
parent ce7074c883
commit 8203b6875b
4 changed files with 30 additions and 29 deletions
+1 -1
View File
@@ -1259,7 +1259,7 @@ fn is_modifier(virtual_key: VIRTUAL_KEY) -> bool {
}
#[inline]
fn current_modifiers() -> Modifiers {
pub(crate) fn current_modifiers() -> Modifiers {
Modifiers {
control: is_virtual_key_pressed(VK_CONTROL),
alt: is_virtual_key_pressed(VK_MENU),
+1 -23
View File
@@ -27,10 +27,7 @@ use windows::{
System::{Com::*, LibraryLoader::*, Ole::*, SystemInformation::*, Threading::*, Time::*},
UI::{Input::KeyboardAndMouse::*, Shell::*, WindowsAndMessaging::*},
},
UI::{
Color,
ViewManagement::{UIColorType, UISettings},
},
UI::ViewManagement::UISettings,
};
use crate::*;
@@ -678,25 +675,6 @@ fn load_icon() -> Result<HICON> {
Ok(HICON(handle.0))
}
// https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes
#[inline]
fn system_appearance() -> Result<WindowAppearance> {
let ui_settings = UISettings::new()?;
let foreground_color = ui_settings.GetColorValue(UIColorType::Foreground)?;
// If the foreground is light, then is_color_light will evaluate to true,
// meaning Dark mode is enabled.
if is_color_light(&foreground_color) {
Ok(WindowAppearance::Dark)
} else {
Ok(WindowAppearance::Light)
}
}
#[inline(always)]
fn is_color_light(color: &Color) -> bool {
((5 * color.G as u32) + (2 * color.R as u32) + color.B as u32) > (8 * 128)
}
#[inline]
fn should_auto_hide_scrollbars() -> Result<bool> {
let ui_settings = UISettings::new()?;
+26 -1
View File
@@ -1,7 +1,13 @@
use std::sync::OnceLock;
use ::util::ResultExt;
use windows::Win32::{Foundation::*, UI::WindowsAndMessaging::*};
use windows::{
Win32::{Foundation::*, UI::WindowsAndMessaging::*},
UI::{
Color,
ViewManagement::{UIColorType, UISettings},
},
};
use crate::*;
@@ -118,3 +124,22 @@ pub(crate) fn logical_point(x: f32, y: f32, scale_factor: f32) -> Point<Pixels>
y: px(y / scale_factor),
}
}
// https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes
#[inline]
pub(crate) fn system_appearance() -> Result<WindowAppearance> {
let ui_settings = UISettings::new()?;
let foreground_color = ui_settings.GetColorValue(UIColorType::Foreground)?;
// If the foreground is light, then is_color_light will evaluate to true,
// meaning Dark mode is enabled.
if is_color_light(&foreground_color) {
Ok(WindowAppearance::Dark)
} else {
Ok(WindowAppearance::Light)
}
}
#[inline(always)]
fn is_color_light(color: &Color) -> bool {
((5 * color.G as u32) + (2 * color.R as u32) + color.B as u32) > (8 * 128)
}
+2 -4
View File
@@ -383,9 +383,8 @@ impl PlatformWindow for WindowsWindow {
self.0.state.borrow().scale_factor
}
// todo(windows)
fn appearance(&self) -> WindowAppearance {
WindowAppearance::Dark
system_appearance().log_err().unwrap_or_default()
}
fn display(&self) -> Option<Rc<dyn PlatformDisplay>> {
@@ -405,9 +404,8 @@ impl PlatformWindow for WindowsWindow {
logical_point(point.x as f32, point.y as f32, scale_factor)
}
// todo(windows)
fn modifiers(&self) -> Modifiers {
Modifiers::none()
current_modifiers()
}
fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {