1616
1717use std:: sync:: Arc ;
1818
19+ use crate :: env:: KeyLike ;
1920use crate :: piet:: { PietTextLayoutBuilder , TextStorage as PietTextStorage } ;
2021use crate :: { Data , Env } ;
2122
2223use super :: attribute:: Link ;
24+ use crate :: UpdateCtx ;
2325
2426/// A type that represents text that can be displayed.
2527pub trait TextStorage : PietTextStorage + Data {
@@ -30,6 +32,13 @@ pub trait TextStorage: PietTextStorage + Data {
3032 builder
3133 }
3234
35+ /// This is called whenever the Env changes and should return true
36+ /// if the layout should be rebuilt.
37+ #[ allow( unused_variables) ]
38+ fn env_update ( & self , ctx : & EnvUpdateCtx ) -> bool {
39+ false
40+ }
41+
3342 /// Any additional [`Link`] attributes on this text.
3443 ///
3544 /// If this `TextStorage` object manages link attributes, it should implement this
@@ -45,6 +54,26 @@ pub trait TextStorage: PietTextStorage + Data {
4554 }
4655}
4756
57+ /// Provides information about keys change for more fine grained invalidation
58+ pub struct EnvUpdateCtx < ' a , ' b > ( & ' a UpdateCtx < ' a , ' b > ) ;
59+
60+ impl < ' a , ' b > EnvUpdateCtx < ' a , ' b > {
61+ /// Create an EnvChangeCtx for Widget::update
62+ pub ( crate ) fn for_update ( ctx : & ' a UpdateCtx < ' a , ' b > ) -> Self {
63+ Self ( ctx)
64+ }
65+
66+ /// Returns `true` if the given key has changed since the last [`env_update`]
67+ /// call.
68+ ///
69+ /// See [`UpdateCtx::env_key_changed`] for more details.
70+ ///
71+ /// [`env_update`]: (TextStorage::env_update)
72+ pub fn env_key_changed < T > ( & self , key : & impl KeyLike < T > ) -> bool {
73+ self . 0 . env_key_changed ( key)
74+ }
75+ }
76+
4877/// A reference counted string slice.
4978///
5079/// This is a data-friendly way to represent strings in druid. Unlike `String`
0 commit comments