summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-03-09 19:05:38 +0100
committerLibravatar GitHub <noreply@github.com>2023-03-09 19:05:38 +0100
commitcaf2836b1b15bff6e8a2ea72441d67f297eb8707 (patch)
tree0ffa0d1d604780999892b88de85ee93e3ed7d539 /winit
parent11b2c3bbe31a43e73a61b9bd9f022233f302ae27 (diff)
parent424ac8177309440bbd8efe0dd9f7622cb10807ce (diff)
downloadiced-caf2836b1b15bff6e8a2ea72441d67f297eb8707.tar.gz
iced-caf2836b1b15bff6e8a2ea72441d67f297eb8707.tar.bz2
iced-caf2836b1b15bff6e8a2ea72441d67f297eb8707.zip
Merge pull request #1748 from iced-rs/feature/software-renderer
Software renderer, runtime renderer fallback, and core consolidation
Diffstat (limited to '')
-rw-r--r--runtime/src/window.rs (renamed from winit/src/window.rs)70
-rw-r--r--winit/Cargo.toml14
-rw-r--r--winit/src/application.rs110
-rw-r--r--winit/src/application/state.rs14
-rw-r--r--winit/src/clipboard.rs17
-rw-r--r--winit/src/conversion.rs11
-rw-r--r--winit/src/error.rs7
-rw-r--r--winit/src/lib.rs9
-rw-r--r--winit/src/proxy.rs2
-rw-r--r--winit/src/system.rs11
10 files changed, 129 insertions, 136 deletions
diff --git a/winit/src/window.rs b/runtime/src/window.rs
index 961562bd..236064f7 100644
--- a/winit/src/window.rs
+++ b/runtime/src/window.rs
@@ -1,68 +1,78 @@
-//! Interact with the window of your application.
+//! Build window-based GUI applications.
+mod action;
+
+pub use action::Action;
+
use crate::command::{self, Command};
-use iced_native::window;
+use crate::core::time::Instant;
+use crate::core::window::{Event, Mode, UserAttention};
+use crate::futures::subscription::{self, Subscription};
-pub use window::{frames, Event, Mode, RedrawRequest, UserAttention};
+/// Subscribes to the frames of the window of the running application.
+///
+/// The resulting [`Subscription`] will produce items at a rate equal to the
+/// refresh rate of the window. Note that this rate may be variable, as it is
+/// normally managed by the graphics driver and/or the OS.
+///
+/// In any case, this [`Subscription`] is useful to smoothly draw application-driven
+/// animations without missing any frames.
+pub fn frames() -> Subscription<Instant> {
+ subscription::raw_events(|event, _status| match event {
+ iced_core::Event::Window(Event::RedrawRequested(at)) => Some(at),
+ _ => None,
+ })
+}
/// Closes the current window and exits the application.
pub fn close<Message>() -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Close))
+ Command::single(command::Action::Window(Action::Close))
}
/// Begins dragging the window while the left mouse button is held.
pub fn drag<Message>() -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Drag))
+ Command::single(command::Action::Window(Action::Drag))
}
/// Resizes the window to the given logical dimensions.
pub fn resize<Message>(width: u32, height: u32) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Resize {
- width,
- height,
- }))
+ Command::single(command::Action::Window(Action::Resize { width, height }))
}
/// Maximizes the window.
pub fn maximize<Message>(maximized: bool) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Maximize(
- maximized,
- )))
+ Command::single(command::Action::Window(Action::Maximize(maximized)))
}
/// Minimes the window.
pub fn minimize<Message>(minimized: bool) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Minimize(
- minimized,
- )))
+ Command::single(command::Action::Window(Action::Minimize(minimized)))
}
/// Moves a window to the given logical coordinates.
pub fn move_to<Message>(x: i32, y: i32) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Move { x, y }))
+ Command::single(command::Action::Window(Action::Move { x, y }))
}
/// Sets the [`Mode`] of the window.
pub fn change_mode<Message>(mode: Mode) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::ChangeMode(mode)))
+ Command::single(command::Action::Window(Action::ChangeMode(mode)))
}
/// Fetches the current [`Mode`] of the window.
pub fn fetch_mode<Message>(
f: impl FnOnce(Mode) -> Message + 'static,
) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::FetchMode(
- Box::new(f),
- )))
+ Command::single(command::Action::Window(Action::FetchMode(Box::new(f))))
}
/// Toggles the window to maximized or back.
pub fn toggle_maximize<Message>() -> Command<Message> {
- Command::single(command::Action::Window(window::Action::ToggleMaximize))
+ Command::single(command::Action::Window(Action::ToggleMaximize))
}
/// Toggles the window decorations.
pub fn toggle_decorations<Message>() -> Command<Message> {
- Command::single(command::Action::Window(window::Action::ToggleDecorations))
+ Command::single(command::Action::Window(Action::ToggleDecorations))
}
/// Request user attention to the window, this has no effect if the application
@@ -74,9 +84,9 @@ pub fn toggle_decorations<Message>() -> Command<Message> {
pub fn request_user_attention<Message>(
user_attention: Option<UserAttention>,
) -> Command<Message> {
- Command::single(command::Action::Window(
- window::Action::RequestUserAttention(user_attention),
- ))
+ Command::single(command::Action::Window(Action::RequestUserAttention(
+ user_attention,
+ )))
}
/// Brings the window to the front and sets input focus. Has no effect if the window is
@@ -86,21 +96,17 @@ pub fn request_user_attention<Message>(
/// you are certain that's what the user wants. Focus stealing can cause an extremely disruptive
/// user experience.
pub fn gain_focus<Message>() -> Command<Message> {
- Command::single(command::Action::Window(window::Action::GainFocus))
+ Command::single(command::Action::Window(Action::GainFocus))
}
/// Changes whether or not the window will always be on top of other windows.
pub fn change_always_on_top<Message>(on_top: bool) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::ChangeAlwaysOnTop(
- on_top,
- )))
+ Command::single(command::Action::Window(Action::ChangeAlwaysOnTop(on_top)))
}
/// Fetches an identifier unique to the window.
pub fn fetch_id<Message>(
f: impl FnOnce(u64) -> Message + 'static,
) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::FetchId(Box::new(
- f,
- ))))
+ Command::single(command::Action::Window(Action::FetchId(Box::new(f))))
}
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index 60e464c6..1bf63804 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -13,7 +13,7 @@ categories = ["gui"]
[features]
trace = ["tracing", "tracing-core", "tracing-subscriber"]
chrome-trace = ["trace", "tracing-chrome"]
-debug = ["iced_native/debug"]
+debug = ["iced_runtime/debug"]
system = ["sysinfo"]
application = []
@@ -27,17 +27,17 @@ version = "0.27"
git = "https://github.com/iced-rs/winit.git"
rev = "940457522e9fb9f5dac228b0ecfafe0138b4048c"
-[dependencies.iced_native]
+[dependencies.iced_runtime]
version = "0.9"
-path = "../native"
+path = "../runtime"
[dependencies.iced_graphics]
version = "0.7"
path = "../graphics"
-[dependencies.iced_futures]
-version = "0.6"
-path = "../futures"
+[dependencies.iced_style]
+version = "0.7"
+path = "../style"
[dependencies.tracing]
version = "0.1.37"
@@ -65,5 +65,5 @@ version = "0.3"
features = ["Document", "Window"]
[dependencies.sysinfo]
-version = "0.23"
+version = "0.28"
optional = true
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 889becad..48f94235 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -5,25 +5,25 @@ mod state;
pub use state::State;
-use crate::clipboard::{self, Clipboard};
use crate::conversion;
-use crate::mouse;
-use crate::renderer;
-use crate::widget::operation;
-use crate::{
- Command, Debug, Error, Event, Executor, Proxy, Runtime, Settings, Size,
- Subscription,
-};
-
-use iced_futures::futures;
-use iced_futures::futures::channel::mpsc;
-use iced_graphics::compositor;
-use iced_graphics::window;
-use iced_native::program::Program;
-use iced_native::time::Instant;
-use iced_native::user_interface::{self, UserInterface};
-
-pub use iced_native::application::{Appearance, StyleSheet};
+use crate::core;
+use crate::core::mouse;
+use crate::core::renderer;
+use crate::core::time::Instant;
+use crate::core::widget::operation;
+use crate::core::window;
+use crate::core::{Event, Size};
+use crate::futures::futures;
+use crate::futures::{Executor, Runtime, Subscription};
+use crate::graphics::compositor::{self, Compositor};
+use crate::runtime::clipboard;
+use crate::runtime::program::Program;
+use crate::runtime::user_interface::{self, UserInterface};
+use crate::runtime::{Command, Debug};
+use crate::style::application::{Appearance, StyleSheet};
+use crate::{Clipboard, Error, Proxy, Settings};
+
+use futures::channel::mpsc;
use std::mem::ManuallyDrop;
@@ -45,7 +45,7 @@ use tracing::{info_span, instrument::Instrument};
/// can be toggled by pressing `F12`.
pub trait Application: Program
where
- <Self::Renderer as crate::Renderer>::Theme: StyleSheet,
+ <Self::Renderer as core::Renderer>::Theme: StyleSheet,
{
/// The data needed to initialize your [`Application`].
type Flags;
@@ -67,12 +67,12 @@ where
fn title(&self) -> String;
/// Returns the current `Theme` of the [`Application`].
- fn theme(&self) -> <Self::Renderer as crate::Renderer>::Theme;
+ fn theme(&self) -> <Self::Renderer as core::Renderer>::Theme;
/// Returns the `Style` variation of the `Theme`.
fn style(
&self,
- ) -> <<Self::Renderer as crate::Renderer>::Theme as StyleSheet>::Style {
+ ) -> <<Self::Renderer as core::Renderer>::Theme as StyleSheet>::Style {
Default::default()
}
@@ -112,8 +112,8 @@ pub fn run<A, E, C>(
where
A: Application + 'static,
E: Executor + 'static,
- C: window::Compositor<Renderer = A::Renderer> + 'static,
- <A::Renderer as crate::Renderer>::Theme: StyleSheet,
+ C: Compositor<Renderer = A::Renderer> + 'static,
+ <A::Renderer as core::Renderer>::Theme: StyleSheet,
{
use futures::task;
use futures::Future;
@@ -278,28 +278,25 @@ async fn run_instance<A, E, C>(
) where
A: Application + 'static,
E: Executor + 'static,
- C: window::Compositor<Renderer = A::Renderer> + 'static,
- <A::Renderer as crate::Renderer>::Theme: StyleSheet,
+ C: Compositor<Renderer = A::Renderer> + 'static,
+ <A::Renderer as core::Renderer>::Theme: StyleSheet,
{
- use iced_futures::futures::stream::StreamExt;
+ use futures::stream::StreamExt;
use winit::event;
use winit::event_loop::ControlFlow;
- let mut clipboard = Clipboard::connect(&window);
- let mut cache = user_interface::Cache::default();
- let mut surface = compositor.create_surface(&window);
- let mut should_exit = false;
-
let mut state = State::new(&application, &window);
let mut viewport_version = state.viewport_version();
-
let physical_size = state.physical_size();
- compositor.configure_surface(
- &mut surface,
+ let mut clipboard = Clipboard::connect(&window);
+ let mut cache = user_interface::Cache::default();
+ let mut surface = compositor.create_surface(
+ &window,
physical_size.width,
physical_size.height,
);
+ let mut should_exit = false;
if should_be_visible {
window.set_visible(true);
@@ -319,7 +316,7 @@ async fn run_instance<A, E, C>(
&window,
|| compositor.fetch_information(),
);
- runtime.track(application.subscription());
+ runtime.track(application.subscription().into_recipes());
let mut user_interface = ManuallyDrop::new(build_user_interface(
&application,
@@ -363,8 +360,10 @@ async fn run_instance<A, E, C>(
debug.event_processing_finished();
- for event in events.drain(..).zip(statuses.into_iter()) {
- runtime.broadcast(event);
+ for (event, status) in
+ events.drain(..).zip(statuses.into_iter())
+ {
+ runtime.broadcast(event, status);
}
if !messages.is_empty()
@@ -414,7 +413,7 @@ async fn run_instance<A, E, C>(
// Then, we can use the `interface_state` here to decide if a redraw
// is needed right away, or simply wait until a specific time.
let redraw_event = Event::Window(
- crate::window::Event::RedrawRequested(Instant::now()),
+ window::Event::RedrawRequested(Instant::now()),
);
let (interface_state, _) = user_interface.update(
@@ -445,17 +444,14 @@ async fn run_instance<A, E, C>(
}
window.request_redraw();
- runtime
- .broadcast((redraw_event, crate::event::Status::Ignored));
+ runtime.broadcast(redraw_event, core::event::Status::Ignored);
let _ = control_sender.start_send(match interface_state {
user_interface::State::Updated {
redraw_request: Some(redraw_request),
} => match redraw_request {
- crate::window::RedrawRequest::NextFrame => {
- ControlFlow::Poll
- }
- crate::window::RedrawRequest::At(at) => {
+ window::RedrawRequest::NextFrame => ControlFlow::Poll,
+ window::RedrawRequest::At(at) => {
ControlFlow::WaitUntil(at)
}
},
@@ -467,9 +463,9 @@ async fn run_instance<A, E, C>(
event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(
event::MacOS::ReceivedUrl(url),
)) => {
- use iced_native::event;
+ use crate::core::event;
- events.push(iced_native::Event::PlatformSpecific(
+ events.push(Event::PlatformSpecific(
event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(
url,
)),
@@ -618,7 +614,7 @@ pub fn build_user_interface<'a, A: Application>(
debug: &mut Debug,
) -> UserInterface<'a, A::Message, A::Renderer>
where
- <A::Renderer as crate::Renderer>::Theme: StyleSheet,
+ <A::Renderer as core::Renderer>::Theme: StyleSheet,
{
#[cfg(feature = "trace")]
let view_span = info_span!("Application", "VIEW").entered();
@@ -659,7 +655,7 @@ pub fn update<A: Application, E: Executor>(
window: &winit::window::Window,
graphics_info: impl FnOnce() -> compositor::Information + Copy,
) where
- <A::Renderer as crate::Renderer>::Theme: StyleSheet,
+ <A::Renderer as core::Renderer>::Theme: StyleSheet,
{
for message in messages.drain(..) {
#[cfg(feature = "trace")]
@@ -691,7 +687,7 @@ pub fn update<A: Application, E: Executor>(
}
let subscription = application.subscription();
- runtime.track(subscription);
+ runtime.track(subscription.into_recipes());
}
/// Runs the actions of a [`Command`].
@@ -711,11 +707,11 @@ pub fn run_command<A, E>(
) where
A: Application,
E: Executor,
- <A::Renderer as crate::Renderer>::Theme: StyleSheet,
+ <A::Renderer as core::Renderer>::Theme: StyleSheet,
{
- use iced_native::command;
- use iced_native::system;
- use iced_native::window;
+ use crate::runtime::command;
+ use crate::runtime::system;
+ use crate::runtime::window;
for action in command.actions() {
match action {
@@ -762,7 +758,7 @@ pub fn run_command<A, E>(
window::Action::ChangeMode(mode) => {
window.set_visible(conversion::visible(mode));
window.set_fullscreen(conversion::fullscreen(
- window.primary_monitor(),
+ window.current_monitor(),
mode,
));
}
@@ -770,7 +766,7 @@ pub fn run_command<A, E>(
let mode = if window.is_visible().unwrap_or(true) {
conversion::mode(window.fullscreen())
} else {
- window::Mode::Hidden
+ core::window::Mode::Hidden
};
proxy
@@ -822,7 +818,7 @@ pub fn run_command<A, E>(
},
command::Action::Widget(action) => {
let mut current_cache = std::mem::take(cache);
- let mut current_operation = Some(action.into_operation());
+ let mut current_operation = Some(action);
let mut user_interface = build_user_interface(
application,
@@ -852,7 +848,7 @@ pub fn run_command<A, E>(
*cache = current_cache;
}
command::Action::LoadFont { bytes, tagger } => {
- use crate::text::Renderer;
+ use crate::core::text::Renderer;
// TODO: Error handling (?)
renderer.load_font(bytes);
diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs
index 8d6a1df1..c37ccca6 100644
--- a/winit/src/application/state.rs
+++ b/winit/src/application/state.rs
@@ -1,6 +1,10 @@
use crate::application::{self, StyleSheet as _};
use crate::conversion;
-use crate::{Application, Color, Debug, Point, Size, Viewport};
+use crate::core;
+use crate::core::{Color, Point, Size};
+use crate::graphics::Viewport;
+use crate::runtime::Debug;
+use crate::Application;
use std::marker::PhantomData;
use winit::event::{Touch, WindowEvent};
@@ -10,7 +14,7 @@ use winit::window::Window;
#[allow(missing_debug_implementations)]
pub struct State<A: Application>
where
- <A::Renderer as crate::Renderer>::Theme: application::StyleSheet,
+ <A::Renderer as core::Renderer>::Theme: application::StyleSheet,
{
title: String,
scale_factor: f64,
@@ -18,14 +22,14 @@ where
viewport_version: usize,
cursor_position: winit::dpi::PhysicalPosition<f64>,
modifiers: winit::event::ModifiersState,
- theme: <A::Renderer as crate::Renderer>::Theme,
+ theme: <A::Renderer as core::Renderer>::Theme,
appearance: application::Appearance,
application: PhantomData<A>,
}
impl<A: Application> State<A>
where
- <A::Renderer as crate::Renderer>::Theme: application::StyleSheet,
+ <A::Renderer as core::Renderer>::Theme: application::StyleSheet,
{
/// Creates a new [`State`] for the provided [`Application`] and window.
pub fn new(application: &A, window: &Window) -> Self {
@@ -98,7 +102,7 @@ where
}
/// Returns the current theme of the [`State`].
- pub fn theme(&self) -> &<A::Renderer as crate::Renderer>::Theme {
+ pub fn theme(&self) -> &<A::Renderer as core::Renderer>::Theme {
&self.theme
}
diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs
index c1fd8813..7271441d 100644
--- a/winit/src/clipboard.rs
+++ b/winit/src/clipboard.rs
@@ -1,7 +1,4 @@
//! Access the clipboard.
-pub use iced_native::clipboard::Action;
-
-use crate::command::{self, Command};
/// A buffer for short-term storage and transfer within and between
/// applications.
@@ -56,7 +53,7 @@ impl Clipboard {
}
}
-impl iced_native::Clipboard for Clipboard {
+impl crate::core::Clipboard for Clipboard {
fn read(&self) -> Option<String> {
self.read()
}
@@ -65,15 +62,3 @@ impl iced_native::Clipboard for Clipboard {
self.write(contents)
}
}
-
-/// Read the current contents of the clipboard.
-pub fn read<Message>(
- f: impl Fn(Option<String>) -> Message + 'static,
-) -> Command<Message> {
- Command::single(command::Action::Clipboard(Action::Read(Box::new(f))))
-}
-
-/// Write the given contents to the clipboard.
-pub fn write<Message>(contents: String) -> Command<Message> {
- Command::single(command::Action::Clipboard(Action::Write(contents)))
-}
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs
index 1b2ead36..0759ad9d 100644
--- a/winit/src/conversion.rs
+++ b/winit/src/conversion.rs
@@ -2,11 +2,12 @@
//!
//! [`winit`]: https://github.com/rust-windowing/winit
//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native
-use crate::keyboard;
-use crate::mouse;
-use crate::touch;
-use crate::window;
-use crate::{Event, Point, Position};
+use crate::core::keyboard;
+use crate::core::mouse;
+use crate::core::touch;
+use crate::core::window;
+use crate::core::{Event, Point};
+use crate::Position;
/// Converts a winit window event into an iced event.
pub fn window_event(
diff --git a/winit/src/error.rs b/winit/src/error.rs
index eaeafd51..7687fb17 100644
--- a/winit/src/error.rs
+++ b/winit/src/error.rs
@@ -1,4 +1,5 @@
-use iced_futures::futures;
+use crate::futures::futures;
+use crate::graphics;
/// An error that occurred while running an application.
#[derive(Debug, thiserror::Error)]
@@ -13,10 +14,10 @@ pub enum Error {
/// The application graphics context could not be created.
#[error("the application graphics context could not be created")]
- GraphicsCreationFailed(iced_graphics::Error),
+ GraphicsCreationFailed(graphics::Error),
}
-impl From<iced_graphics::Error> for Error {
+impl From<graphics::Error> for Error {
fn from(error: iced_graphics::Error) -> Error {
Error::GraphicsCreationFailed(error)
}
diff --git a/winit/src/lib.rs b/winit/src/lib.rs
index 3a33e174..5cde510a 100644
--- a/winit/src/lib.rs
+++ b/winit/src/lib.rs
@@ -30,9 +30,11 @@
#![forbid(rust_2018_idioms, unsafe_code)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_cfg))]
-
-#[doc(no_inline)]
-pub use iced_native::*;
+pub use iced_graphics as graphics;
+pub use iced_runtime as runtime;
+pub use iced_runtime::core;
+pub use iced_runtime::futures;
+pub use iced_style as style;
pub use winit;
#[cfg(feature = "application")]
@@ -40,7 +42,6 @@ pub mod application;
pub mod clipboard;
pub mod conversion;
pub mod settings;
-pub mod window;
#[cfg(feature = "system")]
pub mod system;
diff --git a/winit/src/proxy.rs b/winit/src/proxy.rs
index 7b9074d7..1d6c48bb 100644
--- a/winit/src/proxy.rs
+++ b/winit/src/proxy.rs
@@ -1,4 +1,4 @@
-use iced_native::futures::{
+use crate::futures::futures::{
channel::mpsc,
task::{Context, Poll},
Sink,
diff --git a/winit/src/system.rs b/winit/src/system.rs
index 619086b8..145a4d92 100644
--- a/winit/src/system.rs
+++ b/winit/src/system.rs
@@ -1,8 +1,7 @@
//! Access the native system.
-use crate::command::{self, Command};
-pub use iced_native::system::*;
-
-use iced_graphics::compositor;
+use crate::graphics::compositor;
+use crate::runtime::command::{self, Command};
+use crate::runtime::system::{Action, Information};
/// Query for available system information.
pub fn fetch_information<Message>(
@@ -16,11 +15,11 @@ pub fn fetch_information<Message>(
pub(crate) fn information(
graphics_info: compositor::Information,
) -> Information {
- use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt};
+ use sysinfo::{CpuExt, ProcessExt, System, SystemExt};
let mut system = System::new_all();
system.refresh_all();
- let cpu = system.global_processor_info();
+ let cpu = system.global_cpu_info();
let memory_used = sysinfo::get_current_pid()
.and_then(|pid| system.process(pid).ok_or("Process not found"))