Use nested for lazy widgets

This commit is contained in:
Cory Forsstrom 2023-02-19 17:43:13 -08:00 committed by Héctor Ramón Jiménez
parent 4de6ee6fa1
commit b0205e03d8
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
7 changed files with 77 additions and 49 deletions

View file

@ -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;

4
runtime/src/overlay.rs Normal file
View file

@ -0,0 +1,4 @@
//! Overlays for user interfaces.
mod nested;
pub use nested::Nested;

View file

@ -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<'_>,

View file

@ -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`].
///