-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds support for theming on macOS and also unifies the system theme handling across platforms.
- Loading branch information
Showing
20 changed files
with
256 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![allow(clippy::single_match)] | ||
|
||
use simple_logger::SimpleLogger; | ||
use winit::{ | ||
event::{Event, WindowEvent}, | ||
event_loop::{ControlFlow, EventLoop}, | ||
window::{Theme, WindowBuilder}, | ||
}; | ||
|
||
fn main() { | ||
SimpleLogger::new().init().unwrap(); | ||
let event_loop = EventLoop::new(); | ||
|
||
let window = WindowBuilder::new() | ||
.with_title("A fantastic window!") | ||
.with_theme(Some(Theme::Dark)) | ||
.build(&event_loop) | ||
.unwrap(); | ||
|
||
println!("Initial theme: {:?}", window.theme()); | ||
|
||
event_loop.run(move |event, _, control_flow| { | ||
*control_flow = ControlFlow::Wait; | ||
|
||
match event { | ||
Event::WindowEvent { | ||
event: WindowEvent::CloseRequested, | ||
.. | ||
} => *control_flow = ControlFlow::Exit, | ||
Event::WindowEvent { | ||
event: WindowEvent::ThemeChanged(theme), | ||
window_id, | ||
.. | ||
} if window_id == window.id() => { | ||
println!("Theme is changed: {:?}", theme) | ||
} | ||
_ => (), | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use objc2::foundation::{NSArray, NSObject, NSString}; | ||
use objc2::rc::{Id, Shared}; | ||
use objc2::{extern_class, extern_methods, msg_send_id, ClassType}; | ||
|
||
extern_class!( | ||
#[derive(Debug, PartialEq, Eq, Hash)] | ||
pub(crate) struct NSAppearance; | ||
|
||
unsafe impl ClassType for NSAppearance { | ||
type Super = NSObject; | ||
} | ||
); | ||
|
||
type NSAppearanceName = NSString; | ||
|
||
extern_methods!( | ||
unsafe impl NSAppearance { | ||
pub fn appearanceNamed(name: &NSAppearanceName) -> Id<Self, Shared> { | ||
unsafe { msg_send_id![Self::class(), appearanceNamed: name] } | ||
} | ||
|
||
pub fn bestMatchFromAppearancesWithNames( | ||
&self, | ||
appearances: &NSArray<NSAppearanceName>, | ||
) -> Id<NSAppearanceName, Shared> { | ||
unsafe { msg_send_id![self, bestMatchFromAppearancesWithNames: appearances,] } | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.