Rename iced_sentinel to iced_beacon and refactor its API

This commit is contained in:
Héctor Ramón Jiménez 2024-05-10 20:08:09 +02:00
parent aaf396256e
commit 57033dc4d0
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
19 changed files with 596 additions and 438 deletions

View file

@ -48,6 +48,9 @@ where
/// The data needed to initialize your [`Application`].
type Flags;
/// Returns the unique name of the [`Application`].
fn name() -> &'static str;
/// Initializes the [`Application`] with the flags provided to
/// [`run`] as part of the [`Settings`].
///
@ -156,7 +159,8 @@ where
use futures::Future;
use winit::event_loop::EventLoop;
let boot_timer = debug::boot_time();
debug::init(A::name());
let boot_span = debug::boot();
let event_loop = EventLoop::with_user_event()
.build()
@ -193,7 +197,7 @@ where
control_sender,
init_command,
settings.fonts,
boot_timer,
boot_span,
));
let context = task::Context::from_waker(task::noop_waker_ref());
@ -498,7 +502,7 @@ async fn run_instance<A, E, C>(
mut control_sender: mpsc::UnboundedSender<winit::event_loop::ControlFlow>,
init_command: Command<A::Message>,
fonts: Vec<Cow<'static, [u8]>>,
boot_timer: debug::Timer,
boot_span: debug::Span,
) where
A: Application + 'static,
E: Executor + 'static,
@ -554,7 +558,7 @@ async fn run_instance<A, E, C>(
&window,
);
runtime.track(application.subscription().into_recipes());
boot_timer.finish();
boot_span.finish();
let mut user_interface = ManuallyDrop::new(build_user_interface(
&application,
@ -608,12 +612,12 @@ async fn run_instance<A, E, C>(
if viewport_version != current_viewport_version {
let logical_size = state.logical_size();
let layout_timer = debug::layout_time(window::Id::MAIN);
let layout_span = debug::layout(window::Id::MAIN);
user_interface = ManuallyDrop::new(
ManuallyDrop::into_inner(user_interface)
.relayout(logical_size, &mut renderer),
);
layout_timer.finish();
layout_span.finish();
compositor.configure_surface(
&mut surface,
@ -660,7 +664,7 @@ async fn run_instance<A, E, C>(
runtime.broadcast(redraw_event, core::event::Status::Ignored);
let draw_timer = debug::draw_time(window::Id::MAIN);
let draw_span = debug::draw(window::Id::MAIN);
let new_mouse_interaction = user_interface.draw(
&mut renderer,
state.theme(),
@ -670,7 +674,7 @@ async fn run_instance<A, E, C>(
state.cursor(),
);
redraw_pending = false;
draw_timer.finish();
draw_span.finish();
if new_mouse_interaction != mouse_interaction {
window.set_cursor(conversion::mouse_interaction(
@ -680,7 +684,7 @@ async fn run_instance<A, E, C>(
mouse_interaction = new_mouse_interaction;
}
let render_timer = debug::render_time(window::Id::MAIN);
let present_span = debug::present(window::Id::MAIN);
match compositor.present(
&mut renderer,
&mut surface,
@ -688,7 +692,7 @@ async fn run_instance<A, E, C>(
state.background_color(),
) {
Ok(()) => {
render_timer.finish();
present_span.finish();
}
Err(error) => match error {
// This is an unrecoverable error.
@ -733,7 +737,7 @@ async fn run_instance<A, E, C>(
redraw_request: None,
}
} else {
let interact_timer = debug::interact_time(window::Id::MAIN);
let interact_span = debug::interact(window::Id::MAIN);
let (interface_state, statuses) = user_interface.update(
&events,
state.cursor(),
@ -747,7 +751,7 @@ async fn run_instance<A, E, C>(
{
runtime.broadcast(event, status);
}
interact_timer.finish();
interact_span.finish();
interface_state
};
@ -842,13 +846,13 @@ pub fn build_user_interface<'a, A: Application>(
where
A::Theme: DefaultStyle,
{
let view_timer = debug::view_time(window::Id::MAIN);
let view_span = debug::view(window::Id::MAIN);
let view = application.view();
view_timer.finish();
view_span.finish();
let layout_timer = debug::layout_time(window::Id::MAIN);
let layout_span = debug::layout(window::Id::MAIN);
let user_interface = UserInterface::build(view, size, cache, renderer);
layout_timer.finish();
layout_span.finish();
user_interface
}
@ -875,9 +879,9 @@ pub fn update<A: Application, C, E: Executor>(
for message in messages.drain(..) {
debug::log_message(&message);
let update_timer = debug::update_time();
let update_span = debug::update();
let command = runtime.enter(|| application.update(message));
update_timer.finish();
update_span.finish();
run_command(
application,

View file

@ -38,8 +38,7 @@ where
let theme = application.theme();
let appearance = application.style(&theme);
let _ = application::DefaultStyle::palette(&theme)
.map(debug::theme_changed);
debug::theme_changed(|| application::DefaultStyle::palette(&theme));
let viewport = {
let physical_size = window.inner_size();
@ -216,7 +215,8 @@ where
self.theme = application.theme();
self.appearance = application.style(&self.theme);
let _ = application::DefaultStyle::palette(&self.theme)
.map(debug::theme_changed);
debug::theme_changed(|| {
application::DefaultStyle::palette(&self.theme)
});
}
}

View file

@ -117,7 +117,7 @@ where
{
use winit::event_loop::EventLoop;
let boot_timer = debug::boot_time();
let boot_span = debug::boot();
let event_loop = EventLoop::with_user_event()
.build()
@ -153,7 +153,7 @@ where
event_receiver,
control_sender,
init_command,
boot_timer,
boot_span,
));
let context = task::Context::from_waker(task::noop_waker_ref());
@ -452,7 +452,7 @@ async fn run_instance<A, E, C>(
mut event_receiver: mpsc::UnboundedReceiver<Event<A::Message>>,
mut control_sender: mpsc::UnboundedSender<Control>,
init_command: Command<A::Message>,
boot_timer: debug::Timer,
boot_span: debug::Span,
) where
A: Application + 'static,
E: Executor + 'static,
@ -524,7 +524,7 @@ async fn run_instance<A, E, C>(
);
runtime.track(application.subscription().into_recipes());
boot_timer.finish();
boot_span.finish();
let mut messages = Vec::new();
let mut user_events = 0;
@ -636,7 +636,7 @@ async fn run_instance<A, E, C>(
&mut messages,
);
let draw_timer = debug::draw_time(id);
let draw_span = debug::draw(id);
let new_mouse_interaction = ui.draw(
&mut window.renderer,
window.state.theme(),
@ -645,7 +645,7 @@ async fn run_instance<A, E, C>(
},
cursor,
);
draw_timer.finish();
draw_span.finish();
if new_mouse_interaction != window.mouse_interaction {
window.raw.set_cursor(
@ -692,7 +692,7 @@ async fn run_instance<A, E, C>(
{
let logical_size = window.state.logical_size();
let layout_time = debug::layout_time(id);
let layout = debug::layout(id);
let ui = user_interfaces
.remove(&id)
.expect("Remove user interface");
@ -701,9 +701,9 @@ async fn run_instance<A, E, C>(
id,
ui.relayout(logical_size, &mut window.renderer),
);
layout_time.finish();
layout.finish();
let draw_time = debug::draw_time(id);
let draw = debug::draw(id);
let new_mouse_interaction = user_interfaces
.get_mut(&id)
.expect("Get user interface")
@ -715,7 +715,7 @@ async fn run_instance<A, E, C>(
},
window.state.cursor(),
);
draw_time.finish();
draw.finish();
if new_mouse_interaction != window.mouse_interaction
{
@ -739,7 +739,7 @@ async fn run_instance<A, E, C>(
window.state.viewport_version();
}
let render_time = debug::render_time(id);
let present_span = debug::present(id);
match compositor.present(
&mut window.renderer,
&mut window.surface,
@ -747,7 +747,7 @@ async fn run_instance<A, E, C>(
window.state.background_color(),
) {
Ok(()) => {
render_time.finish();
present_span.finish();
// TODO: Handle animations!
// Maybe we can use `ControlFlow::WaitUntil` for this.
@ -821,7 +821,7 @@ async fn run_instance<A, E, C>(
let mut uis_stale = false;
for (id, window) in window_manager.iter_mut() {
let interact_time = debug::interact_time(id);
let interact = debug::interact(id);
let mut window_events = vec![];
events.retain(|(window_id, event)| {
@ -864,7 +864,7 @@ async fn run_instance<A, E, C>(
{
runtime.broadcast(event, status);
}
interact_time.finish();
interact.finish();
}
// TODO mw application update returns which window IDs to update
@ -938,13 +938,13 @@ fn build_user_interface<'a, A: Application>(
where
A::Theme: DefaultStyle,
{
let view_timer = debug::view_time(id);
let view_span = debug::view(id);
let view = application.view(id);
view_timer.finish();
view_span.finish();
let layout_timer = debug::layout_time(id);
let layout_span = debug::layout(id);
let user_interface = UserInterface::build(view, size, cache, renderer);
layout_timer.finish();
layout_span.finish();
user_interface
}
@ -968,9 +968,9 @@ fn update<A: Application, C, E: Executor>(
for message in messages.drain(..) {
debug::log_message(&message);
let update_timer = debug::update_time();
let update_span = debug::update();
let command = runtime.enter(|| application.update(message));
update_timer.finish();
update_span.finish();
run_command(
application,