fn layout(&mut self, renderer: &mut crate::render::Renderer, theme: &crate::style::Theme, constraints: (u32, u32), is_root: bool) {
        let alignment = if let Some(alignment) = self.alignment {
            alignment
        } else {
            theme.default_alignment
        };
        
        let mut current_x = 0;
        let mut current_y = 0;
        let mut view_width = 0;
        let mut view_height = 0;

        // Initial padding within window
        if is_root {
            if !alignment.is_centered() {
                current_x += theme.view_padding.horizontal;
            }
            // FIXME: Is this correct?
            current_y += theme.view_padding.vertical;
        }
        
        for child in &mut self.children {
            let child_width;
            let child_height;

            match child {
                ViewElement::View(view) => {
                    view.layout(renderer, theme, constraints, false);
                    let size = view.render_size();
                    child_width = size.0; 
                    child_height = size.1;
                    
                    if alignment.is_centered() {
                        if self.orientation.is_vertical() {
                            view.translate((constraints.0 / 2) as i32 - (child_width / 2) as i32, current_y as i32);
                        }
                    } else {   
                        view.translate(current_x as i32, current_y as i32);
                    }
                }
                
                ViewElement::Widget(widget) => {
                    let size = widget.render_size(theme);
                    child_width = size.0; 
                    child_height = size.1;

                    if alignment.is_centered() {
                        if self.orientation.is_vertical() {
                            widget.place((constraints.0 / 2) as i32 - (child_width / 2) as i32, current_y as i32);
                        }
                    } else {   
                        widget.place(current_x as i32, current_y as i32);
                    }
                }
            }

            // Determines size of view thus far & where to place next element
            match self.orientation {
                Orientation::Vertical => {
                    current_y += child_height + theme.widget_padding.vertical;
                    view_width = std::cmp::max(child_width, view_width);
                }
                Orientation::Horizontal => {
                    current_x += child_width + theme.widget_padding.horizontal;
                    view_height = std::cmp::max(child_height, view_height);
                }
            }
        }

        // NOTE: Subtraction is to remove the extra padding added in final iteration of the above loop
        if is_root { // Add extra padding at the end of the root view (to match the initial padding)
            match self.orientation {
                Orientation::Vertical => {
                    self.bounds.width = current_x + view_width + theme.view_padding.horizontal;
                    self.bounds.height = current_y + theme.view_padding.vertical - theme.widget_padding.vertical;
                }
                Orientation::Horizontal => {
                    self.bounds.width = current_x + theme.view_padding.horizontal - theme.widget_padding.horizontal;
                    self.bounds.height = current_y + view_height + theme.view_padding.vertical;
                }
            }
        } else { // Do not add any more padding --> treat child view just like a widget
            match self.orientation {
                Orientation::Vertical => {
                    self.bounds.width = view_width;
                    self.bounds.height = current_y - theme.widget_padding.vertical;
                }
                Orientation::Horizontal => {
                    self.bounds.width = current_x - theme.widget_padding.horizontal;
                    self.bounds.height = view_height;
                }
            }
        }

        // Translate the view to be centered vertically within its bounds
        if alignment.is_centered() {
            let view_center_y = self.bounds.height / 2;
            let bounds_center_y = constraints.1 / 2;
            self.translate(0, bounds_center_y as i32 - view_center_y as i32);
        }
    }
// TODO: Right alignment
// TODO: Finish Center alignment
// TODO: Test with VStack root and HStack root (ensure same behavior)
Right alignment
TODO: Finish Center alignment
TODO: Test with VStack root and HStack root (ensure same behavior)
Right alignment TODO : Finish Center alignment TODO : Test with VStack root and HStack root ( ensure same behavior )
fn layout(&mut self, renderer: &mut crate::render::Renderer, theme: &crate::style::Theme, constraints: (u32, u32), is_root: bool) {
        let alignment = if let Some(alignment) = self.alignment {
            alignment
        } else {
            theme.default_alignment
        };
        let mut current_x = 0;
        let mut current_y = 0;
        let mut view_width = 0;
        let mut view_height = 0;
        // Initial padding within window
        if is_root {
            if !alignment.is_centered() {
                current_x += theme.view_padding.horizontal;
            }
            // FIXME: Is this correct?
            current_y += theme.view_padding.vertical;
        }
        for child in &mut self.children {
            let child_width;
            let child_height;
            match child {
                ViewElement::View(view) => {
                    view.layout(renderer, theme, constraints, false);
                    let size = view.render_size();
                    child_width = size.0; 
                    child_height = size.1;
                    if alignment.is_centered() {
                        if self.orientation.is_vertical() {
                            view.translate((constraints.0 / 2) as i32 - (child_width / 2) as i32, current_y as i32);
                        }
                    } else {   
                        view.translate(current_x as i32, current_y as i32);
                    }
                }
                ViewElement::Widget(widget) => {
                    let size = widget.render_size(theme);
                    child_width = size.0; 
                    child_height = size.1;
                    if alignment.is_centered() {
                        if self.orientation.is_vertical() {
                            widget.place((constraints.0 / 2) as i32 - (child_width / 2) as i32, current_y as i32);
                        }
                    } else {   
                        widget.place(current_x as i32, current_y as i32);
                    }
                }
            }
            // Determines size of view thus far & where to place next element
            match self.orientation {
                Orientation::Vertical => {
                    current_y += child_height + theme.widget_padding.vertical;
                    view_width = std::cmp::max(child_width, view_width);
                }
                Orientation::Horizontal => {
                    current_x += child_width + theme.widget_padding.horizontal;
                    view_height = std::cmp::max(child_height, view_height);
                }
            }
        }
        // NOTE: Subtraction is to remove the extra padding added in final iteration of the above loop
        if is_root { // Add extra padding at the end of the root view (to match the initial padding)
            match self.orientation {
                Orientation::Vertical => {
                    self.bounds.width = current_x + view_width + theme.view_padding.horizontal;
                    self.bounds.height = current_y + theme.view_padding.vertical - theme.widget_padding.vertical;
                }
                Orientation::Horizontal => {
                    self.bounds.width = current_x + theme.view_padding.horizontal - theme.widget_padding.horizontal;
                    self.bounds.height = current_y + view_height + theme.view_padding.vertical;
                }
            }
        } else { // Do not add any more padding --> treat child view just like a widget
            match self.orientation {
                Orientation::Vertical => {
                    self.bounds.width = view_width;
                    self.bounds.height = current_y - theme.widget_padding.vertical;
                }
                Orientation::Horizontal => {
                    self.bounds.width = current_x - theme.widget_padding.horizontal;
                    self.bounds.height = view_height;
                }
            }
        }
        // Translate the view to be centered vertically within its bounds
        if alignment.is_centered() {
            let view_center_y = self.bounds.height / 2;
            let bounds_center_y = constraints.1 / 2;
            self.translate(0, bounds_center_y as i32 - view_center_y as i32);
        }
    }
