summaryrefslogtreecommitdiffstats
path: root/native/src/program/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/program/state.rs')
-rw-r--r--native/src/program/state.rs36
1 files changed, 11 insertions, 25 deletions
diff --git a/native/src/program/state.rs b/native/src/program/state.rs
index 95e6b60c..fd1f2b52 100644
--- a/native/src/program/state.rs
+++ b/native/src/program/state.rs
@@ -1,12 +1,9 @@
use crate::{
- Cache, Clipboard, Command, Debug, Event, Point, Program, Renderer, Size,
- UserInterface,
+ Cache, Command, Debug, Event, Point, Program, Renderer, Size, UserInterface,
};
/// The execution state of a [`Program`]. It leverages caching, event
/// processing, and rendering primitive storage.
-///
-/// [`Program`]: trait.Program.html
#[allow(missing_debug_implementations)]
pub struct State<P>
where
@@ -25,9 +22,6 @@ where
{
/// Creates a new [`State`] with the provided [`Program`], initializing its
/// primitive with the given logical bounds and renderer.
- ///
- /// [`State`]: struct.State.html
- /// [`Program`]: trait.Program.html
pub fn new(
mut program: P,
bounds: Size,
@@ -59,39 +53,30 @@ where
}
/// Returns a reference to the [`Program`] of the [`State`].
- ///
- /// [`Program`]: trait.Program.html
- /// [`State`]: struct.State.html
pub fn program(&self) -> &P {
&self.program
}
/// Returns a reference to the current rendering primitive of the [`State`].
- ///
- /// [`State`]: struct.State.html
pub fn primitive(&self) -> &<P::Renderer as Renderer>::Output {
&self.primitive
}
/// Queues an event in the [`State`] for processing during an [`update`].
///
- /// [`State`]: struct.State.html
- /// [`update`]: #method.update
+ /// [`update`]: Self::update
pub fn queue_event(&mut self, event: Event) {
self.queued_events.push(event);
}
/// Queues a message in the [`State`] for processing during an [`update`].
///
- /// [`State`]: struct.State.html
- /// [`update`]: #method.update
+ /// [`update`]: Self::update
pub fn queue_message(&mut self, message: P::Message) {
self.queued_messages.push(message);
}
/// Returns whether the event queue of the [`State`] is empty or not.
- ///
- /// [`State`]: struct.State.html
pub fn is_queue_empty(&self) -> bool {
self.queued_events.is_empty() && self.queued_messages.is_empty()
}
@@ -101,14 +86,12 @@ where
///
/// Returns the [`Command`] obtained from [`Program`] after updating it,
/// only if an update was necessary.
- ///
- /// [`Program`]: trait.Program.html
pub fn update(
&mut self,
bounds: Size,
cursor_position: Point,
- clipboard: Option<&dyn Clipboard>,
renderer: &mut P::Renderer,
+ clipboard: &mut P::Clipboard,
debug: &mut Debug,
) -> Option<Command<P::Message>> {
let mut user_interface = build_user_interface(
@@ -120,14 +103,17 @@ where
);
debug.event_processing_started();
- let mut messages = user_interface.update(
+ let mut messages = Vec::new();
+
+ let _ = user_interface.update(
&self.queued_events,
cursor_position,
- clipboard,
renderer,
+ clipboard,
+ &mut messages,
);
- messages.extend(self.queued_messages.drain(..));
+ messages.extend(self.queued_messages.drain(..));
self.queued_events.clear();
debug.event_processing_finished();
@@ -149,7 +135,7 @@ where
debug.log_message(&message);
debug.update_started();
- let command = self.program.update(message);
+ let command = self.program.update(message, clipboard);
debug.update_finished();
command