/// draw border and return the position & size of the inner canvas
/// (top, left, width, height)
draw border and return the position & size of the inner canvas
(top, left, width, height)
draw border and return the position & size of the inner canvas ( top left width height )
fn draw_border(&self, rect: Rectangle, canvas: &mut dyn Canvas) -> Result<()> {
        let Rectangle {
            top,
            left,
            width,
            height,
        } = rect;
        if self.border_top || self.border_bottom {
            if (height < 1) || (self.border_top && self.border_bottom && height < 2) {
                return Err("not enough height for border".into());
            }
        }
        if self.border_left || self.border_right {
            if (width < 1) || (self.border_left && self.border_right && width < 2) {
                return Err("not enough width for border".into());
            }
        }
        let bottom = max(top + height, 1) - 1;
        let right = max(left + width, 1) - 1;
        if self.border_top {
            let _ = canvas.print_with_attr(top, left, &"─".repeat(width), self.border_top_attr);
        }
        if self.border_bottom {
            let _ =
                canvas.print_with_attr(bottom, left, &"─".repeat(width), self.border_bottom_attr);
        }
        if self.border_left {
            for i in top..(top + height) {
                let _ = canvas.print_with_attr(i, left, "│", self.border_left_attr);
            }
        }
        if self.border_right {
            for i in top..(top + height) {
                let _ = canvas.print_with_attr(i, right, "│", self.border_right_attr);
            }
        }
        // draw 4 corners if necessary
        if self.border_top && self.border_left {
            let _ = canvas.put_cell(
                top,
                left,
                Cell::default().ch('┌').attribute(self.border_top_attr),
            );
        }
        if self.border_top && self.border_right {
            let _ = canvas.put_cell(
                top,
                right,
                Cell::default().ch('┐').attribute(self.border_top_attr),
            );
        }
        if self.border_bottom && self.border_left {
            let _ = canvas.put_cell(
                bottom,
                left,
                Cell::default().ch('└').attribute(self.border_bottom_attr),
            );
        }
        if self.border_bottom && self.border_right {
            let _ = canvas.put_cell(
                bottom,
                right,
                Cell::default().ch('┘').attribute(self.border_bottom_attr),
            );
        }
        if !self.title.is_empty() {
            let _ = canvas.print_with_attr(top, left + 2, &self.title, self.title_attr);
        }
        Ok(())
    }
fn draw_border ( & self , rect : Rectangle , canvas : & mut dyn Canvas ) -> Result < ( ) > { let Rectangle { top , left , width , height , } = rect ; if self . border_top || self . border_bottom { if ( height < 1 ) || ( self . border_top && self . border_bottom && height < 2 ) { return Err ( " " . into ( ) ) ; } } if self . border_left || self . border_right { if ( width < 1 ) || ( self . border_left && self . border_right && width < 2 ) { return Err ( " " . into ( ) ) ; } } let bottom = max ( top + height , 1 ) - 1 ; let right = max ( left + width , 1 ) - 1 ; if self . border_top { let _ = canvas . print_with_attr ( top , left , & " r e peat(w i dth), s lf.b o rder_top_attr); } if self . border_bottom { let _ = canvas . print_with_attr ( bottom , left , & " r e peat(w i dth), s lf.b o rder_bottom_attr); } if self . border_left { for i in top .. ( top + height ) { let _ = canvas . print_with_attr ( i , left , " s lf.b o rder_left_attr); } } if self . border_right { for i in top .. ( top + height ) { let _ = canvas . print_with_attr ( i , right , " s lf.b o rder_right_attr); } } // draw 4 corners if necessary if self . border_top && self . border_left { let _ = canvas . put_cell ( top , left , Cell :: default ( ) . ch ( '┌'). a t tribute(s e lf.b o rder_top_attr), ) ; } if self . border_top && self . border_right { let _ = canvas . put_cell ( top , right , Cell :: default ( ) . ch ( '┐'). a t tribute(s e lf.b o rder_top_attr), ) ; } if self . border_bottom && self . border_left { let _ = canvas . put_cell ( bottom , left , Cell :: default ( ) . ch ( '└'). a t tribute(s e lf.b o rder_bottom_attr), ) ; } if self . border_bottom && self . border_right { let _ = canvas . put_cell ( bottom , right , Cell :: default ( ) . ch ( '┘'). a t tribute(s e lf.b o rder_bottom_attr), ) ; } if ! self . title . is_empty ( ) { let _ = canvas . print_with_attr ( top , left + 2 , & self . title , self . title_attr ) ; } Ok ( ( ) ) }
draw border and return the position & size of the inner canvas
(top, left, width, height)
draw border and return the position & size of the inner canvas ( top left width height )
&self
rect
Rectangle
canvas
&mut dyn Canvas