@@ -19,6 +19,8 @@ mod imp {
1919 pub ( crate ) struct Sticker {
2020 pub ( super ) file_id : Cell < i32 > ,
2121 pub ( super ) aspect_ratio : Cell < f64 > ,
22+ pub ( super ) recolor : Cell < bool > ,
23+ pub ( super ) is_loaded : Cell < bool > ,
2224 pub ( super ) child : RefCell < Option < gtk:: Widget > > ,
2325
2426 #[ property( get, set = Self :: set_longer_side_size) ]
@@ -84,6 +86,23 @@ mod imp {
8486 child. allocate ( width, height, baseline, None ) ;
8587 }
8688 }
89+
90+ fn snapshot ( & self , snapshot : & gtk:: Snapshot ) {
91+ if self . recolor . get ( ) && self . is_loaded . get ( ) {
92+ use gtk:: graphene:: * ;
93+ let color = self . obj ( ) . color ( ) ;
94+ let color_offset = Vec4 :: new ( color. red ( ) , color. green ( ) , color. blue ( ) , 0.0 ) ;
95+ let mut matrix = [ 0.0 ; 16 ] ;
96+ matrix[ 15 ] = color. alpha ( ) ;
97+ let color_matrix = Matrix :: from_float ( matrix) ;
98+
99+ snapshot. push_color_matrix ( & color_matrix, & color_offset) ;
100+ self . parent_snapshot ( snapshot) ;
101+ snapshot. pop ( ) ;
102+ } else {
103+ self . parent_snapshot ( snapshot) ;
104+ }
105+ }
87106 }
88107
89108 impl Sticker {
@@ -108,11 +127,15 @@ impl Sticker {
108127 return ;
109128 }
110129
111- self . set_child ( Some ( VectorPath :: new ( & sticker. outline ) . upcast ( ) ) ) ;
130+ self . set_child ( VectorPath :: new ( & sticker. outline ) . upcast ( ) , false ) ;
112131
113132 let aspect_ratio = sticker. width as f64 / sticker. height as f64 ;
114133 imp. aspect_ratio . set ( aspect_ratio) ;
115134
135+ let recolor = matches ! ( & sticker. full_type,
136+ tdlib:: enums:: StickerFullType :: CustomEmoji ( data) if data. needs_repainting) ;
137+ imp. recolor . set ( recolor) ;
138+
116139 let format = sticker. format ;
117140
118141 spawn ( clone ! ( @weak self as obj, @weak session => async move {
@@ -185,18 +208,17 @@ impl Sticker {
185208
186209 // Skip if widget was recycled by ListView
187210 if self . imp ( ) . file_id . get ( ) == file_id {
188- self . set_child ( Some ( widget) ) ;
211+ self . set_child ( widget, true ) ;
189212 }
190213 }
191214
192- fn set_child ( & self , child : Option < gtk:: Widget > ) {
215+ fn set_child ( & self , child : gtk:: Widget , is_loaded : bool ) {
193216 let imp = self . imp ( ) ;
217+ imp. is_loaded . set ( is_loaded) ;
194218
195- if let Some ( ref child) = child {
196- child. set_parent ( self ) ;
197- }
219+ child. set_parent ( self ) ;
198220
199- if let Some ( old) = imp. child . replace ( child) {
221+ if let Some ( old) = imp. child . replace ( Some ( child) ) {
200222 old. unparent ( )
201223 }
202224 }
0 commit comments