summaryrefslogtreecommitdiffstats
path: root/winit/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-11 16:45:08 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-11 16:45:08 +0200
commit669f7cc74b2e7918e86a8197916f503f2d3d9b93 (patch)
treeacb365358235be6ce115b50db9404d890b6e77a6 /winit/src
parentbc62013b6cde52174bf4c4286939cf170bfa7760 (diff)
parent63d3fc6996b848e10e77e6924bfebdf6ba82852e (diff)
downloadiced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.tar.gz
iced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.tar.bz2
iced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.zip
Merge pull request #1830 from iced-rs/advanced-text
Advanced text
Diffstat (limited to 'winit/src')
-rw-r--r--winit/src/application.rs116
-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/settings.rs11
-rw-r--r--winit/src/system.rs7
-rw-r--r--winit/src/window.rs113
10 files changed, 92 insertions, 215 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index dd345785..3d7c6e5d 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;
@@ -282,28 +282,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);
@@ -323,7 +320,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,
@@ -367,8 +364,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()
@@ -418,7 +417,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(
@@ -449,17 +448,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)
}
},
@@ -471,9 +467,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,
)),
@@ -622,7 +618,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();
@@ -663,7 +659,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")]
@@ -695,7 +691,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`].
@@ -715,11 +711,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 {
@@ -777,7 +773,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
@@ -829,7 +825,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,
@@ -858,6 +854,16 @@ pub fn run_command<A, E>(
current_cache = user_interface.into_cache();
*cache = current_cache;
}
+ command::Action::LoadFont { bytes, tagger } => {
+ use crate::core::text::Renderer;
+
+ // TODO: Error handling (?)
+ renderer.load_font(bytes);
+
+ proxy
+ .send_event(tagger(Ok(())))
+ .expect("Send message to event loop");
+ }
}
}
}
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 e416c073..a9262184 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.9/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 6b6c6045..9f6bcebb 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/settings.rs b/winit/src/settings.rs
index 6658773d..be0ab329 100644
--- a/winit/src/settings.rs
+++ b/winit/src/settings.rs
@@ -22,6 +22,7 @@ mod platform;
pub use platform::PlatformSpecific;
use crate::conversion;
+use crate::core::window::Icon;
use crate::Position;
use winit::monitor::MonitorHandle;
@@ -51,14 +52,6 @@ pub struct Settings<Flags> {
///
/// [`Application`]: crate::Application
pub exit_on_close_request: bool,
-
- /// Whether the [`Application`] should try to build the context
- /// using OpenGL ES first then OpenGL.
- ///
- /// NOTE: Only works for the `glow` backend.
- ///
- /// [`Application`]: crate::Application
- pub try_opengles_first: bool,
}
/// The window settings of an application.
@@ -92,7 +85,7 @@ pub struct Window {
pub always_on_top: bool,
/// The window icon, which is also usually used in the taskbar
- pub icon: Option<crate::window::Icon>,
+ pub icon: Option<Icon>,
/// Platform specific settings.
pub platform_specific: platform::PlatformSpecific,
diff --git a/winit/src/system.rs b/winit/src/system.rs
index 8d8b018c..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>(
diff --git a/winit/src/window.rs b/winit/src/window.rs
deleted file mode 100644
index ba0180c8..00000000
--- a/winit/src/window.rs
+++ /dev/null
@@ -1,113 +0,0 @@
-//! Interact with the window of your application.
-use crate::command::{self, Command};
-use iced_native::window;
-
-pub use window::{
- frames, icon, Event, Icon, Mode, RedrawRequest, UserAttention,
-};
-
-/// Closes the current window and exits the application.
-pub fn close<Message>() -> Command<Message> {
- Command::single(command::Action::Window(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))
-}
-
-/// 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,
- }))
-}
-
-/// Maximizes the window.
-pub fn maximize<Message>(maximized: bool) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Maximize(
- maximized,
- )))
-}
-
-/// Minimes the window.
-pub fn minimize<Message>(minimized: bool) -> Command<Message> {
- Command::single(command::Action::Window(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 }))
-}
-
-/// Sets the [`Mode`] of the window.
-pub fn change_mode<Message>(mode: Mode) -> Command<Message> {
- Command::single(command::Action::Window(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),
- )))
-}
-
-/// Toggles the window to maximized or back.
-pub fn toggle_maximize<Message>() -> Command<Message> {
- Command::single(command::Action::Window(window::Action::ToggleMaximize))
-}
-
-/// Toggles the window decorations.
-pub fn toggle_decorations<Message>() -> Command<Message> {
- Command::single(command::Action::Window(window::Action::ToggleDecorations))
-}
-
-/// Request user attention to the window, this has no effect if the application
-/// is already focused. How requesting for user attention manifests is platform dependent,
-/// see [`UserAttention`] for details.
-///
-/// Providing `None` will unset the request for user attention. Unsetting the request for
-/// user attention might not be done automatically by the WM when the window receives input.
-pub fn request_user_attention<Message>(
- user_attention: Option<UserAttention>,
-) -> Command<Message> {
- Command::single(command::Action::Window(
- window::Action::RequestUserAttention(user_attention),
- ))
-}
-
-/// Brings the window to the front and sets input focus. Has no effect if the window is
-/// already in focus, minimized, or not visible.
-///
-/// This [`Command`] steals input focus from other applications. Do not use this method unless
-/// 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))
-}
-
-/// 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,
- )))
-}
-
-/// 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,
- ))))
-}
-
-/// Changes the [`Icon`] of the window.
-pub fn change_icon<Message>(icon: Icon) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::ChangeIcon(icon)))
-}