diff --git a/TODO/_current.md b/TODO/_current.md index 6fe24cc5f..511498e63 100644 --- a/TODO/_current.md +++ b/TODO/_current.md @@ -36,6 +36,7 @@ WindowManager//WindowId(1) update var of type zero_ui_units::factor::Factor (250 ``` - tracing permanently disables callsite if there no interest on the first usage, so need to build with some kind of subscriber from the start. + - Or could delay log calls until enabled, our own thing. # Hit-test diff --git a/zero-ui-app/src/running.rs b/zero-ui-app/src/running.rs index 1ed37d0d6..f628ae652 100644 --- a/zero-ui-app/src/running.rs +++ b/zero-ui-app/src/running.rs @@ -8,7 +8,7 @@ use std::{ use zero_ui_app_context::{app_local, AppScope}; use zero_ui_layout::units::Deadline; -use zero_ui_var::{response_var, ResponderVar, ResponseVar, VARS}; +use zero_ui_var::{response_var, ResponderVar, ResponseVar, VARS, VARS_APP}; use crate::{ event::{ @@ -59,9 +59,11 @@ impl RunningApp { UPDATES.init(sender); - VARS.init_app_waker(|| { + fn app_waker() { UPDATES.update(None); - }); + } + VARS_APP.init_app_waker(app_waker); + VARS_APP.init_modify_trace(UpdatesTrace::log_var); let mut info = AppExtensionsInfo::start(); extensions.register(&mut info); diff --git a/zero-ui-app/src/update.rs b/zero-ui-app/src/update.rs index c32aeef37..2add26e43 100644 --- a/zero-ui-app/src/update.rs +++ b/zero-ui-app/src/update.rs @@ -782,6 +782,7 @@ impl UpdatesTrace { /// Log a var update request. pub fn log_var(type_name: &str) { + dbg!(type_name); tracing::event!( target: UpdatesTrace::UPDATES_TARGET, tracing::Level::TRACE, diff --git a/zero-ui-var/src/vars.rs b/zero-ui-var/src/vars.rs index 3ccffd829..e8c8d671b 100644 --- a/zero-ui-var/src/vars.rs +++ b/zero-ui-var/src/vars.rs @@ -48,6 +48,7 @@ pub(crate) struct VarsService { updates_after: Mutex>, app_waker: Option>, + modify_trace: Option>, } impl VarsService { pub(crate) fn new() -> Self { @@ -58,6 +59,7 @@ impl VarsService { updating_thread: None, updates_after: Mutex::new(vec![]), app_waker: None, + modify_trace: None, } } @@ -239,17 +241,10 @@ impl VARS { } pub(super) fn schedule_update(&self, update: VarUpdateFn, type_name: &'static str) { - { - // same as UpdatesTrace::log_var(type_name), without the dependency. - const UPDATES_TARGET: &str = "zero-ui-updates"; - tracing::event!( - target: UPDATES_TARGET, - tracing::Level::TRACE, - { kind = "update var", type_name = pretty_type_name::pretty_type_name_str(type_name) } - ); - } - let vars = VARS_SV.read(); + if let Some(trace) = &vars.modify_trace { + trace(type_name); + } let curr_modify = match VARS_MODIFY_CTX.get_clone() { Some(current) => current, // override set by modify and animation closures. None => vars.ans.current_modify.clone(), @@ -270,19 +265,6 @@ impl VARS { } } - /// Register a closure called when [`apply_updates`] should be called because there are changes pending. - /// - /// # Panics - /// - /// Panics if already called for the current app. This must be called by app framework implementers only. - /// - /// [`apply_updates`]: Self::apply_updates - pub fn init_app_waker(&self, waker: impl Fn() + Send + Sync + 'static) { - let mut vars = VARS_SV.write(); - assert!(vars.app_waker.is_none()); - vars.app_waker = Some(Box::new(waker)); - } - pub(crate) fn wake_app(&self) { VARS_SV.read().wake_app(); } @@ -382,3 +364,33 @@ impl VARS { !VARS_SV.write().updates.get_mut().is_empty() } } + +/// VARS APP integration. +#[allow(non_camel_case_types)] +pub struct VARS_APP; +impl VARS_APP { + /// Register a closure called when [`apply_updates`] should be called because there are changes pending. + /// + /// # Panics + /// + /// Panics if already called for the current app. This must be called by app framework implementers only. + /// + /// [`apply_updates`]: Self::apply_updates + pub fn init_app_waker(&self, waker: impl Fn() + Send + Sync + 'static) { + let mut vars = VARS_SV.write(); + assert!(vars.app_waker.is_none()); + vars.app_waker = Some(Box::new(waker)); + } + + /// Register a closure called when a variable modify is about to be scheduled. The + /// closure parameter is the type name of the variable type. + /// + /// # Panics + /// + /// Panics if already called for the current app. This must be called by app framework implementers only. + pub fn init_modify_trace(&self, trace: impl Fn(&'static str) + Send + Sync + 'static) { + let mut vars = VARS_SV.write(); + assert!(vars.modify_trace.is_none()); + vars.modify_trace = Some(Box::new(trace)); + } +}