summaryrefslogtreecommitdiffstats
path: root/winit/src/multi_window
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-03-08 14:00:28 +0100
committerLibravatar GitHub <noreply@github.com>2024-03-08 14:00:28 +0100
commitedf7d7ca7593f660f4b15f154257471c26df87de (patch)
tree7cee3cbfbeb2ae5145f1bf6087b61fce4cbed8c9 /winit/src/multi_window
parent2074757cdc65ec16eeb1c7a12a5ff3bb5ed00859 (diff)
parent8919f2593e39f76b273513e959fa6d5ffb78fde2 (diff)
downloadiced-edf7d7ca7593f660f4b15f154257471c26df87de.tar.gz
iced-edf7d7ca7593f660f4b15f154257471c26df87de.tar.bz2
iced-edf7d7ca7593f660f4b15f154257471c26df87de.zip
Merge pull request #2312 from iced-rs/theming-reloaded
Theming reloaded
Diffstat (limited to '')
-rw-r--r--winit/src/multi_window.rs21
-rw-r--r--winit/src/multi_window/state.rs16
-rw-r--r--winit/src/multi_window/window_manager.rs13
3 files changed, 24 insertions, 26 deletions
diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs
index 49d4b8e8..18db1fb5 100644
--- a/winit/src/multi_window.rs
+++ b/winit/src/multi_window.rs
@@ -22,9 +22,10 @@ use crate::runtime::command::{self, Command};
use crate::runtime::multi_window::Program;
use crate::runtime::user_interface::{self, UserInterface};
use crate::runtime::Debug;
-use crate::style::application::StyleSheet;
use crate::{Clipboard, Error, Proxy, Settings};
+pub use crate::application::{default, Appearance, DefaultStyle};
+
use std::collections::HashMap;
use std::mem::ManuallyDrop;
use std::sync::Arc;
@@ -43,7 +44,7 @@ use std::time::Instant;
/// can be toggled by pressing `F12`.
pub trait Application: Program
where
- Self::Theme: StyleSheet,
+ Self::Theme: DefaultStyle,
{
/// The data needed to initialize your [`Application`].
type Flags;
@@ -68,8 +69,8 @@ where
fn theme(&self, window: window::Id) -> Self::Theme;
/// Returns the `Style` variation of the `Theme`.
- fn style(&self) -> <Self::Theme as StyleSheet>::Style {
- Default::default()
+ fn style(&self, theme: &Self::Theme) -> Appearance {
+ theme.default_style()
}
/// Returns the event `Subscription` for the current state of the
@@ -110,7 +111,7 @@ where
A: Application + 'static,
E: Executor + 'static,
C: Compositor<Renderer = A::Renderer> + 'static,
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
use winit::event_loop::EventLoopBuilder;
@@ -352,7 +353,7 @@ async fn run_instance<A, E, C>(
A: Application + 'static,
E: Executor + 'static,
C: Compositor<Renderer = A::Renderer> + 'static,
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
use winit::event;
use winit::event_loop::ControlFlow;
@@ -822,7 +823,7 @@ fn build_user_interface<'a, A: Application>(
id: window::Id,
) -> UserInterface<'a, A::Message, A::Theme, A::Renderer>
where
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
debug.view_started();
let view = application.view(id);
@@ -850,7 +851,7 @@ fn update<A: Application, C, E: Executor>(
ui_caches: &mut HashMap<window::Id, user_interface::Cache>,
) where
C: Compositor<Renderer = A::Renderer> + 'static,
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
for message in messages.drain(..) {
debug.log_message(&message);
@@ -893,7 +894,7 @@ fn run_command<A, C, E>(
A: Application,
E: Executor,
C: Compositor<Renderer = A::Renderer> + 'static,
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
use crate::runtime::clipboard;
use crate::runtime::system;
@@ -1219,8 +1220,8 @@ pub fn build_user_interfaces<'a, A: Application, C: Compositor>(
mut cached_user_interfaces: HashMap<window::Id, user_interface::Cache>,
) -> HashMap<window::Id, UserInterface<'a, A::Message, A::Theme, A::Renderer>>
where
- A::Theme: StyleSheet,
C: Compositor<Renderer = A::Renderer>,
+ A::Theme: DefaultStyle,
{
cached_user_interfaces
.drain()
diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs
index 2e97a13d..dfd8e696 100644
--- a/winit/src/multi_window/state.rs
+++ b/winit/src/multi_window/state.rs
@@ -2,18 +2,16 @@ use crate::conversion;
use crate::core::{mouse, window};
use crate::core::{Color, Size};
use crate::graphics::Viewport;
-use crate::multi_window::Application;
-use crate::style::application;
+use crate::multi_window::{self, Application};
use std::fmt::{Debug, Formatter};
-use iced_style::application::StyleSheet;
use winit::event::{Touch, WindowEvent};
use winit::window::Window;
/// The state of a multi-windowed [`Application`].
pub struct State<A: Application>
where
- A::Theme: application::StyleSheet,
+ A::Theme: multi_window::DefaultStyle,
{
title: String,
scale_factor: f64,
@@ -22,12 +20,12 @@ where
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
modifiers: winit::keyboard::ModifiersState,
theme: A::Theme,
- appearance: application::Appearance,
+ appearance: multi_window::Appearance,
}
impl<A: Application> Debug for State<A>
where
- A::Theme: application::StyleSheet,
+ A::Theme: multi_window::DefaultStyle,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("multi_window::State")
@@ -43,7 +41,7 @@ where
impl<A: Application> State<A>
where
- A::Theme: application::StyleSheet,
+ A::Theme: multi_window::DefaultStyle,
{
/// Creates a new [`State`] for the provided [`Application`]'s `window`.
pub fn new(
@@ -54,7 +52,7 @@ where
let title = application.title(window_id);
let scale_factor = application.scale_factor(window_id);
let theme = application.theme(window_id);
- let appearance = theme.appearance(&application.style());
+ let appearance = application.style(&theme);
let viewport = {
let physical_size = window.inner_size();
@@ -236,6 +234,6 @@ where
// Update theme and appearance
self.theme = application.theme(window_id);
- self.appearance = self.theme.appearance(&application.style());
+ self.appearance = application.style(&self.theme);
}
}
diff --git a/winit/src/multi_window/window_manager.rs b/winit/src/multi_window/window_manager.rs
index 23f3c0ba..71c1688b 100644
--- a/winit/src/multi_window/window_manager.rs
+++ b/winit/src/multi_window/window_manager.rs
@@ -2,8 +2,7 @@ use crate::core::mouse;
use crate::core::window::Id;
use crate::core::{Point, Size};
use crate::graphics::Compositor;
-use crate::multi_window::{Application, State};
-use crate::style::application::StyleSheet;
+use crate::multi_window::{Application, DefaultStyle, State};
use std::collections::BTreeMap;
use std::sync::Arc;
@@ -12,8 +11,8 @@ use winit::monitor::MonitorHandle;
#[allow(missing_debug_implementations)]
pub struct WindowManager<A: Application, C: Compositor>
where
- A::Theme: StyleSheet,
C: Compositor<Renderer = A::Renderer>,
+ A::Theme: DefaultStyle,
{
aliases: BTreeMap<winit::window::WindowId, Id>,
entries: BTreeMap<Id, Window<A, C>>,
@@ -23,7 +22,7 @@ impl<A, C> WindowManager<A, C>
where
A: Application,
C: Compositor<Renderer = A::Renderer>,
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
pub fn new() -> Self {
Self {
@@ -109,7 +108,7 @@ impl<A, C> Default for WindowManager<A, C>
where
A: Application,
C: Compositor<Renderer = A::Renderer>,
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
fn default() -> Self {
Self::new()
@@ -121,7 +120,7 @@ pub struct Window<A, C>
where
A: Application,
C: Compositor<Renderer = A::Renderer>,
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
pub raw: Arc<winit::window::Window>,
pub state: State<A>,
@@ -136,7 +135,7 @@ impl<A, C> Window<A, C>
where
A: Application,
C: Compositor<Renderer = A::Renderer>,
- A::Theme: StyleSheet,
+ A::Theme: DefaultStyle,
{
pub fn position(&self) -> Option<Point> {
self.raw