@@ -488,27 +488,29 @@ impl MainAxis {
488488 // Axis contains elements that want the free space. Give it to them, don't use
489489 // justify-content.
490490
491- let mut added_space = 0 ;
491+ let mut current_item_assigned_space = 0 ;
492492 let item_main_axis_size =
493493 layout. flexitem_main_axis_size ( & mut RefCell :: borrow_mut ( & item) ) ;
494494 if remaining_grow_factor > 0 {
495- added_space = ( RefCell :: borrow ( & item ) . flex_grow as usize
496- / remaining_grow_factor)
497- * assignable_free_space;
495+ current_item_assigned_space =
496+ ( ( RefCell :: borrow ( & item ) . flex_grow as f64 / remaining_grow_factor as f64 )
497+ * assignable_free_space as f64 ) as usize ;
498498 }
499499
500500 match layout. options . direction {
501501 FlexDirection :: Row => {
502502 start_x = offset;
503- width = item_main_axis_size + added_space ;
503+ width = item_main_axis_size + current_item_assigned_space ;
504504 } ,
505505 FlexDirection :: Column => {
506506 start_y = offset;
507- height = item_main_axis_size + added_space ;
507+ height = item_main_axis_size + current_item_assigned_space ;
508508 } ,
509509 }
510- offset += item_main_axis_size + layout. options . main_axis_gap as usize + added_space;
511- assignable_free_space -= added_space;
510+ offset += item_main_axis_size
511+ + layout. options . main_axis_gap as usize
512+ + current_item_assigned_space;
513+ assignable_free_space -= current_item_assigned_space;
512514 remaining_grow_factor -= RefCell :: borrow ( & item) . flex_grow as usize ;
513515 } else {
514516 // Axis doesn't contain elements that want free space. Use justify-content property
@@ -957,40 +959,37 @@ impl View for Flexbox {
957959 fn required_size ( & mut self , constraint : cursive_core:: Vec2 ) -> cursive_core:: Vec2 {
958960 // PERF: Cache the values that the previous layout was generated with and regenerate if
959961 // cached version is outdated.
960- let layout = self . generate_layout ( constraint) ;
961- layout. size ( )
962+ constraint
962963 }
963964
964965 fn on_event (
965966 & mut self ,
966967 mut event : cursive_core:: event:: Event ,
967968 ) -> cursive_core:: event:: EventResult {
968- if let Some ( active_child) = self . focused {
969- if let cursive_core:: event:: Event :: Mouse {
970- ref mut offset,
971- ref mut position,
972- ..
973- } = event
974- {
975- if let Some ( ref layout) = self . layout {
976- if let Some ( placed_element) =
977- layout. element_at ( global_to_view_coordinates ( * position, * offset) )
978- {
979- * offset = * offset + placed_element. position . top_left ( ) ;
980- RefCell :: borrow_mut ( & placed_element. element )
981- . view
982- . on_event ( event)
983- } else {
984- EventResult :: Ignored
985- }
969+ if let cursive_core:: event:: Event :: Mouse {
970+ ref mut offset,
971+ ref mut position,
972+ ..
973+ } = event
974+ {
975+ if let Some ( ref layout) = self . layout {
976+ if let Some ( placed_element) =
977+ layout. element_at ( global_to_view_coordinates ( * position, * offset) )
978+ {
979+ * offset = * offset + placed_element. position . top_left ( ) ;
980+ RefCell :: borrow_mut ( & placed_element. element )
981+ . view
982+ . on_event ( event)
986983 } else {
987984 EventResult :: Ignored
988985 }
989986 } else {
990- RefCell :: borrow_mut ( & self . content [ active_child] )
991- . view
992- . on_event ( event)
987+ EventResult :: Ignored
993988 }
989+ } else if let Some ( active_child) = self . focused {
990+ RefCell :: borrow_mut ( & self . content [ active_child] )
991+ . view
992+ . on_event ( event)
994993 } else {
995994 EventResult :: Ignored
996995 }
0 commit comments