Skip to content

[ Widgets ]

Fill and Clear

koto::Fill fills a rectangular area with a repeated codepoint, foreground/background colors, and an optional id tag, while koto::Clear resets an area to spaces (U' ') with COLOR_DEFAULT colors (Header: koto/fill.hpp).

Fill and Clear
Fill(Color::DarkGray)
.fg(Color::Cyan)
.char_code(U'.')
.id(Id("backdrop"))
.draw(frame, fill_area);
Output
........................
........................
........................
........................
  • Fill::draw(frame, area): Calls frame.fill(area, m_ch, m_fg, m_bg, m_tag_id) (src/fill.cpp:35-38), which writes Cell{m_ch, m_fg, m_bg, 1, false} to every coordinate in area and, if m_tag_id is not Id::none(), stamps m_hit_buffer and updates m_tag_bounds.
  • Clear::draw(frame, area): Calls frame.fill(area, U' ', COLOR_DEFAULT, COLOR_DEFAULT, m_tag_id) (src/fill.cpp:46-49), resetting every cell in area to a default blank space and optionally tagging the region with m_tag_id.
MethodDescriptionDefault
Fill()Default-constructs a Fill widget with U' ' and COLOR_DEFAULT colors.m_ch = U' ', m_fg = COLOR_DEFAULT, m_bg = COLOR_DEFAULT
Fill(Color bg)Explicit constructor setting m_bg = bg.value.m_ch = U' ', m_fg = COLOR_DEFAULT
bg(Color color)Sets the fill background color.COLOR_DEFAULT
fg(Color color)Sets the fill character foreground color.COLOR_DEFAULT
char_code(char32_t ch)Sets the codepoint written to each cell.U' '
id(Id id)Sets the id token stamped into the hit buffer across area.Id::none()
draw(Frame& frame, Area area)Fills area in frame.None
MethodDescriptionDefault
Clear()Default-constructs a Clear widget.m_tag_id = Id::none()
id(Id id)Sets the id token stamped into the hit buffer across area.Id::none()
draw(Frame& frame, Area area)Resets area in frame to U' ' with COLOR_DEFAULT foreground and background.None
  • Fill::char_code uses width 1 in Frame::fill: Frame::fill(area, m_ch, m_fg, m_bg, m_tag_id) constructs Cell{ch, fg, bg, 1, false} (src/frame.cpp:167-170), which Frame::set_cell promotes to width 2 if codepoint_width(ch) == 2. Avoid passing a 2-column CJK or emoji codepoint to Fill::char_code, because Frame::fill steps col by 1 across every column and each column will overwrite the continuation cell of the previous column.