Skip to content

Commit

Permalink
Add system theme to RawInput
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Jun 30, 2024
1 parent 7c6c0e1 commit 3e7bb2c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use epaint::ColorImage;

use crate::{emath::*, Key, ViewportId, ViewportIdMap};
use crate::{emath::*, Key, Theme, ViewportId, ViewportIdMap};

/// What the integrations provides to egui at the start of each frame.
///
Expand Down Expand Up @@ -73,6 +73,11 @@ pub struct RawInput {
///
/// False when the user alt-tab away from the application, for instance.
pub focused: bool,

/// Does the OS use dark or light mode?
///
/// `None` means "don't know".
pub system_theme: Option<Theme>,
}

impl Default for RawInput {
Expand All @@ -89,6 +94,7 @@ impl Default for RawInput {
hovered_files: Default::default(),
dropped_files: Default::default(),
focused: true, // integrations opt into global focus tracking
system_theme: None,
}
}
}
Expand Down Expand Up @@ -117,6 +123,7 @@ impl RawInput {
hovered_files: self.hovered_files.clone(),
dropped_files: std::mem::take(&mut self.dropped_files),
focused: self.focused,
system_theme: self.system_theme.clone(),
}
}

Expand All @@ -134,6 +141,7 @@ impl RawInput {
mut hovered_files,
mut dropped_files,
focused,
system_theme,
} = newer;

self.viewport_id = viewport_ids;
Expand All @@ -147,6 +155,7 @@ impl RawInput {
self.hovered_files.append(&mut hovered_files);
self.dropped_files.append(&mut dropped_files);
self.focused = focused;
self.system_theme = system_theme;
}
}

Expand Down Expand Up @@ -1038,6 +1047,7 @@ impl RawInput {
hovered_files,
dropped_files,
focused,
system_theme,
} = self;

ui.label(format!("Active viwport: {viewport_id:?}"));
Expand All @@ -1062,6 +1072,7 @@ impl RawInput {
ui.label(format!("hovered_files: {}", hovered_files.len()));
ui.label(format!("dropped_files: {}", dropped_files.len()));
ui.label(format!("focused: {focused}"));
ui.label(format!("system_theme: {system_theme:?}"));
ui.scope(|ui| {
ui.set_min_height(150.0);
ui.label(format!("events: {events:#?}"))
Expand Down

0 comments on commit 3e7bb2c

Please sign in to comment.