Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions examples/webgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ pub fn app_view() -> impl IntoView {
// Create a vertical layout
(
// The counter value updates automatically, thanks to reactivity
Label::derived(move || format!("Value: {}", counter.get())),
Label::derived(move || format!("Value: {}", counter.get()))
.style(|s| s.font_family("Fira Sans".to_owned())),
// Create a horizontal layout
(
"Increment".class(ButtonClass).action(move || {
counter.update(|value| *value += 1);
}),
"Decrement".class(ButtonClass).action(move || {
counter.update(|value| *value -= 1);
}),
"Increment"
.class(ButtonClass)
.style(|s| s.font_family("Fira Sans".to_owned()))
.action(move || {
counter.update(|value| *value += 1);
}),
"Decrement"
.class(ButtonClass)
.style(|s| s.font_family("Fira Sans".to_owned()))
.action(move || {
counter.update(|value| *value -= 1);
}),
),
)
.style(|s| s.flex_col())
Expand Down
3 changes: 2 additions & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{
action::{Timer, TimerToken},
inspector::{Capture, profiler::Profile},
platform::clipboard::Clipboard,
platform::menu_types::Menu,
view::IntoView,
window::{WindowConfig, WindowCreation},
};
Expand Down Expand Up @@ -107,7 +108,7 @@ pub enum AppEvent {
Reopen { has_visible_windows: bool },
}

pub(crate) struct MenuWrapper(pub(crate) muda::Menu);
pub(crate) struct MenuWrapper(pub(crate) Menu);
// SAFETY: these unsafe wappers are needed so that we can send the muda memu.
// The muda menu internally uses RC on a String ID and it's Vec of children.
// This unsafe wrapper is memory safe but the race condition could potentially (unlikely)
Expand Down
3 changes: 2 additions & 1 deletion src/event/dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Event dispatch logic for handling events through the view tree.

use std::{rc::Rc, sync::LazyLock, time::Instant};
use std::{rc::Rc, sync::LazyLock};

use peniko::kurbo::{Affine, Point, Rect};
use smallvec::SmallVec;
Expand All @@ -25,6 +25,7 @@ use crate::{
DragEvent, DragToken, Event, FocusEvent, InteractionEvent, Phase, PointerCaptureEvent,
WindowEvent, drag_state::DragEventDispatch, dropped_file::FileDragEvent, path::hit_test,
},
platform::time::Instant,
style::{StyleSelector, StyleSelectors, recalc::StyleReason},
view::{VIEW_STORAGE, View},
window::WindowState,
Expand Down
6 changes: 5 additions & 1 deletion src/window/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ impl WindowHandle {
// Capture a single timestamp for the entire style pass.
// All views in this frame see the same `now`, which is both cheaper
// (avoids per-view syscall) and more correct (no sub-frame jitter).
self.window_state.frame_start = std::time::Instant::now();
self.window_state.frame_start = Instant::now();

// Loop until no more views need styling
// This handles the case where styling a parent marks children dirty
Expand Down Expand Up @@ -786,7 +786,10 @@ impl WindowHandle {
}

pub(crate) fn render_frame(&mut self) {
#[cfg(not(target_arch = "wasm32"))]
let renderer_ready = matches!(self.paint_state, PaintState::Initialized { .. });
#[cfg(target_arch = "wasm32")]
let renderer_ready = true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you speak to the accuracy of doing this. Is this always true?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During testing I noticed that when setting render_ready to always true the paint_state was in pending for some cycles and then got to initialized. Without, the paint_state was always stuck in pending. While looking at it again now, I suspect the actual reason might be because the last_presented_at only gets set inside the condition. So when renderer_ready is false render_frame gets called without any/very low delay in between thus preventing the initialization. To confirm, I moved the self.last_presented_at = Instant::now(); outside of the condition and with that it also works with the original renderer_ready flag. Maybe that would be the better fix instead?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be but

if self.window_state.request_paint && renderer_ready {
self.window_state.request_paint = false;
self.paint();
Expand Down Expand Up @@ -1228,6 +1231,7 @@ impl WindowHandle {
pos,
});
}
#[cfg(not(target_arch = "wasm32"))]
UpdateMessage::WindowMenu { menu } => {
self.window_menu_actions.clear();
let (menu, registry) = menu.build();
Expand Down
3 changes: 2 additions & 1 deletion src/window/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::RefCell, collections::HashMap, time::Instant};
use std::{cell::RefCell, collections::HashMap};

use crate::{
action::exec_after_animation_frame,
Expand Down Expand Up @@ -27,6 +27,7 @@ use crate::{
event::{DragTracker, Event, WindowEvent, clear_hit_test_cache},
layout::responsive::{GridBreakpoints, ScreenSizeBp},
message::UpdateMessage,
platform::time::Instant,
style::{CursorStyle, Style, StyleSelector, theme::default_theme},
view::{LayoutNodeCx, MeasureCx, VIEW_STORAGE, ViewId},
};
Expand Down
Loading