@@ -60,10 +60,16 @@ pub trait Component {
60
60
render_params. clone ( )
61
61
}
62
62
63
+ // The render_condition determines whether the component should be rendered or not
63
64
fn render_condition ( & self ) -> bool {
64
65
true
65
66
}
66
67
68
+ // The difference with render_condition is that self_render_condition still renders childrens
69
+ fn self_render_condition ( & self ) -> bool {
70
+ true
71
+ }
72
+
67
73
fn draw_self (
68
74
& self ,
69
75
_pixmap : & mut Pixmap ,
@@ -87,7 +93,19 @@ pub trait Component {
87
93
}
88
94
89
95
fn parsed_style ( & self ) -> Style < f32 > {
90
- let style = self . style ( ) ;
96
+ // If render_condition return false, the whole component shouldn't rendered,
97
+ // includes its children
98
+ if !self . render_condition ( ) {
99
+ return ComponentStyle :: default ( ) ;
100
+ }
101
+
102
+ // If self_render_condition return false, the component shouldn't rendered,
103
+ // so the corresponding style should be cleared
104
+ let style = if self . self_render_condition ( ) {
105
+ self . style ( )
106
+ } else {
107
+ RawComponentStyle :: default ( )
108
+ } ;
91
109
let ( width, height) = self . get_dynamic_wh ( ) ;
92
110
let width = self . parse_size ( style. width , width)
93
111
+ style. padding . horizontal ( )
@@ -121,12 +139,19 @@ pub trait Component {
121
139
let render_params = self . initialize (
122
140
& component_render_params. parse_into_render_params_with_style (
123
141
parent_style. clone ( ) ,
124
- sibling_style,
142
+ sibling_style. clone ( ) ,
125
143
style. clone ( ) ,
126
144
) ,
127
145
) ;
128
146
129
- self . draw_self ( pixmap, context, & render_params, & style, & parent_style) ?;
147
+ // Render nothing on paint if render_condition return false
148
+ if !self . render_condition ( ) {
149
+ return Ok ( render_params. clone ( ) ) ;
150
+ }
151
+
152
+ if self . self_render_condition ( ) {
153
+ self . draw_self ( pixmap, context, & render_params, & style, & parent_style) ?;
154
+ }
130
155
131
156
let children = self . children ( ) ;
132
157
let mut sibling_render_params = RenderParams {
@@ -136,10 +161,6 @@ pub trait Component {
136
161
let mut sibling_style = ComponentStyle :: default ( ) ;
137
162
138
163
for child in children {
139
- if !child. render_condition ( ) {
140
- continue ;
141
- }
142
-
143
164
sibling_render_params = child. draw (
144
165
pixmap,
145
166
context,
0 commit comments