pub fn build(mut self, layout: &FlexboxLayout) -> Result<(), NwgError> {
        use winapi::um::winuser::WM_SIZE;
        use winapi::shared::minwindef::{HIWORD, LOWORD};

        if self.layout.base.is_null() {
            return Err(NwgError::layout_create("Flexboxlayout does not have a parent."));
        }

        let (w, h) = unsafe { wh::get_window_size(self.layout.base) };
        let base_handle = ControlHandle::Hwnd(self.layout.base);

        // Auto compute size if enabled
        if self.auto_size {
            let children_count = self.layout.children.len();
            let size = 1.0f32 / (children_count as f32);
            for child in self.layout.children.iter_mut() {
                let child_size = match &self.layout.style.flex_direction {
                    FlexDirection::Row | FlexDirection::RowReverse => {
                        Size { width: Dimension::Percent(size), height: Dimension::Auto }
                    },
                    FlexDirection::Column | FlexDirection::ColumnReverse => {
                        Size { width: Dimension::Auto, height: Dimension::Percent(size) }
                    }
                };

                child.modify_style(|s| s.size = child_size);
            }
        }

        // Auto spacing if enabled
        if let Some(spacing) = self.auto_spacing {
            let spacing = Dimension::Points(spacing as f32);
            let spacing = Rect { start: spacing, end: spacing, top: spacing, bottom: spacing};
            self.layout.style.padding = spacing;
            for child in self.layout.children.iter_mut() {
                child.modify_style(|s| s.margin = spacing);
            }
        }

        // Saves the new layout. Free the old layout (if there is one)
        {
            let mut layout_inner = layout.inner.borrow_mut();
            if layout_inner.handler.is_some() {
                drop(unbind_raw_event_handler(layout_inner.handler.as_ref().unwrap()));
            }
            
            *layout_inner = self.layout;        
        }

        // Sets the parent_layout of any child layout to this layout
        for child in layout.inner.borrow_mut().children.iter_mut() {
            match child {
                FlexboxLayoutChild::Item(_) => {},
                FlexboxLayoutChild::Flexbox(child_layout) => { 
                    child_layout.inner.borrow_mut().parent_layout.replace(layout.clone()); 
                },
            }
        }

        // Initial layout update
        layout.update_layout(w, h, (0, 0)).expect("Failed to compute layout");

        // Fetch a new ID for the layout handler
        use std::sync::atomic::{AtomicUsize, Ordering};
        static FLEX_LAYOUT_ID: AtomicUsize = AtomicUsize::new(0x9FFF); 
        let handler_id = FLEX_LAYOUT_ID.fetch_add(1, Ordering::SeqCst);
 
        // Bind the event handler
        let event_layout = layout.clone();
        let cb = move |_h, msg, _w, l| {
            if msg == WM_SIZE {
                let size = l as u32;
                let width = LOWORD(size) as i32;
                let height = HIWORD(size) as i32;
                let (w, h) = unsafe { crate::win32::high_dpi::physical_to_logical(width, height) };
                FlexboxLayout::update_layout(&event_layout, w as u32, h as u32, (0, 0)).expect("Failed to compute layout!");
            }
            None
        };

        {
            let mut layout_inner = layout.inner.borrow_mut();
            layout_inner.handler = Some(bind_raw_event_handler_inner(&base_handle, handler_id, cb).unwrap());
        }

        Ok(())
    }
/// Build the layout object and bind the callback.
Build the layout object and bind the callback.
Build the layout object and bind the callback .
pub fn build(mut self, layout: &FlexboxLayout) -> Result<(), NwgError> {
        use winapi::um::winuser::WM_SIZE;
        use winapi::shared::minwindef::{HIWORD, LOWORD};
        if self.layout.base.is_null() {
            return Err(NwgError::layout_create("Flexboxlayout does not have a parent."));
        }
        let (w, h) = unsafe { wh::get_window_size(self.layout.base) };
        let base_handle = ControlHandle::Hwnd(self.layout.base);
        // Auto compute size if enabled
        if self.auto_size {
            let children_count = self.layout.children.len();
            let size = 1.0f32 / (children_count as f32);
            for child in self.layout.children.iter_mut() {
                let child_size = match &self.layout.style.flex_direction {
                    FlexDirection::Row | FlexDirection::RowReverse => {
                        Size { width: Dimension::Percent(size), height: Dimension::Auto }
                    },
                    FlexDirection::Column | FlexDirection::ColumnReverse => {
                        Size { width: Dimension::Auto, height: Dimension::Percent(size) }
                    }
                };
                child.modify_style(|s| s.size = child_size);
            }
        }
        // Auto spacing if enabled
        if let Some(spacing) = self.auto_spacing {
            let spacing = Dimension::Points(spacing as f32);
            let spacing = Rect { start: spacing, end: spacing, top: spacing, bottom: spacing};
            self.layout.style.padding = spacing;
            for child in self.layout.children.iter_mut() {
                child.modify_style(|s| s.margin = spacing);
            }
        }
        // Saves the new layout. Free the old layout (if there is one)
        {
            let mut layout_inner = layout.inner.borrow_mut();
            if layout_inner.handler.is_some() {
                drop(unbind_raw_event_handler(layout_inner.handler.as_ref().unwrap()));
            }
            *layout_inner = self.layout;        
        }
        // Sets the parent_layout of any child layout to this layout
        for child in layout.inner.borrow_mut().children.iter_mut() {
            match child {
                FlexboxLayoutChild::Item(_) => {},
                FlexboxLayoutChild::Flexbox(child_layout) => { 
                    child_layout.inner.borrow_mut().parent_layout.replace(layout.clone()); 
                },
            }
        }
        // Initial layout update
        layout.update_layout(w, h, (0, 0)).expect("Failed to compute layout");
        // Fetch a new ID for the layout handler
        use std::sync::atomic::{AtomicUsize, Ordering};
        static FLEX_LAYOUT_ID: AtomicUsize = AtomicUsize::new(0x9FFF); 
        let handler_id = FLEX_LAYOUT_ID.fetch_add(1, Ordering::SeqCst);
        // Bind the event handler
        let event_layout = layout.clone();
        let cb = move |_h, msg, _w, l| {
            if msg == WM_SIZE {
                let size = l as u32;
                let width = LOWORD(size) as i32;
                let height = HIWORD(size) as i32;
                let (w, h) = unsafe { crate::win32::high_dpi::physical_to_logical(width, height) };
                FlexboxLayout::update_layout(&event_layout, w as u32, h as u32, (0, 0)).expect("Failed to compute layout!");
            }
            None
        };
        {
            let mut layout_inner = layout.inner.borrow_mut();
            layout_inner.handler = Some(bind_raw_event_handler_inner(&base_handle, handler_id, cb).unwrap());
        }
        Ok(())
    }
