[ Widgets ]
Box
koto::Box draws a rectangular border, optional interior fill, and an optional top-edge title into an area (Header: koto/box.hpp).
Quick example
Section titled “Quick example”Box() .border_style(BorderStyle::Rounded) .title("System Status") .title_align(TitleAlign::Center) .fg(Color::Cyan) .filled(true) .draw(frame, box_area);╭──────── System Status ─────────╮│ ││ ││ │╰────────────────────────────────╯Behavior
Section titled “Behavior”- Hit-buffer tagging: When
.id(Id(...))or.tag(Id(...))is set to a non-emptyid,Box::draw()callsframe.tag_area(area, m_tag_id)across the entirearea(even whenfilled(false)), and also passesm_tag_idto every border and interiorframe.set_cell()call. - Border styles and edge toggles:
BorderStyleselects the corner and edge glyphs (Noneuses spacesU' ',Singleuses┌┐└┘─│,Doubleuses╔╗╚╝═║,Roundeduses╭╮╰╯─│,Thickuses┏┓┗┛━┃).Borders({top, bottom, left, right}, alltrueby default) controls individual edges; whenborders.leftorborders.rightisfalse, the top and bottom corner cells draw the horizontal glyph instead of a corner glyph. - Interior fill: When
filled(false)(the default), interior cells (!on_border) are skipped and retain whatever was previously in theframeback buffer. Whenfilled(true), interior cells are overwritten withCell{U' ', m_fg, m_bg}. - Title rendering: The title is drawn on
area.rowonly when!m_title.empty()andtext_width(m_title) + 4 <= area.width.TitleAlign::Leftstarts atarea.col + 3,TitleAlign::Centerstarts atarea.col + (area.width - title_width) / 2, andTitleAlign::Rightstarts atarea.right() - title_width - 2. Single space cells are placed immediately before (title_col - 1) and after (title_col + title_width) the title text. - Focus styling: When
focused(true)is set, the border color switches fromm_fgtom_focused_border_fg(Color::Cyanby default), the title foreground defaults toborder_colorifm_title_fg == COLOR_DEFAULT, and the border style switches tom_focused_border_styleonly if.focused_border_style(...)was explicitly called.
Methods
Section titled “Methods”| Method | Description | Default |
|---|---|---|
Box() | Constructs a Box with default single border and centered title alignment. | See member defaults |
fg(Color fg) | Sets the unfocused border foreground color (and interior space foreground when filled(true)). | COLOR_DEFAULT |
bg(Color bg) | Sets the border background color and interior fill background color when filled(true). | COLOR_DEFAULT |
title_fg(Color fg) | Sets the title text foreground color (if COLOR_DEFAULT and focused(true), uses focused_border_fg). | COLOR_DEFAULT |
title_bg(Color bg) | Sets the background color of the title text and its two flanking space cells. | COLOR_DEFAULT |
filled(bool fill) | Enables or disables filling interior cells with Cell{U' ', m_fg, m_bg}. | false |
border_style(BorderStyle style) | Sets the border glyph style (None, Single, Double, Rounded, Thick). | BorderStyle::Single |
borders(Borders borders) | Enables or disables individual edges ({top, bottom, left, right}). | {true, true, true, true} |
title(std::string title) | Sets the top-border title string. | "" |
title_align(TitleAlign align) | Sets horizontal title alignment (Left, Center, Right). | TitleAlign::Center |
focused(bool is_focused) | Enables or disables focused border/title styling. | false |
focused_border_fg(Color fg) | Sets the border foreground color used when focused(true). | Color::Cyan |
focused_border_style(BorderStyle style) | Sets an explicit border style to use when focused(true). | BorderStyle::Thick (inactive unless called) |
id(Id tag_id) | Sets the id token stamped into the frame hit buffer. | Id::none() |
tag(Id tag_id) | Alias for id(tag_id). | Id::none() |
draw(Frame& frame, Area area) | Renders the box into frame within area. | None |
Gotchas
Section titled “Gotchas”- There is no
.border_fg()method: Use.fg(Color)for the unfocused border color and.focused_border_fg(Color)for the focused border color. - Default
title_alignisTitleAlign::Center: UnlikeList,Tabs, andTextArea(which default toTitleAlign::Left),Boxdefaults toTitleAlign::Center(include/koto/box.hpp:62). - Narrow boxes omit the title: If
text_width(title) + 4 > area.width,Box::draw()does not truncate the title; it skips drawing the title entirely so the corner glyphs remain intact (src/box.cpp:268). - 1x1 or 1-row areas:
Box::draw()only checksif (!area.is_valid()) return;. In an area withheight == 1orwidth == 1,on_topandon_bottom(oron_leftandon_right) are both true, so the top/left branch wins.