[ Widgets ]
Rule
koto::Rule draws a horizontal divider line across the vertical center of an area with an optional space-padded title (Header: koto/rule.hpp).
Quick example
Section titled “Quick example”Rule("Section") .style(BorderStyle::Double) .title_align(TitleAlign::Center) .fg(Color::Cyan) .title_fg(Color::White) .draw(frame, rule_area);════════════ Section ═════════════Behavior
Section titled “Behavior”- Vertical centering:
Rule::draw()draws on a single row atrow = area.row + (area.height - 1) / 2(src/rule.cpp:64). Rows above and belowrowinareaare untouched. - Line glyph selection:
BorderStyle::SingleandBorderStyle::RoundeduseU'─',BorderStyle::DoubleusesU'═',BorderStyle::ThickusesU'━', andBorderStyle::NoneusesU' '(src/rule.cpp:66-83). - Title padding and alignment: When
m_titleis non-empty,Ruleconstructspadded = " " + m_title + " "and measurestitle_w = text_width(padded). Iftitle_w > area.width, the title is skipped and the solid line remains intact. Otherwise:TitleAlign::Leftplacespaddedatarea.col + 2(clamped to[area.col, area.right() - title_w]).TitleAlign::Centerplacespaddedatarea.col + (area.width - title_w) / 2.TitleAlign::Rightplacespaddedatarea.right() - 2 - title_w(clamped to[area.col, area.right() - title_w]).
- Title color fallback: If
m_title_fg == COLOR_DEFAULT, the title usesm_fg; ifm_title_bg == COLOR_DEFAULT, the title usesm_bg(src/rule.cpp:122-123).
Methods
Section titled “Methods”| Method | Description | Default |
|---|---|---|
Rule(std::string_view title = "") | Constructs a Rule with an optional title string. | title = "" |
title(std::string_view title) | Sets the embedded title text. | "" |
title_align(TitleAlign align) | Sets horizontal title alignment (Left, Center, Right). | TitleAlign::Center |
style(BorderStyle style) | Sets the horizontal line glyph style (Single, Rounded, Double, Thick, None). | BorderStyle::Single |
fg(Color fg) | Sets the line foreground color (and fallback title foreground). | COLOR_DEFAULT |
bg(Color bg) | Sets the line background color (and fallback title background). | COLOR_DEFAULT |
title_fg(Color fg) | Sets an explicit foreground color for the padded title. | COLOR_DEFAULT (falls back to fg) |
title_bg(Color bg) | Sets an explicit background color for the padded title. | COLOR_DEFAULT (falls back to bg) |
draw(Frame& frame, Area area) | Renders the horizontal rule into frame within area. | None |
Gotchas
Section titled “Gotchas”- Method name is
.style(...), not.border_style(...): UnlikeBox,Button,List,Tabs,TextArea, andTextInput,Rulenames itsBorderStylesetter.style(BorderStyle)(include/koto/rule.hpp:19). - No
.id(...)method:Ruleis a purely decorative divider and does not expose.id(Id).