fn layout ( & mut self , renderer : & mut crate :: render :: Renderer , theme : & crate :: style :: Theme , constraints : ( u32 , u32 ) , is_root : bool ) { let alignment = if let Some ( alignment ) = self . alignment { alignment } else { theme . default_alignment } ; let mut current_x = 0 ; let mut current_y = 0 ; let mut view_width = 0 ; let mut view_height = 0 ; // Initial padding within window if is_root { if ! alignment . is_centered ( ) { current_x += theme . view_padding . horizontal ; } // FIXME: Is this correct? current_y += theme . view_padding . vertical ; } for child in & mut self . children { let child_width ; let child_height ; match child { ViewElement :: View ( view ) => { view . layout ( renderer , theme , constraints , false ) ; let size = view . render_size ( ) ; child_width = size . 0 ; child_height = size . 1 ; if alignment . is_centered ( ) { if self . orientation . is_vertical ( ) { view . translate ( ( constraints . 0 / 2 ) as i32 - ( child_width / 2 ) as i32 , current_y as i32 ) ; } } else { view . translate ( current_x as i32 , current_y as i32 ) ; } } ViewElement :: Widget ( widget ) => { let size = widget . render_size ( theme ) ; child_width = size . 0 ; child_height = size . 1 ; if alignment . is_centered ( ) { if self . orientation . is_vertical ( ) { widget . place ( ( constraints . 0 / 2 ) as i32 - ( child_width / 2 ) as i32 , current_y as i32 ) ; } } else { widget . place ( current_x as i32 , current_y as i32 ) ; } } } // Determines size of view thus far & where to place next element match self . orientation { Orientation :: Vertical => { current_y += child_height + theme . widget_padding . vertical ; view_width = std :: cmp :: max ( child_width , view_width ) ; } Orientation :: Horizontal => { current_x += child_width + theme . widget_padding . horizontal ; view_height = std :: cmp :: max ( child_height , view_height ) ; } } } // NOTE: Subtraction is to remove the extra padding added in final iteration of the above loop if is_root { // Add extra padding at the end of the root view (to match the initial padding) match self . orientation { Orientation :: Vertical => { self . bounds . width = current_x + view_width + theme . view_padding . horizontal ; self . bounds . height = current_y + theme . view_padding . vertical - theme . widget_padding . vertical ; } Orientation :: Horizontal => { self . bounds . width = current_x + theme . view_padding . horizontal - theme . widget_padding . horizontal ; self . bounds . height = current_y + view_height + theme . view_padding . vertical ; } } } else { // Do not add any more padding --> treat child view just like a widget match self . orientation { Orientation :: Vertical => { self . bounds . width = view_width ; self . bounds . height = current_y - theme . widget_padding . vertical ; } Orientation :: Horizontal => { self . bounds . width = current_x - theme . widget_padding . horizontal ; self . bounds . height = view_height ; } } } // Translate the view to be centered vertically within its bounds if alignment . is_centered ( ) { let view_center_y = self . bounds . height / 2 ; let bounds_center_y = constraints . 1 / 2 ; self . translate ( 0 , bounds_center_y as i32 - view_center_y as i32 ) ; } }
TODO: Right alignment
TODO: Finish Center alignment
TODO: Test with VStack root and HStack root (ensure same behavior)
TODO : Right alignment TODO : Finish Center alignment TODO : Test with VStack root and HStack root ( ensure same behavior )
&mut self
renderer
&mut crate::render::Renderer
theme
&crate::style::Theme
constraints
(u32, u32)
is_root
bool
&mut self
renderer
&mut crate::render::Renderer
theme
&crate::style::Theme
constraints
(u32, u32)
is_root
bool