pub fn build ( mut self , layout : & FlexboxLayout ) -> Result < ( ) , NwgError > { use winapi :: um :: winuser :: WM_SIZE ; use winapi :: shared :: minwindef :: { HIWORD , LOWORD } ; if self . layout . base . is_null ( ) { return Err ( NwgError :: layout_create ( " " ) ) ; } let ( w , h ) = unsafe { wh :: get_window_size ( self . layout . base ) } ; let base_handle = ControlHandle :: Hwnd ( self . layout . base ) ; // Auto compute size if enabled if self . auto_size { let children_count = self . layout . children . len ( ) ; let size = 1.0f32 / ( children_count as f32 ) ; for child in self . layout . children . iter_mut ( ) { let child_size = match & self . layout . style . flex_direction { FlexDirection :: Row | FlexDirection :: RowReverse => { Size { width : Dimension :: Percent ( size ) , height : Dimension :: Auto } } , FlexDirection :: Column | FlexDirection :: ColumnReverse => { Size { width : Dimension :: Auto , height : Dimension :: Percent ( size ) } } } ; child . modify_style ( | s | s . size = child_size ) ; } } // Auto spacing if enabled if let Some ( spacing ) = self . auto_spacing { let spacing = Dimension :: Points ( spacing as f32 ) ; let spacing = Rect { start : spacing , end : spacing , top : spacing , bottom : spacing } ; self . layout . style . padding = spacing ; for child in self . layout . children . iter_mut ( ) { child . modify_style ( | s | s . margin = spacing ) ; } } // Saves the new layout. Free the old layout (if there is one) { let mut layout_inner = layout . inner . borrow_mut ( ) ; if layout_inner . handler . is_some ( ) { drop ( unbind_raw_event_handler ( layout_inner . handler . as_ref ( ) . unwrap ( ) ) ) ; } * layout_inner = self . layout ; } // Sets the parent_layout of any child layout to this layout for child in layout . inner . borrow_mut ( ) . children . iter_mut ( ) { match child { FlexboxLayoutChild :: Item ( _ ) => { } , FlexboxLayoutChild :: Flexbox ( child_layout ) => { child_layout . inner . borrow_mut ( ) . parent_layout . replace ( layout . clone ( ) ) ; } , } } // Initial layout update layout . update_layout ( w , h , ( 0 , 0 ) ) . expect ( " " ) ; // Fetch a new ID for the layout handler use std :: sync :: atomic :: { AtomicUsize , Ordering } ; static FLEX_LAYOUT_ID : AtomicUsize = AtomicUsize :: new ( 0x9FFF ) ; let handler_id = FLEX_LAYOUT_ID . fetch_add ( 1 , Ordering :: SeqCst ) ; // Bind the event handler let event_layout = layout . clone ( ) ; let cb = move | _h , msg , _w , l | { if msg == WM_SIZE { let size = l as u32 ; let width = LOWORD ( size ) as i32 ; let height = HIWORD ( size ) as i32 ; let ( w , h ) = unsafe { crate :: win32 :: high_dpi :: physical_to_logical ( width , height ) } ; FlexboxLayout :: update_layout ( & event_layout , w as u32 , h as u32 , ( 0 , 0 ) ) . expect ( " " ) ; } None } ; { let mut layout_inner = layout . inner . borrow_mut ( ) ; layout_inner . handler = Some ( bind_raw_event_handler_inner ( & base_handle , handler_id , cb ) . unwrap ( ) ) ; } Ok ( ( ) ) }
Build the layout object and bind the callback.
Build the layout object and bind the callback .
mut self
layout
&FlexboxLayout