summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/multi_window_panes/src/main.rs41
-rw-r--r--src/multi_window/application.rs7
-rw-r--r--winit/src/multi_window.rs2
-rw-r--r--winit/src/multi_window/state.rs4
4 files changed, 35 insertions, 19 deletions
diff --git a/examples/multi_window_panes/src/main.rs b/examples/multi_window_panes/src/main.rs
index b8b63769..b1d0a3bc 100644
--- a/examples/multi_window_panes/src/main.rs
+++ b/examples/multi_window_panes/src/main.rs
@@ -1,5 +1,4 @@
use iced::alignment::{self, Alignment};
-use iced::{executor, time};
use iced::keyboard;
use iced::multi_window::Application;
use iced::theme::{self, Theme};
@@ -8,6 +7,7 @@ use iced::widget::{
button, column, container, pick_list, row, scrollable, text, text_input,
};
use iced::window;
+use iced::{executor, time};
use iced::{Color, Command, Element, Length, Settings, Size, Subscription};
use iced_lazy::responsive;
use iced_native::{event, subscription, Event};
@@ -34,6 +34,7 @@ struct Example {
struct Window {
title: String,
scale: f64,
+ theme: Theme,
panes: pane_grid::State<Pane>,
focus: Option<pane_grid::Pane>,
}
@@ -77,6 +78,7 @@ impl Application for Example {
focus: None,
title: String::from("Default window"),
scale: 1.0,
+ theme: Theme::default(),
};
(
@@ -167,7 +169,10 @@ impl Application for Example {
let _ = self.windows.remove(&id);
return window::close(id);
}
- WindowMessage::Resized(pane_grid::ResizeEvent { split, ratio }) => {
+ WindowMessage::Resized(pane_grid::ResizeEvent {
+ split,
+ ratio,
+ }) => {
let window = self.windows.get_mut(&id).unwrap();
window.panes.resize(&split, ratio);
}
@@ -177,7 +182,8 @@ impl Application for Example {
pane.is_moving = false;
if let Some(window) = self.windows.get_mut(&selected.0) {
- let (&first_pane, _) = window.panes.iter().next().unwrap();
+ let (&first_pane, _) =
+ window.panes.iter().next().unwrap();
let result =
window.panes.split(pane.axis, &first_pane, pane);
@@ -205,8 +211,16 @@ impl Application for Example {
let window = Window {
panes,
focus: None,
- title: format!("New window ({})", self.windows.len()),
+ title: format!(
+ "New window ({})",
+ self.windows.len()
+ ),
scale: 1.0 + (self.windows.len() as f64 / 10.0),
+ theme: if self.windows.len() % 2 == 0 {
+ Theme::Light
+ } else {
+ Theme::Dark
+ },
};
let window_id = window::Id::new(self.windows.len());
@@ -215,15 +229,12 @@ impl Application for Example {
}
}
WindowMessage::Dragged(pane_grid::DragEvent::Dropped {
- pane,
- target,
- }) => {
+ pane,
+ target,
+ }) => {
let window = self.windows.get_mut(&id).unwrap();
window.panes.swap(&pane, &target);
}
- // WindowMessage::Dragged(pane_grid::DragEvent::Picked { pane }) => {
- // println!("Picked {pane:?}");
- // }
WindowMessage::Dragged(_) => {}
WindowMessage::TogglePin(pane) => {
let window = self.windows.get_mut(&id).unwrap();
@@ -273,9 +284,9 @@ impl Application for Example {
match event {
Event::Keyboard(keyboard::Event::KeyPressed {
- modifiers,
- key_code,
- }) if modifiers.command() => {
+ modifiers,
+ key_code,
+ }) if modifiers.command() => {
handle_hotkey(key_code).map(|message| {
Message::Window(window::Id::new(0usize), message)
})
@@ -391,6 +402,10 @@ impl Application for Example {
fn scale_factor(&self, window: Id) -> f64 {
self.windows.get(&window).map(|w| w.scale).unwrap_or(1.0)
}
+
+ fn theme(&self, window: Id) -> Theme {
+ self.windows.get(&window).expect("Window not found!").theme.clone()
+ }
}
const PANE_ID_COLOR_UNFOCUSED: Color = Color::from_rgb(
diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs
index 1fb4bcd4..9974128c 100644
--- a/src/multi_window/application.rs
+++ b/src/multi_window/application.rs
@@ -107,7 +107,8 @@ pub trait Application: Sized {
/// Returns the current [`Theme`] of the [`Application`].
///
/// [`Theme`]: Self::Theme
- fn theme(&self) -> Self::Theme {
+ #[allow(unused_variables)]
+ fn theme(&self, window: window::Id) -> Self::Theme {
Self::Theme::default()
}
@@ -229,8 +230,8 @@ where
self.0.title(window)
}
- fn theme(&self) -> A::Theme {
- self.0.theme()
+ fn theme(&self, window: window::Id) -> A::Theme {
+ self.0.theme(window)
}
fn style(&self) -> <A::Theme as StyleSheet>::Style {
diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs
index 6e28f1fa..9b395c1d 100644
--- a/winit/src/multi_window.rs
+++ b/winit/src/multi_window.rs
@@ -112,7 +112,7 @@ where
fn title(&self, window: window::Id) -> String;
/// Returns the current [`Theme`] of the [`Application`].
- fn theme(&self) -> <Self::Renderer as crate::Renderer>::Theme;
+ fn theme(&self, window: window::Id) -> <Self::Renderer as crate::Renderer>::Theme;
/// Returns the [`Style`] variation of the [`Theme`].
fn style(
diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs
index d0e442d0..54a114ad 100644
--- a/winit/src/multi_window/state.rs
+++ b/winit/src/multi_window/state.rs
@@ -37,7 +37,7 @@ where
) -> Self {
let title = application.title(window_id);
let scale_factor = application.scale_factor(window_id);
- let theme = application.theme();
+ let theme = application.theme(window_id);
let appearance = theme.appearance(&application.style());
let viewport = {
@@ -212,7 +212,7 @@ where
}
// Update theme and appearance
- self.theme = application.theme();
+ self.theme = application.theme(window_id);
self.appearance = self.theme.appearance(&application.style());
}
}