Simplify theming for Application
This commit is contained in:
parent
34e7c6593a
commit
7c4bf70023
14 changed files with 382 additions and 392 deletions
|
|
@ -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,
|
||||
multi_window::Style<A::Theme>: Default,
|
||||
{
|
||||
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,
|
||||
multi_window::Style<A::Theme>: Default,
|
||||
{
|
||||
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,
|
||||
multi_window::Style<A::Theme>: Default,
|
||||
{
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, State, Style};
|
||||
|
||||
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>,
|
||||
Style<A::Theme>: Default,
|
||||
{
|
||||
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,
|
||||
Style<A::Theme>: Default,
|
||||
{
|
||||
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,
|
||||
Style<A::Theme>: Default,
|
||||
{
|
||||
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,
|
||||
Style<A::Theme>: Default,
|
||||
{
|
||||
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,
|
||||
Style<A::Theme>: Default,
|
||||
{
|
||||
pub fn position(&self) -> Option<Point> {
|
||||
self.raw
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue