summaryrefslogtreecommitdiffstats
path: root/runtime/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-06-29 10:23:52 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-29 10:23:52 +0200
commit949eca3eb814bce04f0c658ea0c9da9ecbbdfe12 (patch)
tree18d79bdf4ef32175af18301bbf5d689de76df0b0 /runtime/src
parent0cc85c7820136f3ad858c287e8e35884604e7bd0 (diff)
parentaf4d65c42862190adc9266dd95d98195bb1107de (diff)
downloadiced-949eca3eb814bce04f0c658ea0c9da9ecbbdfe12.tar.gz
iced-949eca3eb814bce04f0c658ea0c9da9ecbbdfe12.tar.bz2
iced-949eca3eb814bce04f0c658ea0c9da9ecbbdfe12.zip
Merge pull request #1913 from Drakulix/feature/runtime-state-operate
runtime: Handle widget operations in `program::State` helper
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/program/state.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/runtime/src/program/state.rs b/runtime/src/program/state.rs
index d83e3f54..35df6078 100644
--- a/runtime/src/program/state.rs
+++ b/runtime/src/program/state.rs
@@ -1,6 +1,7 @@
use crate::core::event::{self, Event};
use crate::core::mouse;
use crate::core::renderer;
+use crate::core::widget::operation::{self, Operation};
use crate::core::{Clipboard, Size};
use crate::user_interface::{self, UserInterface};
use crate::{Command, Debug, Program};
@@ -173,6 +174,43 @@ where
(uncaptured_events, command)
}
+
+ /// Applies [`widget::Operation`]s to the [`State`]
+ pub fn operate(
+ &mut self,
+ renderer: &mut P::Renderer,
+ operations: impl Iterator<Item = Box<dyn Operation<P::Message>>>,
+ bounds: Size,
+ debug: &mut Debug,
+ ) {
+ let mut user_interface = build_user_interface(
+ &mut self.program,
+ self.cache.take().unwrap(),
+ renderer,
+ bounds,
+ debug,
+ );
+
+ for operation in operations {
+ let mut current_operation = Some(operation);
+
+ while let Some(mut operation) = current_operation.take() {
+ user_interface.operate(renderer, operation.as_mut());
+
+ match operation.finish() {
+ operation::Outcome::None => {}
+ operation::Outcome::Some(message) => {
+ self.queued_messages.push(message)
+ }
+ operation::Outcome::Chain(next) => {
+ current_operation = Some(next);
+ }
+ };
+ }
+ }
+
+ self.cache = Some(user_interface.into_cache());
+ }
}
fn build_user_interface<'a, P: Program>(