summaryrefslogtreecommitdiffstats
path: root/runtime/src
diff options
context:
space:
mode:
authorLibravatar Cory Forsstrom <cforsstrom18@gmail.com>2023-02-19 17:43:13 -0800
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-06-14 11:03:41 +0200
commitb0205e03d8e4794850e55e8c4bf83a40dd41aa9d (patch)
treecb2fd958de24dd74896373f6c0ac5084c0d7595a /runtime/src
parent4de6ee6fa18be5b8fa511bffe93bbec2c5811bfc (diff)
downloadiced-b0205e03d8e4794850e55e8c4bf83a40dd41aa9d.tar.gz
iced-b0205e03d8e4794850e55e8c4bf83a40dd41aa9d.tar.bz2
iced-b0205e03d8e4794850e55e8c4bf83a40dd41aa9d.zip
Use nested for lazy widgets
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/lib.rs1
-rw-r--r--runtime/src/overlay.rs4
-rw-r--r--runtime/src/overlay/nested.rs (renamed from runtime/src/user_interface/overlay.rs)13
-rw-r--r--runtime/src/user_interface.rs6
4 files changed, 19 insertions, 5 deletions
diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs
index 50abf7b2..4bbf9687 100644
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -47,6 +47,7 @@ pub mod clipboard;
pub mod command;
pub mod font;
pub mod keyboard;
+pub mod overlay;
pub mod program;
pub mod system;
pub mod user_interface;
diff --git a/runtime/src/overlay.rs b/runtime/src/overlay.rs
new file mode 100644
index 00000000..03390980
--- /dev/null
+++ b/runtime/src/overlay.rs
@@ -0,0 +1,4 @@
+//! Overlays for user interfaces.
+mod nested;
+
+pub use nested::Nested;
diff --git a/runtime/src/user_interface/overlay.rs b/runtime/src/overlay/nested.rs
index 1211d55b..5c5fafde 100644
--- a/runtime/src/user_interface/overlay.rs
+++ b/runtime/src/overlay/nested.rs
@@ -21,6 +21,12 @@ where
Self { overlay: element }
}
+ /// Returns the position of the [`Nested`] overlay.
+ pub fn position(&self) -> Point {
+ self.overlay.position()
+ }
+
+ /// Returns the layout [`Node`] of the [`Nested`] overlay.
pub fn layout(
&mut self,
renderer: &Renderer,
@@ -36,7 +42,7 @@ where
where
Renderer: renderer::Renderer,
{
- let translation = position - Point::ORIGIN;
+ let translation = position - element.position();
let node = element.layout(renderer, bounds, translation);
@@ -58,6 +64,7 @@ where
recurse(&mut self.overlay, renderer, bounds, position)
}
+ /// Draws the [`Nested`] overlay using the associated `Renderer`.
pub fn draw(
&mut self,
renderer: &mut Renderer,
@@ -127,6 +134,7 @@ where
recurse(&mut self.overlay, layout, renderer, theme, style, cursor);
}
+ /// Applies a [`widget::Operation`] to the [`Nested`] overlay.
pub fn operate(
&mut self,
layout: Layout<'_>,
@@ -157,6 +165,7 @@ where
recurse(&mut self.overlay, layout, renderer, operation)
}
+ /// Processes a runtime [`Event`].
pub fn on_event(
&mut self,
event: Event,
@@ -247,6 +256,7 @@ where
status
}
+ /// Returns the current [`mouse::Interaction`] of the [`Nested`] overlay.
pub fn mouse_interaction(
&mut self,
layout: Layout<'_>,
@@ -298,6 +308,7 @@ where
.unwrap_or_default()
}
+ /// Returns true if the cursor is over the [`Nested`] overlay.
pub fn is_over(
&mut self,
layout: Layout<'_>,
diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs
index 1d55970e..619423fd 100644
--- a/runtime/src/user_interface.rs
+++ b/runtime/src/user_interface.rs
@@ -1,14 +1,12 @@
//! Implement your own event loop to drive a user interface.
-mod overlay;
-
use crate::core::event::{self, Event};
use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget;
use crate::core::window;
-use crate::core::{Clipboard, Point, Rectangle, Size};
-use crate::core::{Element, Layout, Shell};
+use crate::core::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size};
+use crate::overlay;
/// A set of interactive graphical elements with a specific [`Layout`].
///