summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Cargo.toml3
-rw-r--r--core/README.md12
-rw-r--r--core/src/element.rs61
-rw-r--r--core/src/event.rs23
-rw-r--r--core/src/keyboard/modifiers.rs24
-rw-r--r--core/src/overlay.rs2
-rw-r--r--core/src/overlay/element.rs60
-rw-r--r--core/src/overlay/group.rs2
-rw-r--r--core/src/widget.rs2
-rw-r--r--core/src/widget/operation.rs10
-rw-r--r--core/src/window/position.rs8
-rw-r--r--core/src/window/settings/windows.rs5
12 files changed, 47 insertions, 165 deletions
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 3c557bca..a1228909 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -33,8 +33,5 @@ web-time.workspace = true
dark-light.workspace = true
dark-light.optional = true
-[target.'cfg(windows)'.dependencies]
-raw-window-handle.workspace = true
-
[dev-dependencies]
approx = "0.5"
diff --git a/core/README.md b/core/README.md
index 519e0608..de11acad 100644
--- a/core/README.md
+++ b/core/README.md
@@ -13,15 +13,3 @@ This crate is meant to be a starting point for an Iced runtime.
</p>
[documentation]: https://docs.rs/iced_core
-
-## Installation
-Add `iced_core` as a dependency in your `Cargo.toml`:
-
-```toml
-iced_core = "0.9"
-```
-
-__Iced moves fast and the `master` branch can contain breaking changes!__ If
-you want to learn about a specific release, check out [the release list].
-
-[the release list]: https://github.com/iced-rs/iced/releases
diff --git a/core/src/element.rs b/core/src/element.rs
index 7d918a2e..385d8295 100644
--- a/core/src/element.rs
+++ b/core/src/element.rs
@@ -10,7 +10,6 @@ use crate::{
Widget,
};
-use std::any::Any;
use std::borrow::Borrow;
/// A generic [`Widget`].
@@ -305,63 +304,9 @@ where
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
- operation: &mut dyn widget::Operation<B>,
+ operation: &mut dyn widget::Operation<()>,
) {
- struct MapOperation<'a, B> {
- operation: &'a mut dyn widget::Operation<B>,
- }
-
- impl<'a, T, B> widget::Operation<T> for MapOperation<'a, B> {
- fn container(
- &mut self,
- id: Option<&widget::Id>,
- bounds: Rectangle,
- operate_on_children: &mut dyn FnMut(
- &mut dyn widget::Operation<T>,
- ),
- ) {
- self.operation.container(id, bounds, &mut |operation| {
- operate_on_children(&mut MapOperation { operation });
- });
- }
-
- fn focusable(
- &mut self,
- state: &mut dyn widget::operation::Focusable,
- id: Option<&widget::Id>,
- ) {
- self.operation.focusable(state, id);
- }
-
- fn scrollable(
- &mut self,
- state: &mut dyn widget::operation::Scrollable,
- id: Option<&widget::Id>,
- bounds: Rectangle,
- translation: Vector,
- ) {
- self.operation.scrollable(state, id, bounds, translation);
- }
-
- fn text_input(
- &mut self,
- state: &mut dyn widget::operation::TextInput,
- id: Option<&widget::Id>,
- ) {
- self.operation.text_input(state, id);
- }
-
- fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) {
- self.operation.custom(state, id);
- }
- }
-
- self.widget.operate(
- tree,
- layout,
- renderer,
- &mut MapOperation { operation },
- );
+ self.widget.operate(tree, layout, renderer, operation);
}
fn on_event(
@@ -495,7 +440,7 @@ where
state: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
- operation: &mut dyn widget::Operation<Message>,
+ operation: &mut dyn widget::Operation<()>,
) {
self.element
.widget
diff --git a/core/src/event.rs b/core/src/event.rs
index 870b3074..b6cf321e 100644
--- a/core/src/event.rs
+++ b/core/src/event.rs
@@ -19,31 +19,10 @@ pub enum Event {
Mouse(mouse::Event),
/// A window event
- Window(window::Id, window::Event),
+ Window(window::Event),
/// A touch event
Touch(touch::Event),
-
- /// A platform specific event
- PlatformSpecific(PlatformSpecific),
-}
-
-/// A platform specific event
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub enum PlatformSpecific {
- /// A MacOS specific event
- MacOS(MacOS),
-}
-
-/// Describes an event specific to MacOS
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub enum MacOS {
- /// Triggered when the app receives an URL from the system
- ///
- /// _**Note:** For this event to be triggered, the executable needs to be properly [bundled]!_
- ///
- /// [bundled]: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW19
- ReceivedUrl(String),
}
/// The status of an [`Event`] after being processed.
diff --git a/core/src/keyboard/modifiers.rs b/core/src/keyboard/modifiers.rs
index e531510f..edbf6d38 100644
--- a/core/src/keyboard/modifiers.rs
+++ b/core/src/keyboard/modifiers.rs
@@ -84,4 +84,28 @@ impl Modifiers {
is_pressed
}
+
+ /// Returns true if the "jump key" is pressed in the [`Modifiers`].
+ ///
+ /// The "jump key" is the modifier key used to widen text motions. It is the `Alt`
+ /// key in macOS and the `Ctrl` key in other platforms.
+ pub fn jump(self) -> bool {
+ if cfg!(target_os = "macos") {
+ self.alt()
+ } else {
+ self.control()
+ }
+ }
+
+ /// Returns true if the "command key" is pressed on a macOS device.
+ ///
+ /// This is relevant for macOS-specific actions (e.g. `⌘ + ArrowLeft` moves the cursor
+ /// to the beginning of the line).
+ pub fn macos_command(self) -> bool {
+ if cfg!(target_os = "macos") {
+ self.logo()
+ } else {
+ false
+ }
+ }
}
diff --git a/core/src/overlay.rs b/core/src/overlay.rs
index 3a57fe16..16f867da 100644
--- a/core/src/overlay.rs
+++ b/core/src/overlay.rs
@@ -41,7 +41,7 @@ where
&mut self,
_layout: Layout<'_>,
_renderer: &Renderer,
- _operation: &mut dyn widget::Operation<Message>,
+ _operation: &mut dyn widget::Operation<()>,
) {
}
diff --git a/core/src/overlay/element.rs b/core/src/overlay/element.rs
index 695b88b3..61e75e8a 100644
--- a/core/src/overlay/element.rs
+++ b/core/src/overlay/element.rs
@@ -5,9 +5,7 @@ use crate::layout;
use crate::mouse;
use crate::renderer;
use crate::widget;
-use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector};
-
-use std::any::Any;
+use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size};
/// A generic [`Overlay`].
#[allow(missing_debug_implementations)]
@@ -94,7 +92,7 @@ where
&mut self,
layout: Layout<'_>,
renderer: &Renderer,
- operation: &mut dyn widget::Operation<Message>,
+ operation: &mut dyn widget::Operation<()>,
) {
self.overlay.operate(layout, renderer, operation);
}
@@ -146,59 +144,9 @@ where
&mut self,
layout: Layout<'_>,
renderer: &Renderer,
- operation: &mut dyn widget::Operation<B>,
+ operation: &mut dyn widget::Operation<()>,
) {
- struct MapOperation<'a, B> {
- operation: &'a mut dyn widget::Operation<B>,
- }
-
- impl<'a, T, B> widget::Operation<T> for MapOperation<'a, B> {
- fn container(
- &mut self,
- id: Option<&widget::Id>,
- bounds: Rectangle,
- operate_on_children: &mut dyn FnMut(
- &mut dyn widget::Operation<T>,
- ),
- ) {
- self.operation.container(id, bounds, &mut |operation| {
- operate_on_children(&mut MapOperation { operation });
- });
- }
-
- fn focusable(
- &mut self,
- state: &mut dyn widget::operation::Focusable,
- id: Option<&widget::Id>,
- ) {
- self.operation.focusable(state, id);
- }
-
- fn scrollable(
- &mut self,
- state: &mut dyn widget::operation::Scrollable,
- id: Option<&widget::Id>,
- bounds: Rectangle,
- translation: Vector,
- ) {
- self.operation.scrollable(state, id, bounds, translation);
- }
-
- fn text_input(
- &mut self,
- state: &mut dyn widget::operation::TextInput,
- id: Option<&widget::Id>,
- ) {
- self.operation.text_input(state, id);
- }
-
- fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) {
- self.operation.custom(state, id);
- }
- }
-
- self.content
- .operate(layout, renderer, &mut MapOperation { operation });
+ self.content.operate(layout, renderer, operation);
}
fn on_event(
diff --git a/core/src/overlay/group.rs b/core/src/overlay/group.rs
index 7e4bebd0..cd12eac9 100644
--- a/core/src/overlay/group.rs
+++ b/core/src/overlay/group.rs
@@ -132,7 +132,7 @@ where
&mut self,
layout: Layout<'_>,
renderer: &Renderer,
- operation: &mut dyn widget::Operation<Message>,
+ operation: &mut dyn widget::Operation<()>,
) {
operation.container(None, layout.bounds(), &mut |operation| {
self.children.iter_mut().zip(layout.children()).for_each(
diff --git a/core/src/widget.rs b/core/src/widget.rs
index b02e3a4f..0d12deba 100644
--- a/core/src/widget.rs
+++ b/core/src/widget.rs
@@ -105,7 +105,7 @@ where
_state: &mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
- _operation: &mut dyn Operation<Message>,
+ _operation: &mut dyn Operation<()>,
) {
}
diff --git a/core/src/widget/operation.rs b/core/src/widget/operation.rs
index b91cf9ac..3e4ed618 100644
--- a/core/src/widget/operation.rs
+++ b/core/src/widget/operation.rs
@@ -12,11 +12,11 @@ use crate::{Rectangle, Vector};
use std::any::Any;
use std::fmt;
-use std::rc::Rc;
+use std::sync::Arc;
/// A piece of logic that can traverse the widget tree of an application in
/// order to query or update some widget state.
-pub trait Operation<T> {
+pub trait Operation<T>: Send {
/// Operates on a widget that contains other widgets.
///
/// The `operate_on_children` function can be called to return control to
@@ -81,7 +81,7 @@ where
/// Maps the output of an [`Operation`] using the given function.
pub fn map<A, B>(
operation: Box<dyn Operation<A>>,
- f: impl Fn(A) -> B + 'static,
+ f: impl Fn(A) -> B + Send + Sync + 'static,
) -> impl Operation<B>
where
A: 'static,
@@ -90,7 +90,7 @@ where
#[allow(missing_debug_implementations)]
struct Map<A, B> {
operation: Box<dyn Operation<A>>,
- f: Rc<dyn Fn(A) -> B>,
+ f: Arc<dyn Fn(A) -> B + Send + Sync>,
}
impl<A, B> Operation<B> for Map<A, B>
@@ -197,7 +197,7 @@ where
Map {
operation,
- f: Rc::new(f),
+ f: Arc::new(f),
}
}
diff --git a/core/src/window/position.rs b/core/src/window/position.rs
index 73391e75..1c8e86b6 100644
--- a/core/src/window/position.rs
+++ b/core/src/window/position.rs
@@ -1,4 +1,4 @@
-use crate::Point;
+use crate::{Point, Size};
/// The position of a window in a given screen.
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -15,6 +15,12 @@ pub enum Position {
/// at (0, 0) you would have to set the position to
/// `(PADDING_X, PADDING_Y)`.
Specific(Point),
+ /// Like [`Specific`], but the window is positioned with the specific coordinates returned by the function.
+ ///
+ /// The function receives the window size and the monitor's resolution as input.
+ ///
+ /// [`Specific`]: Self::Specific
+ SpecificWith(fn(Size, Size) -> Point),
}
impl Default for Position {
diff --git a/core/src/window/settings/windows.rs b/core/src/window/settings/windows.rs
index d3bda259..88fe2fbd 100644
--- a/core/src/window/settings/windows.rs
+++ b/core/src/window/settings/windows.rs
@@ -1,12 +1,8 @@
//! Platform specific settings for Windows.
-use raw_window_handle::RawWindowHandle;
/// The platform specific window settings of an application.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PlatformSpecific {
- /// Parent window
- pub parent: Option<RawWindowHandle>,
-
/// Drag and drop support
pub drag_and_drop: bool,
@@ -17,7 +13,6 @@ pub struct PlatformSpecific {
impl Default for PlatformSpecific {
fn default() -> Self {
Self {
- parent: None,
drag_and_drop: true,
skip_taskbar: false,
}