summaryrefslogtreecommitdiffstats
path: root/winit/src/program
diff options
context:
space:
mode:
Diffstat (limited to 'winit/src/program')
-rw-r--r--winit/src/program/state.rs32
-rw-r--r--winit/src/program/window_manager.rs31
2 files changed, 42 insertions, 21 deletions
diff --git a/winit/src/program/state.rs b/winit/src/program/state.rs
index a7fa2788..e883d04a 100644
--- a/winit/src/program/state.rs
+++ b/winit/src/program/state.rs
@@ -1,17 +1,18 @@
use crate::conversion;
-use crate::core::{mouse, window};
+use crate::core::{mouse, theme, window};
use crate::core::{Color, Size};
use crate::graphics::Viewport;
-use crate::program::{self, Program};
-use std::fmt::{Debug, Formatter};
+use crate::program::Program;
use winit::event::{Touch, WindowEvent};
use winit::window::Window;
+use std::fmt::{Debug, Formatter};
+
/// The state of a multi-windowed [`Program`].
pub struct State<P: Program>
where
- P::Theme: program::DefaultStyle,
+ P::Theme: theme::Base,
{
title: String,
scale_factor: f64,
@@ -20,12 +21,12 @@ where
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
modifiers: winit::keyboard::ModifiersState,
theme: P::Theme,
- appearance: program::Appearance,
+ style: theme::Style,
}
impl<P: Program> Debug for State<P>
where
- P::Theme: program::DefaultStyle,
+ P::Theme: theme::Base,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("multi_window::State")
@@ -34,14 +35,14 @@ where
.field("viewport", &self.viewport)
.field("viewport_version", &self.viewport_version)
.field("cursor_position", &self.cursor_position)
- .field("appearance", &self.appearance)
+ .field("style", &self.style)
.finish()
}
}
impl<P: Program> State<P>
where
- P::Theme: program::DefaultStyle,
+ P::Theme: theme::Base,
{
/// Creates a new [`State`] for the provided [`Program`]'s `window`.
pub fn new(
@@ -52,7 +53,7 @@ where
let title = application.title(window_id);
let scale_factor = application.scale_factor(window_id);
let theme = application.theme(window_id);
- let appearance = application.style(&theme);
+ let style = application.style(&theme);
let viewport = {
let physical_size = window.inner_size();
@@ -71,7 +72,7 @@ where
cursor_position: None,
modifiers: winit::keyboard::ModifiersState::default(),
theme,
- appearance,
+ style,
}
}
@@ -127,12 +128,12 @@ where
/// Returns the current background [`Color`] of the [`State`].
pub fn background_color(&self) -> Color {
- self.appearance.background_color
+ self.style.background_color
}
/// Returns the current text [`Color`] of the [`State`].
pub fn text_color(&self) -> Color {
- self.appearance.text_color
+ self.style.text_color
}
/// Processes the provided window event and updates the [`State`] accordingly.
@@ -190,7 +191,10 @@ where
..
},
..
- } => _debug.toggle(),
+ } => {
+ _debug.toggle();
+ window.request_redraw();
+ }
_ => {}
}
}
@@ -234,6 +238,6 @@ where
// Update theme and appearance
self.theme = application.theme(window_id);
- self.appearance = application.style(&self.theme);
+ self.style = application.style(&self.theme);
}
}
diff --git a/winit/src/program/window_manager.rs b/winit/src/program/window_manager.rs
index 3d22e155..a3c991df 100644
--- a/winit/src/program/window_manager.rs
+++ b/winit/src/program/window_manager.rs
@@ -1,8 +1,10 @@
use crate::core::mouse;
+use crate::core::theme;
+use crate::core::time::Instant;
use crate::core::window::Id;
use crate::core::{Point, Size};
use crate::graphics::Compositor;
-use crate::program::{DefaultStyle, Program, State};
+use crate::program::{Program, State};
use std::collections::BTreeMap;
use std::sync::Arc;
@@ -13,7 +15,7 @@ pub struct WindowManager<P, C>
where
P: Program,
C: Compositor<Renderer = P::Renderer>,
- P::Theme: DefaultStyle,
+ P::Theme: theme::Base,
{
aliases: BTreeMap<winit::window::WindowId, Id>,
entries: BTreeMap<Id, Window<P, C>>,
@@ -23,7 +25,7 @@ impl<P, C> WindowManager<P, C>
where
P: Program,
C: Compositor<Renderer = P::Renderer>,
- P::Theme: DefaultStyle,
+ P::Theme: theme::Base,
{
pub fn new() -> Self {
Self {
@@ -62,6 +64,7 @@ where
surface,
renderer,
mouse_interaction: mouse::Interaction::None,
+ redraw_at: None,
},
);
@@ -74,6 +77,19 @@ where
self.entries.is_empty()
}
+ pub fn is_idle(&self) -> bool {
+ self.entries
+ .values()
+ .all(|window| window.redraw_at.is_none())
+ }
+
+ pub fn redraw_at(&self) -> Option<Instant> {
+ self.entries
+ .values()
+ .filter_map(|window| window.redraw_at)
+ .min()
+ }
+
pub fn first(&self) -> Option<&Window<P, C>> {
self.entries.first_key_value().map(|(_id, window)| window)
}
@@ -117,7 +133,7 @@ impl<P, C> Default for WindowManager<P, C>
where
P: Program,
C: Compositor<Renderer = P::Renderer>,
- P::Theme: DefaultStyle,
+ P::Theme: theme::Base,
{
fn default() -> Self {
Self::new()
@@ -129,7 +145,7 @@ pub struct Window<P, C>
where
P: Program,
C: Compositor<Renderer = P::Renderer>,
- P::Theme: DefaultStyle,
+ P::Theme: theme::Base,
{
pub raw: Arc<winit::window::Window>,
pub state: State<P>,
@@ -138,17 +154,18 @@ where
pub mouse_interaction: mouse::Interaction,
pub surface: C::Surface,
pub renderer: P::Renderer,
+ pub redraw_at: Option<Instant>,
}
impl<P, C> Window<P, C>
where
P: Program,
C: Compositor<Renderer = P::Renderer>,
- P::Theme: DefaultStyle,
+ P::Theme: theme::Base,
{
pub fn position(&self) -> Option<Point> {
self.raw
- .inner_position()
+ .outer_position()
.ok()
.map(|position| position.to_logical(self.raw.scale_factor()))
.map(|position| Point {