Skip to content

Commit

Permalink
Add APIs to query system theme (#98)
Browse files Browse the repository at this point in the history
* Add APIs to query system theme

* Formatted Last Commit
  • Loading branch information
onion108 authored Feb 9, 2025
1 parent 755e587 commit f38ece8
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/sdl3/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use sys::properties::{
SDL_CreateProperties, SDL_DestroyProperties, SDL_SetNumberProperty, SDL_SetStringProperty,
};
use sys::stdinc::{SDL_FunctionPointer, SDL_free, Uint64};
use sys::video::{SDL_DisplayMode, SDL_DisplayModeData, SDL_DisplayOrientation, SDL_WindowFlags};
use sys::video::{
SDL_DisplayMode, SDL_DisplayModeData, SDL_DisplayOrientation, SDL_GetSystemTheme,
SDL_WindowFlags, SDL_SYSTEM_THEME_DARK, SDL_SYSTEM_THEME_LIGHT, SDL_SYSTEM_THEME_UNKNOWN,
};

use crate::sys;

Expand Down Expand Up @@ -687,6 +690,18 @@ impl From<WindowContext> for Window {

impl_raw_accessors!((GLContext, sys::video::SDL_GLContext));

/// System theme.
pub enum SystemTheme {
/// Unknown system theme.
Unknown,

/// Light colored system theme.
Light,

/// Dark colored system theme.
Dark,
}

impl VideoSubsystem {
/// Initializes a new `WindowBuilder`; a convenience method that calls `WindowBuilder::new()`.
pub fn window(&self, title: &str, width: u32, height: u32) -> WindowBuilder {
Expand Down Expand Up @@ -1077,6 +1092,19 @@ impl VideoSubsystem {
pub fn vulkan_get_proc_address_function(&self) -> SDL_FunctionPointer {
unsafe { sys::vulkan::SDL_Vulkan_GetVkGetInstanceProcAddr() }
}

/// Get the current system theme.
#[doc(alias = "SDL_GetSystemTheme")]
pub fn get_system_theme() -> SystemTheme {
unsafe {
match SDL_GetSystemTheme() {
SDL_SYSTEM_THEME_DARK => SystemTheme::Dark,
SDL_SYSTEM_THEME_LIGHT => SystemTheme::Light,
SDL_SYSTEM_THEME_UNKNOWN => SystemTheme::Unknown,
_ => unreachable!(),
}
}
}
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit f38ece8

Please sign in to comment.