Introduce window::Id to timing::Stage in iced_sentinel

This commit is contained in:
Héctor Ramón Jiménez 2024-02-28 15:25:45 +01:00
parent caecbf20ef
commit 8591e5a148
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
8 changed files with 97 additions and 62 deletions

View file

@ -1,6 +1,35 @@
//! A multi-window application.
pub mod program;
pub mod state;
use crate::core::text;
use crate::core::window;
use crate::core::{Element, Renderer};
use crate::Command;
pub use program::Program;
pub use state::State;
/// The core of a user interface for a multi-window application following The Elm Architecture.
pub trait Program: Sized {
/// The graphics backend to use to draw the [`Program`].
type Renderer: Renderer + text::Renderer;
/// The type of __messages__ your [`Program`] will produce.
type Message: std::fmt::Debug + Send;
/// The theme used to draw the [`Program`].
type Theme;
/// Handles a __message__ and updates the state of the [`Program`].
///
/// This is where you define your __update logic__. All the __messages__,
/// produced by either user interactions or commands, will be handled by
/// this method.
///
/// Any [`Command`] returned will be executed immediately in the
/// background by shells.
fn update(&mut self, message: Self::Message) -> Command<Self::Message>;
/// Returns the widgets to display in the [`Program`] for the `window`.
///
/// These widgets can produce __messages__ based on user interaction.
fn view(
&self,
window: window::Id,
) -> Element<'_, Self::Message, Self::Theme, Self::Renderer>;
}

View file

@ -98,12 +98,12 @@ where
bounds,
);
let interact_timer = debug::interact_time();
let mut messages = Vec::new();
let uncaptured_events = user_interfaces.iter_mut().fold(
vec![],
|mut uncaptured_events, ui| {
let interact_timer = debug::interact_time();
let (_, event_statuses) = ui.update(
&self.queued_events,
cursor,
@ -111,6 +111,7 @@ where
clipboard,
&mut messages,
);
interact_timer.finish();
uncaptured_events.extend(
self.queued_events
@ -128,7 +129,6 @@ where
self.queued_events.clear();
messages.append(&mut self.queued_messages);
drop(interact_timer);
let commands = if messages.is_empty() {
let draw_timer = debug::draw_time();

View file

@ -2,6 +2,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::window;
use crate::core::{Clipboard, Size};
use crate::debug;
use crate::user_interface::{self, UserInterface};
@ -101,7 +102,7 @@ where
bounds,
);
let interact_timer = debug::interact_time();
let interact_timer = debug::interact_time(window::Id::MAIN);
let mut messages = Vec::new();
let (_, event_statuses) = user_interface.update(
@ -127,7 +128,7 @@ where
drop(interact_timer);
let command = if messages.is_empty() {
let draw_timer = debug::draw_time();
let draw_timer = debug::draw_time(window::Id::MAIN);
self.mouse_interaction =
user_interface.draw(renderer, theme, style, cursor);
drop(draw_timer);
@ -158,7 +159,7 @@ where
bounds,
);
let draw_timer = debug::draw_time();
let draw_timer = debug::draw_time(window::Id::MAIN);
self.mouse_interaction =
user_interface.draw(renderer, theme, style, cursor);
drop(draw_timer);
@ -213,11 +214,11 @@ fn build_user_interface<'a, P: Program>(
renderer: &mut P::Renderer,
size: Size,
) -> UserInterface<'a, P::Message, P::Theme, P::Renderer> {
let view_timer = debug::view_time();
let view_timer = debug::view_time(window::Id::MAIN);
let view = program.view();
drop(view_timer);
let layout_timer = debug::layout_time();
let layout_timer = debug::layout_time(window::Id::MAIN);
let user_interface = UserInterface::build(view, size, cache, renderer);
drop(layout_timer);