@@ -86,14 +86,15 @@ pub trait Component {
8686 RawComponentStyle :: default ( )
8787 }
8888
89- fn parse_size ( & self , size : Size , dynamic_value : f32 ) -> f32 {
89+ fn parse_size ( & self , size : Size , dynamic_value : f32 , inherit_value : Option < f32 > ) -> f32 {
9090 match size {
9191 Size :: Num ( num) => num,
9292 Size :: Dynamic => dynamic_value,
93+ Size :: Inherit => inherit_value. unwrap_or ( dynamic_value) ,
9394 }
9495 }
9596
96- fn parsed_style ( & self ) -> Style < f32 > {
97+ fn parsed_style ( & self , parent_style : Option < & ComponentStyle > ) -> Style < f32 > {
9798 // If render_condition return false, the whole component shouldn't rendered,
9899 // includes its children
99100 if !self . render_condition ( ) {
@@ -108,7 +109,7 @@ pub trait Component {
108109 RawComponentStyle :: default ( )
109110 } ;
110111 let ( width, height) = self . get_dynamic_wh ( ) ;
111- let width = self . parse_size ( style. width , width)
112+ let width = self . parse_size ( style. width , width, parent_style . map ( |s| s . width ) )
112113 + style. padding . horizontal ( )
113114 + style. margin . horizontal ( ) ;
114115
@@ -119,7 +120,7 @@ pub trait Component {
119120 } else {
120121 style. min_width
121122 } ,
122- height : self . parse_size ( style. height , height)
123+ height : self . parse_size ( style. height , height, parent_style . map ( |s| s . height ) )
123124 + style. padding . vertical ( )
124125 + style. margin . vertical ( ) ,
125126 align : style. align ,
@@ -136,7 +137,7 @@ pub trait Component {
136137 parent_style : ComponentStyle ,
137138 sibling_style : ComponentStyle ,
138139 ) -> render_error:: Result < RenderParams > {
139- let style = self . parsed_style ( ) ;
140+ let style = self . parsed_style ( Some ( & parent_style ) ) ;
140141 let render_params = self . initialize (
141142 & component_render_params. parse_into_render_params_with_style (
142143 parent_style. clone ( ) ,
@@ -172,7 +173,7 @@ pub trait Component {
172173 style. clone ( ) ,
173174 sibling_style,
174175 ) ?;
175- sibling_style = child. parsed_style ( ) ;
176+ sibling_style = child. parsed_style ( Some ( & style . clone ( ) ) ) ;
176177 }
177178
178179 Ok ( render_params. clone ( ) )
@@ -190,13 +191,13 @@ pub trait Component {
190191 match style. align {
191192 // If align is row, width is sum of children width, height is max of children height
192193 ComponentAlign :: Row => calc_children_wh ( |( w, h) , child| {
193- let style = child. parsed_style ( ) ;
194+ let style = child. parsed_style ( None ) ;
194195
195196 ( w + style. width , h. max ( style. height ) )
196197 } ) ,
197198 // If align is column, width is max of children width, height is sum of children height
198199 ComponentAlign :: Column => calc_children_wh ( |( w, h) , child| {
199- let style = child. parsed_style ( ) ;
200+ let style = child. parsed_style ( None ) ;
200201
201202 ( w. max ( style. width ) , h + style. height )
202203 } ) ,
0 commit comments