summaryrefslogtreecommitdiffstats
path: root/runtime/src
diff options
context:
space:
mode:
authorLibravatar Victoria Brekenfeld <victoria@system76.com>2023-06-28 18:51:14 +0200
committerLibravatar Victoria Brekenfeld <victoria@system76.com>2023-06-28 18:51:14 +0200
commit4b831a917d81def2320a5910ea8975acb2baaaf1 (patch)
tree03ee2719c4642eae6f6766acc9e9cde0eaf91403 /runtime/src
parent329fbc7b2157b84183849b2e0f600eb039435aed (diff)
downloadiced-4b831a917d81def2320a5910ea8975acb2baaaf1.tar.gz
iced-4b831a917d81def2320a5910ea8975acb2baaaf1.tar.bz2
iced-4b831a917d81def2320a5910ea8975acb2baaaf1.zip
runtime: Add `operate` method to `program::State`
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..f57d2d8d 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::{Operation, Outcome};
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<'a>(
+ &mut self,
+ renderer: &mut P::Renderer,
+ operations: impl Iterator<Item = &'a mut 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 owned_op;
+ let mut current_operation = Some(operation);
+ while let Some(operation) = current_operation.take() {
+ user_interface.operate(renderer, operation);
+ match operation.finish() {
+ Outcome::None => {}
+ Outcome::Some(message) => {
+ self.queued_messages.push(message)
+ }
+ Outcome::Chain(op) => {
+ owned_op = op;
+ current_operation = Some(owned_op.as_mut());
+ }
+ };
+ }
+ }
+
+ self.cache = Some(user_interface.into_cache());
+ }
}
fn build_user_interface<'a, P: Program>(