Documentation
¶
Overview ¶
Package style defines layout and appearance properties for Kite elements. Build a Style with S and its chainable methods. Optional values distinguish an unset property from an explicit zero; Computed holds resolved values after defaults, inheritance, and other style rules have been applied.
s := style.S().Padding(1, 2).Gap(1).Border(style.SingleBorder())
Index ¶
- Constants
- Variables
- func Hex(hex string) color.Color
- func HexInt(v uint32) color.Color
- func IsTerminalDefault(c color.Color) bool
- func ParseHex(hex string) (color.Color, error)
- func RGB(r, g, b uint8) color.Color
- func RGBA(r, g, b, a uint8) color.Color
- type Align
- type Border
- func (b Border) Bottom(visible bool) Border
- func (b Border) Color(c color.Color) Border
- func (b Border) CornerOverride(tl, tr, bl, br string) Border
- func (b Border) Left(visible bool) Border
- func (b Border) Right(visible bool) Border
- func (b Border) Some() Optional[Border]
- func (b Border) Style(s BorderStyle) Border
- func (b Border) Top(visible bool) Border
- func (b Border) Widths() EdgeValues[int]
- type BorderGlyphs
- type BorderStyle
- type ColorScheme
- type Computed
- type Cursor
- type CursorShape
- type Dimension
- type DimensionKind
- type Display
- type EdgeValues
- type FlexDirection
- type FlexItemValue
- type FlexWrap
- type GapValue
- type GridPlacement
- type GridTrackSize
- type Justify
- type ListStyleType
- type MediaContext
- type MediaQuery
- func (q MediaQuery) ColorScheme(scheme ColorScheme) MediaQuery
- func (q MediaQuery) Matches(viewport geom.Size) bool
- func (q MediaQuery) MatchesContext(ctx MediaContext) bool
- func (q MediaQuery) MaxHeight(h int) MediaQuery
- func (q MediaQuery) MaxWidth(w int) MediaQuery
- func (q MediaQuery) MinHeight(h int) MediaQuery
- func (q MediaQuery) MinWidth(w int) MediaQuery
- type MediaRule
- type Optional
- func (o Optional[T]) Get() (T, bool)
- func (o Optional[T]) IsSet() bool
- func (o Optional[T]) MarshalJSON() ([]byte, error)
- func (o Optional[T]) Merge(other Optional[T]) Optional[T]
- func (o *Optional[T]) Set(v T)
- func (o *Optional[T]) UnmarshalJSON(data []byte) error
- func (o *Optional[T]) Unset()
- func (o Optional[T]) UnwrapOr(fallback T) T
- func (o Optional[T]) Value() T
- type Overflow
- type OverflowWrap
- type PseudoRule
- type PseudoState
- type Scrollbar
- type Sheet
- type Style
- func (s Style) Active(ruleStyle Style) Style
- func (s Style) AlignContent(v Align) Style
- func (s Style) AlignContentOpt() Optional[Align]
- func (s Style) AlignItems(v Align) Style
- func (s Style) AlignItemsOpt() Optional[Align]
- func (s Style) AlignSelf(v Align) Style
- func (s Style) AlignSelfOpt() Optional[Align]
- func (s Style) Apply(base Computed) Computed
- func (s Style) Background(v color.Color) Style
- func (s Style) BackgroundOpt() Optional[color.Color]
- func (s Style) Bold(v bool) Style
- func (s Style) BoldOpt() Optional[bool]
- func (s Style) Border(args ...any) Style
- func (s Style) BorderBottom(visible bool, args ...any) Style
- func (s Style) BorderHorizontal(visible bool, args ...any) Style
- func (s Style) BorderLeft(visible bool, args ...any) Style
- func (s Style) BorderOpt() Optional[Border]
- func (s Style) BorderRight(visible bool, args ...any) Style
- func (s Style) BorderTop(visible bool, args ...any) Style
- func (s Style) BorderVertical(visible bool, args ...any) Style
- func (s Style) Cursor(v Cursor) Style
- func (s Style) CursorOpt() Optional[Cursor]
- func (s Style) Disabled(ruleStyle Style) Style
- func (s Style) Display(v Display) Style
- func (s Style) DisplayOpt() Optional[Display]
- func (s Style) Equal(other Style) bool
- func (s Style) EvaluateMedia(viewport geom.Size) Style
- func (s Style) EvaluateMediaContext(ctx MediaContext) Style
- func (s Style) EvaluatePseudo(active PseudoState) Style
- func (s Style) Flex(grow int, rest ...any) Style
- func (s Style) FlexDirection(v FlexDirection) Style
- func (s Style) FlexDirectionOpt() Optional[FlexDirection]
- func (s Style) FlexOpt() Optional[FlexItemValue]
- func (s Style) FlexWrap(v FlexWrap) Style
- func (s Style) FlexWrapOpt() Optional[FlexWrap]
- func (s Style) Focus(ruleStyle Style) Style
- func (s Style) Foreground(v color.Color) Style
- func (s Style) ForegroundOpt() Optional[color.Color]
- func (s Style) Gap(values ...int) Style
- func (s Style) GapOpt() Optional[GapValue]
- func (s Style) GridColumn(v GridPlacement) Style
- func (s Style) GridColumnGap(v int) Style
- func (s Style) GridColumnGapOpt() Optional[int]
- func (s Style) GridColumnOpt() Optional[GridPlacement]
- func (s Style) GridRow(v GridPlacement) Style
- func (s Style) GridRowGap(v int) Style
- func (s Style) GridRowGapOpt() Optional[int]
- func (s Style) GridRowOpt() Optional[GridPlacement]
- func (s Style) GridTemplateColumns(v ...GridTrackSize) Style
- func (s Style) GridTemplateColumnsOpt() Optional[[]GridTrackSize]
- func (s Style) GridTemplateRows(v ...GridTrackSize) Style
- func (s Style) GridTemplateRowsOpt() Optional[[]GridTrackSize]
- func (s Style) HasMediaRules() bool
- func (s Style) HasPseudoRules() bool
- func (s Style) Height(v Dimension) Style
- func (s Style) HeightOpt() Optional[Dimension]
- func (s Style) Hover(ruleStyle Style) Style
- func (s Style) Italic(v bool) Style
- func (s Style) ItalicOpt() Optional[bool]
- func (s Style) JustifyContent(v Justify) Style
- func (s Style) JustifyContentOpt() Optional[Justify]
- func (s Style) ListStyleType(v ListStyleType) Style
- func (s Style) ListStyleTypeOpt() Optional[ListStyleType]
- func (s Style) Margin(values ...int) Style
- func (s Style) MarginBottom(v int) Style
- func (s Style) MarginHorizontal(v int) Style
- func (s Style) MarginLeft(v int) Style
- func (s Style) MarginOpt() Optional[EdgeValues[int]]
- func (s Style) MarginRight(v int) Style
- func (s Style) MarginTop(v int) Style
- func (s Style) MarginVertical(v int) Style
- func (s Style) MarshalJSON() ([]byte, error)
- func (s Style) MaxHeight(v Dimension) Style
- func (s Style) MaxHeightOpt() Optional[Dimension]
- func (s Style) MaxWidth(v Dimension) Style
- func (s Style) MaxWidthOpt() Optional[Dimension]
- func (s Style) Media(q MediaQuery, ruleStyle Style) Style
- func (s Style) Merge(override Style) Style
- func (s Style) MinHeight(v Dimension) Style
- func (s Style) MinHeightOpt() Optional[Dimension]
- func (s Style) MinWidth(v Dimension) Style
- func (s Style) MinWidthOpt() Optional[Dimension]
- func (s Style) Order(v int) Style
- func (s Style) OrderOpt() Optional[int]
- func (s Style) Overflow(v Overflow) Style
- func (s Style) OverflowWrap(v OverflowWrap) Style
- func (s Style) OverflowWrapOpt() Optional[OverflowWrap]
- func (s Style) OverflowX(v Overflow) Style
- func (s Style) OverflowXOpt() Optional[Overflow]
- func (s Style) OverflowY(v Overflow) Style
- func (s Style) OverflowYOpt() Optional[Overflow]
- func (s Style) Padding(values ...int) Style
- func (s Style) PaddingBottom(v int) Style
- func (s Style) PaddingHorizontal(v int) Style
- func (s Style) PaddingLeft(v int) Style
- func (s Style) PaddingOpt() Optional[EdgeValues[int]]
- func (s Style) PaddingRight(v int) Style
- func (s Style) PaddingTop(v int) Style
- func (s Style) PaddingVertical(v int) Style
- func (s Style) Pseudo(state PseudoState, ruleStyle Style) Style
- func (s Style) Reverse(v bool) Style
- func (s Style) ReverseOpt() Optional[bool]
- func (s Style) Scrollbar(v Scrollbar) Style
- func (s Style) ScrollbarOpt() Optional[Scrollbar]
- func (s Style) ScrollbarThumb(glyph rune, c color.Color) Style
- func (s Style) ScrollbarTrack(glyph rune, c color.Color) Style
- func (s Style) ScrollbarX(v bool) Style
- func (s Style) ScrollbarY(v bool) Style
- func (s Style) SelectionBackground(v color.Color) Style
- func (s Style) SelectionBackgroundOpt() Optional[color.Color]
- func (s Style) SelectionForeground(v color.Color) Style
- func (s Style) SelectionForegroundOpt() Optional[color.Color]
- func (s Style) Strikethrough(v bool) Style
- func (s Style) StrikethroughOpt() Optional[bool]
- func (s Style) TextAlign(v TextAlign) Style
- func (s Style) TextAlignOpt() Optional[TextAlign]
- func (s Style) TextOverflow(v TextOverflow) Style
- func (s Style) TextOverflowOpt() Optional[TextOverflow]
- func (s Style) TextWrap(v TextWrap) Style
- func (s Style) TextWrapOpt() Optional[TextWrap]
- func (s Style) Underline(v bool) Style
- func (s Style) UnderlineOpt() Optional[bool]
- func (s Style) When(cond bool, other Style) Style
- func (s Style) WhiteSpace(v WhiteSpace) Style
- func (s Style) WhiteSpaceOpt() Optional[WhiteSpace]
- func (s Style) Width(v Dimension) Style
- func (s Style) WidthOpt() Optional[Dimension]
- func (s Style) WithoutRules() Style
- func (s Style) WordBreak(v WordBreak) Style
- func (s Style) WordBreakOpt() Optional[WordBreak]
- type TextAlign
- type TextOverflow
- type TextWrap
- type WhiteSpace
- type WordBreak
Examples ¶
Constants ¶
const ( DefaultScrollbarTrackVertical = '│' DefaultScrollbarThumbVertical = '┃' DefaultScrollbarTrackHorizontal = '─' DefaultScrollbarThumbHorizontal = '━' )
Default glyphs for scrollbars.
Variables ¶
var Auto = Dimension{/* contains filtered or unexported fields */}
Auto is a Dimension that lets the layout engine choose the size.
var BorderGlyphsMap = map[BorderStyle]BorderGlyphs{ BorderSingle: {H: "─", V: "│", TL: "┌", TR: "┐", BL: "└", BR: "┘"}, BorderDouble: {H: "═", V: "║", TL: "╔", TR: "╗", BL: "╚", BR: "╝"}, BorderRounded: {H: "─", V: "│", TL: "╭", TR: "╮", BL: "╰", BR: "╯"}, BorderThick: {H: "━", V: "┃", TL: "┏", TR: "┓", BL: "┗", BR: "┛"}, BorderASCII: {H: "-", V: "|", TL: "+", TR: "+", BL: "+", BR: "+"}, }
BorderGlyphsMap defines the standard box-drawing characters for each style.
var Content = Dimension{/* contains filtered or unexported fields */}
Content is a Dimension that sizes the element to fit its content, capped at the available width.
var MaxContent = Dimension{/* contains filtered or unexported fields */}
MaxContent is a Dimension that sizes the element to its unconstrained max-content width, not capped by the available width. Used for UA shadow subtree inner elements that need to overflow a clip container.
var TerminalDefault color.Color = terminalDefaultColor{}
TerminalDefault is the sentinel color meaning "use the terminal's default foreground or background." Backends recognise this value and emit the terminal's default-color escape sequence instead of an explicit RGB color.
Callers should compare against this value using == (it is a package-level variable, not a type), or via a type assertion to the unexported terminalDefaultColor type.
Functions ¶
func Hex ¶
Hex parses a CSS-style hex color string via ParseHex. On invalid input, it returns opaque black (color.RGBA{A: 255}) without panicking.
func IsTerminalDefault ¶
IsTerminalDefault reports whether c is the TerminalDefault sentinel.
func ParseHex ¶
ParseHex parses a CSS-style hex color string in #RGB, RGB, #RRGGBB, RRGGBB, #RRGGBBAA, or RRGGBBAA format (case-insensitive).
Types ¶
type Align ¶
type Align uint8
Align controls cross-axis alignment.
const ( // AlignAuto defers to the parent's AlignItems. AlignAuto Align = iota // AlignStart aligns items at the cross-start edge. AlignStart // AlignEnd aligns items at the cross-end edge. AlignEnd // AlignCenter centers items along the cross axis. AlignCenter // AlignStretch stretches items to fill the cross axis. AlignStretch // AlignBaseline aligns items along their text baselines. AlignBaseline )
type Border ¶
type Border struct {
// Edges defines which sides of the box have a border visible.
Edges EdgeValues[bool] `json:"edges"`
// Styles selects the glyph set for each side.
Styles EdgeValues[BorderStyle] `json:"styles"`
// Colors sets the foreground color for each side's border.
Colors EdgeValues[color.Color] `json:"colors"`
// Glyphs provides per-corner override characters.
Glyphs BorderGlyphs `json:"glyphs"`
}
Border describes the per-side border properties of an element. In a terminal UI, borders always occupy exactly one cell if present.
func DoubleBorder ¶
func DoubleBorder() Border
DoubleBorder returns a standard double-line border on all sides.
func RoundedBorder ¶
func RoundedBorder() Border
RoundedBorder returns a single-line border with rounded corners.
func SingleBorder ¶
func SingleBorder() Border
SingleBorder returns a standard single-line border on all sides.
func (Border) CornerOverride ¶
CornerOverride sets manual overrides for the four corners.
func (Border) Style ¶
func (b Border) Style(s BorderStyle) Border
Style sets the border style for all edges.
func (Border) Widths ¶
func (b Border) Widths() EdgeValues[int]
Widths returns the integer width of each edge (1 or 0).
type BorderGlyphs ¶
type BorderGlyphs struct {
// Base glyphs (active when the corresponding Override is unset).
H, V string // horizontal and vertical bar
TL, TR string // top-left and top-right corners
BL, BR string // bottom-left and bottom-right corners
// Per-corner optional overrides. When set, these take precedence over
// the matching base field.
OverrideTL Optional[string]
OverrideTR Optional[string]
OverrideBL Optional[string]
OverrideBR Optional[string]
}
BorderGlyphs defines the characters used to draw a border. The base fields (H, V, TL, TR, BL, BR) specify the default glyph set. The Override* fields are Optional; when set they replace the corresponding base field so callers can swap a single corner without redefining the entire glyph set.
func (BorderGlyphs) EffectiveBL ¶
func (g BorderGlyphs) EffectiveBL() string
EffectiveBL returns the bottom-left corner glyph, applying any override.
func (BorderGlyphs) EffectiveBR ¶
func (g BorderGlyphs) EffectiveBR() string
EffectiveBR returns the bottom-right corner glyph, applying any override.
func (BorderGlyphs) EffectiveTL ¶
func (g BorderGlyphs) EffectiveTL() string
EffectiveTL returns the top-left corner glyph, applying any override.
func (BorderGlyphs) EffectiveTR ¶
func (g BorderGlyphs) EffectiveTR() string
EffectiveTR returns the top-right corner glyph, applying any override.
type BorderStyle ¶
type BorderStyle uint8
BorderStyle selects the pre-defined glyph set for a border.
const ( // BorderNone draws no border. BorderNone BorderStyle = iota // BorderSingle draws a single-line border (─ │ ┌ ┐ └ ┘). BorderSingle // BorderDouble draws a double-line border (═ ║ ╔ ╗ ╚ ╝). BorderDouble // BorderRounded draws a rounded border (─ │ ╭ ╮ ╰ ╯). BorderRounded // BorderThick draws a heavy-line border (━ ┃ ┏ ┓ ┗ ┛). BorderThick // BorderASCII draws an ASCII border (- | + + + +). BorderASCII // BorderCustom uses the glyphs supplied in [BorderGlyphs] verbatim. BorderCustom )
type ColorScheme ¶
type ColorScheme uint8
ColorScheme represents the host terminal or browser's preferred background appearance (analogous to CSS prefers-color-scheme).
const ( // ColorSchemeUnknown indicates the host did not report a preference. ColorSchemeUnknown ColorScheme = iota // ColorSchemeDark indicates a dark host background preference. ColorSchemeDark // ColorSchemeLight indicates a light host background preference. ColorSchemeLight )
func (ColorScheme) String ¶
func (s ColorScheme) String() string
String returns "dark", "light", or "unknown".
type Computed ¶
type Computed struct {
Display Display `json:"display"`
ListStyleType ListStyleType `json:"listStyleType"`
FlexDirection FlexDirection `json:"flexDirection"`
FlexWrap FlexWrap `json:"flexWrap"`
JustifyContent Justify `json:"justifyContent"`
AlignItems Align `json:"alignItems"`
AlignContent Align `json:"alignContent"`
AlignSelf Align `json:"alignSelf"`
Gap GapValue `json:"gap"`
Flex FlexItemValue `json:"flex"`
Order int `json:"order"`
GridTemplateColumns []GridTrackSize `json:"gridTemplateColumns"`
GridTemplateRows []GridTrackSize `json:"gridTemplateRows"`
GridColumnGap int `json:"gridColumnGap"`
GridRowGap int `json:"gridRowGap"`
GridColumn GridPlacement `json:"gridColumn"`
GridRow GridPlacement `json:"gridRow"`
Width Dimension `json:"width"`
Height Dimension `json:"height"`
MinWidth Dimension `json:"minWidth"`
MaxWidth Dimension `json:"maxWidth"`
MinHeight Dimension `json:"minHeight"`
MaxHeight Dimension `json:"maxHeight"`
Padding EdgeValues[int] `json:"padding"`
Margin EdgeValues[int] `json:"margin"`
Border Border `json:"border"`
// Foreground is never nil after resolution; it may be [TerminalDefault].
Foreground color.Color `json:"foreground"`
// Background is never nil after resolution; it may be color.Transparent.
Background color.Color `json:"background"`
Bold bool `json:"bold"`
Italic bool `json:"italic"`
Underline bool `json:"underline"`
Strikethrough bool `json:"strikethrough"`
Reverse bool `json:"reverse"`
SelectionForeground color.Color `json:"selectionForeground"`
SelectionBackground color.Color `json:"selectionBackground"`
TextAlign TextAlign `json:"textAlign"`
TextWrap TextWrap `json:"textWrap"`
TextOverflow TextOverflow `json:"textOverflow"`
WhiteSpace WhiteSpace `json:"whiteSpace"`
WordBreak WordBreak `json:"wordBreak"`
OverflowWrap OverflowWrap `json:"overflowWrap"`
OverflowX Overflow `json:"overflowX"`
OverflowY Overflow `json:"overflowY"`
Scrollbar Scrollbar `json:"scrollbar"`
Cursor Cursor `json:"cursor"`
}
Computed is the fully-resolved style produced by the style resolver (Task 06). Every field has a concrete value; there are no Optional wrappers. The render layer reads Computed exclusively; it never inspects Style directly.
func DefaultStyle ¶
func DefaultStyle() Computed
DefaultStyle returns a copy of the baseline Computed for a kitex element: the value each property takes when neither the element nor any ancestor provides it. The returned value is a plain struct copy; callers may modify it freely.
func (*Computed) AffectsLayout ¶
AffectsLayout returns true if the change between c and other requires a re-layout.
func (*Computed) AffectsPaint ¶
AffectsPaint returns true if the change between c and other requires a repaint (assuming AffectsLayout returned false).
type Cursor ¶
type Cursor struct {
// Shape is the visual shape of the terminal hardware cursor.
Shape Optional[CursorShape]
// Blink controls whether the cursor blinks. The default is true.
Blink Optional[bool]
// Color is the terminal hardware cursor color. The default is the foreground
// color.
Color Optional[color.Color]
}
type CursorShape ¶
type CursorShape uint8
CursorShape represents the visual shape of the terminal hardware cursor. Defined here (in the style package) so that it can be referenced by [Style.CursorShape] and [Computed.CursorShape] without creating an import cycle between the style and cursor packages.
const ( // CursorShapeBlockBlink is a blinking block cursor (default). CursorBlock CursorShape = iota // CursorShapeBlockSteady is a steady (non-blinking) block cursor. CursorBar // CursorShapeUnderlineBlink is a blinking underline cursor. CursorUnderline )
type Dimension ¶
type Dimension struct {
// contains filtered or unexported fields
}
Dimension is a tagged union representing a layout dimension. Use the constructor functions Cells, Percent, Fr and the package variables Auto and Content to create values; do not construct Dimension literals directly.
func Percent ¶
Percent returns a Dimension measured as a percentage of the parent dimension. For example Percent(50) means 50 %.
func (Dimension) CellsValue ¶
CellsValue returns the fixed cell count. Only valid when Kind() == KindCells; returns 0 otherwise.
func (Dimension) FrValue ¶
FrValue returns the fractional value. Only valid when Kind() == KindFr; returns 0 otherwise.
func (Dimension) Kind ¶
func (d Dimension) Kind() DimensionKind
Kind returns which variant is active.
func (Dimension) MarshalJSON ¶
MarshalJSON serializes Dimension as a human-readable string (e.g. "auto", "20px", "100%", "1fr", "content", "max-content").
func (Dimension) PercentValue ¶
PercentValue returns the percentage. Only valid when Kind() == KindPercent; returns 0 otherwise.
func (*Dimension) UnmarshalJSON ¶
UnmarshalJSON parses a Dimension from its string or object JSON representation.
type DimensionKind ¶
type DimensionKind uint8
DimensionKind identifies which variant of Dimension is active.
const ( // KindAuto lets the layout engine determine the dimension. KindAuto DimensionKind = iota // KindCells is a fixed number of terminal cells. KindCells // KindPercent is a percentage of the parent's dimension. KindPercent // KindContent sizes the element to fit its content, capped at the available width. KindContent // KindFr is a fractional unit used in flex/grid contexts. KindFr // KindMaxContent sizes the element to its unconstrained max-content width, // ignoring the available width limit. Used internally by UA shadow subtrees // (e.g. the inner div of <input>) that must be able to overflow their clip // container so that the host's programmatic scroll offset can pan the content. KindMaxContent )
type Display ¶
type Display uint8
Display controls how an element participates in its parent's layout.
const ( // DisplayBlock renders the element as a block-level box. DisplayBlock Display = iota // DisplayFlex renders the element as a flex container. DisplayFlex // DisplayInline renders the element as an inline-level box that // participates in the surrounding inline-formatting context. DisplayInline // DisplayInlineBlock renders the element as an inline-level box that // establishes its own block-formatting context internally. DisplayInlineBlock // DisplayInlineFlex renders the element as an inline-level box that // establishes its own flex-formatting context internally. DisplayInlineFlex // DisplayNone removes the element from the layout entirely. DisplayNone // DisplayListItem renders the element as a list item with a marker. DisplayListItem // DisplayTable renders the element as a block-level table. DisplayTable // DisplayGrid renders the element as a block-level grid container. DisplayGrid // DisplayTableHeaderGroup renders the element as a table header group. DisplayTableHeaderGroup // DisplayTableRowGroup renders the element as a table row group. DisplayTableRowGroup DisplayTableFooterGroup // DisplayTableRow renders the element as a table row. DisplayTableRow // DisplayTableCell renders the element as a table cell. DisplayTableCell )
type EdgeValues ¶
type EdgeValues[T any] struct { Top T `json:"top"` Right T `json:"right"` Bottom T `json:"bottom"` Left T `json:"left"` }
EdgeValues holds independent values for the four sides of a box: top, right, bottom, and left. It is used for padding, margin, and per-side border properties.
func EdgeAll ¶
func EdgeAll[T any](v T) EdgeValues[T]
EdgeAll returns an EdgeValues where all four sides are set to v.
func Edges ¶
func Edges[T any](vals ...T) EdgeValues[T]
Edges is a variadic constructor for [EdgeValues[T]] following CSS shorthand conventions:
- 1 arg – Edges(all) → all four sides equal
- 2 args – Edges(vertical, horizontal) → top/bottom = v, left/right = h
- 4 args – Edges(top, right, bottom, left)
Any other number of arguments returns the zero EdgeValues.
type FlexDirection ¶
type FlexDirection uint8
FlexDirection defines the main axis of a flex container.
const ( // FlexRow lays children out left-to-right (default). FlexRow FlexDirection = iota // FlexColumn lays children out top-to-bottom. FlexColumn // FlexRowReverse lays children out right-to-left. FlexRowReverse // FlexColumnReverse lays children out bottom-to-top. FlexColumnReverse )
type FlexItemValue ¶
FlexItemValue groups the grow/shrink/basis properties for a flex item.
Build via the Flex variadic constructor, not as a struct literal.
func Flex ¶
func Flex(grow int, rest ...any) FlexItemValue
Flex returns a FlexItemValue.
- Flex(g) → {Grow: g, Shrink: 1, Basis: Auto}
- Flex(g, s) → {Grow: g, Shrink: s, Basis: Auto}
- Flex(g, s, basis) → {Grow: g, Shrink: s, Basis: basis}
grow and shrink are integers; basis is an optional Dimension. Any other arity panics.
type GapValue ¶
GapValue holds the inter-child gaps for both layout axes of a flex container. Row is the block-axis gap (between lines); Column is the inline-axis gap (between items on the same line).
Build via the Gap variadic constructor, not as a struct literal, so callers remain decoupled from the field layout.
type GridPlacement ¶
GridPlacement represents a column or row placement in a CSS Grid. It can specify a start line, an end line, or a span.
func GridArea ¶
func GridArea(start, end int) GridPlacement
GridArea creates a GridPlacement spanning from 1-based line start to end.
func GridLine ¶
func GridLine(start int) GridPlacement
GridLine creates a GridPlacement anchored at the 1-based track line start.
type GridTrackSize ¶
type GridTrackSize = Dimension
GridTrackSize is an alias to Dimension, allowing grid definitions to seamlessly use existing dimension types and helpers (e.g. Cells, Auto).
func Repeat ¶
func Repeat(count int, sizes ...GridTrackSize) []GridTrackSize
Repeat generates a slice of GridTrackSize by repeating the provided sizes the specified number of times. It flattens the result into a single slice.
type Justify ¶
type Justify uint8
Justify controls main-axis alignment inside a flex container.
const ( // JustifyStart packs items toward the main-start edge. JustifyStart Justify = iota // JustifyEnd packs items toward the main-end edge. JustifyEnd // JustifyCenter centers items along the main axis. JustifyCenter // JustifyBetween distributes items with space between them. JustifyBetween // JustifyAround distributes items with space around them. JustifyAround // JustifyEvenly distributes items with equal space between and around them. JustifyEvenly )
type ListStyleType ¶
type ListStyleType uint8
ListStyleType defines the appearance of a list item marker.
const ( // ListStyleInherit inherits the marker from the parent. ListStyleInherit ListStyleType = iota // ListStyleNone renders no marker. ListStyleNone // ListStyleDisc renders a solid bullet (•). ListStyleDisc // ListStyleCircle renders a hollow circle (○). ListStyleCircle // ListStyleSquare renders a solid square (■). ListStyleSquare // ListStyleDecimal renders a decimal number (1., 2., 3.). ListStyleDecimal )
type MediaContext ¶
type MediaContext struct {
Viewport geom.Size
ColorScheme ColorScheme
}
MediaContext bundles the host conditions evaluated against a MediaQuery.
type MediaQuery ¶
type MediaQuery struct {
// contains filtered or unexported fields
}
MediaQuery represents a viewport condition to dynamically match styles.
func Query ¶
func Query() MediaQuery
Query returns an empty MediaQuery to start a query building chain.
func (MediaQuery) ColorScheme ¶
func (q MediaQuery) ColorScheme(scheme ColorScheme) MediaQuery
ColorScheme constrains the query to match only the given host ColorScheme.
func (MediaQuery) Matches ¶
func (q MediaQuery) Matches(viewport geom.Size) bool
Matches returns true if the given viewport size satisfies all constraints of the query.
func (MediaQuery) MatchesContext ¶
func (q MediaQuery) MatchesContext(ctx MediaContext) bool
func (MediaQuery) MaxHeight ¶
func (q MediaQuery) MaxHeight(h int) MediaQuery
MaxHeight sets the maximum viewport height constraint.
func (MediaQuery) MaxWidth ¶
func (q MediaQuery) MaxWidth(w int) MediaQuery
MaxWidth sets the maximum viewport width constraint.
func (MediaQuery) MinHeight ¶
func (q MediaQuery) MinHeight(h int) MediaQuery
MinHeight sets the minimum viewport height constraint.
func (MediaQuery) MinWidth ¶
func (q MediaQuery) MinWidth(w int) MediaQuery
MinWidth sets the minimum viewport width constraint.
type MediaRule ¶
type MediaRule struct {
Query MediaQuery
Style Style
}
MediaRule associates a MediaQuery with an overriding Style.
type Optional ¶
type Optional[T any] struct { // contains filtered or unexported fields }
Optional wraps a value of type T to distinguish "unset" from the zero value. Every field of Style is Optional so that callers can compose styles without clobbering fields they did not intend to set.
func (Optional[T]) MarshalJSON ¶
func (Optional[T]) Merge ¶
Merge returns other if it is set, otherwise it returns o. This is the building block used by Style.Merge to combine two styles field-by-field.
func (*Optional[T]) Set ¶
func (o *Optional[T]) Set(v T)
Set assigns v and marks the Optional as set.
func (*Optional[T]) UnmarshalJSON ¶
func (*Optional[T]) Unset ¶
func (o *Optional[T]) Unset()
Unset clears the value and marks the Optional as unset.
type Overflow ¶
type Overflow uint8
Overflow controls how overflowing content is handled on a single axis.
const ( // OverflowVisible allows content to overflow visibly. OverflowVisible Overflow = iota // OverflowHidden hides overflowing content. OverflowHidden // OverflowScroll enables scrolling for overflowing content. OverflowScroll // OverflowClip clips overflowing content without scrolling. OverflowClip // OverflowAuto enables scrolling when content overflows. OverflowAuto )
type OverflowWrap ¶
type OverflowWrap uint8
OverflowWrap controls emergency breaking inside an otherwise-unbreakable run.
const ( // OverflowWrapNormal never breaks inside an unbreakable run. OverflowWrapNormal OverflowWrap = iota // OverflowWrapAnywhere allows emergency breaking at any cluster boundary. OverflowWrapAnywhere // OverflowWrapBreakWord allows emergency breaking without lowering // min-content width. OverflowWrapBreakWord )
type PseudoRule ¶
type PseudoRule struct {
State PseudoState
Style Style
}
PseudoRule associates a PseudoState bitmask with an overriding Style.
type PseudoState ¶
type PseudoState uint8
PseudoState is a bitmask representing interactive/semantic element states used to evaluate conditional pseudo-rules in the style cascade.
const ( // PseudoHover matches when the pointer is hovering over the element. PseudoHover PseudoState = 1 << iota // PseudoFocus matches when the element holds keyboard focus. PseudoFocus // PseudoActive matches while the element is being activated (e.g. primary mouse down). PseudoActive // PseudoDisabled matches when a disableable element is disabled. PseudoDisabled )
const ( // PseudoNone represents an element with no active pseudo-states. PseudoNone PseudoState = 0 )
type Scrollbar ¶
type Scrollbar struct {
// X enables the horizontal scrollbar.
X Optional[bool]
// Y enables the vertical scrollbar.
Y Optional[bool]
// TrackGlyph is the rune used for the scrollbar track.
TrackGlyph Optional[rune]
// TrackColor is the color of the scrollbar track.
TrackColor Optional[color.Color]
// ThumbGlyph is the rune used for the scrollbar thumb.
ThumbGlyph Optional[rune]
// ThumbColor is the color of the scrollbar thumb.
ThumbColor Optional[color.Color]
}
Scrollbar defines the visual appearance and visibility of scrollbars. Screen real estate is precious in a TUI, so scrollbars are opt-in.
type Sheet ¶
type Sheet struct {
// contains filtered or unexported fields
}
Sheet is an immutable, named collection of Style values. It mirrors the React Native StyleSheet.create pattern: styles are declared once, validated eagerly, and looked up by name in O(1).
Construct via NewSheet; the returned Sheet is immutable — its entries cannot be changed after creation. Returned styles are value copies so callers cannot mutate the registry.
Example:
sheet, err := style.NewSheet(map[string]style.Style{
"button": style.S().Display(style.DisplayFlex),
"buttonHot": style.S().Foreground(hotColor),
})
box.Style(sheet.Get("button"))
func NewSheet ¶
NewSheet creates a Sheet from the given map of named styles. It validates each entry eagerly and returns an error if any value is malformed. The provided map is copied; later mutations to the caller's map do not affect the sheet.
Validation checks performed at creation time:
- Dimension values that are set must have a valid Kind (non-zero tag).
- EdgeValues with negative cell widths are rejected.
- No entry may have an empty key.
func (*Sheet) Get ¶
Get returns the Style registered under name. If no entry exists for name, Get returns a zero Style (all fields unset). The returned value is a copy; mutations do not affect the sheet.
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style is a sparse set of visual and layout properties for a kitex element. Every field is Optional so that callers can compose styles without overwriting fields they did not intend to change.
Construct via S and fluent builders:
s := style.S().
Display(style.DisplayFlex).
FlexDirection(style.FlexColumn).
Gap(1)
Combine two styles with Style.Merge or Style.When.
func S ¶
func S() Style
S returns a new empty Style.
Example ¶
package main
import (
"fmt"
"image/color"
"github.com/masterkeysrd/kite/style"
)
func main() {
panel := style.S().
Display(style.DisplayFlex).
Padding(1, 2).
Foreground(color.White).
Border(style.SingleBorder())
box := panel.Apply(style.Computed{})
fmt.Println("horizontal padding:", box.Padding.Left, box.Padding.Right)
}
Output: horizontal padding: 2 2
func (Style) Active ¶
Active registers a style override applied when PseudoActive is active.
func (Style) AlignContent ¶
AlignContent sets the AlignContent property.
func (Style) AlignContentOpt ¶
AlignContentOpt returns the optional value of AlignContent.
func (Style) AlignItems ¶
AlignItems sets the AlignItems property.
func (Style) AlignItemsOpt ¶
AlignItemsOpt returns the optional value of AlignItems.
func (Style) AlignSelfOpt ¶
AlignSelfOpt returns the optional value of AlignSelf.
func (Style) Apply ¶
Apply returns a copy of base with every set field in s overlaid on top. It is the bridge between the sparse Style author model and the fully-resolved Computed type: the resolver calls it once per dirty node after applying inheritance, so all the per-property Optional checks live here rather than in the resolver.
func (Style) Background ¶
Background sets the Background property.
func (Style) BackgroundOpt ¶
BackgroundOpt returns the optional value of Background.
func (Style) Border ¶
Border sets the border properties. It accepts variadic arguments of types:
- bool: toggles all edges on/off
- BorderStyle: sets the style for all edges
- color.Color: sets the color for all edges
- BorderGlyphs: sets the glyphs for the entire border and switches to BorderCustom
- Border: replaces the entire border definition
func (Style) BorderBottom ¶
BorderBottom toggles the visibility of the bottom border edge and optionally sets its style and color. It accepts optional arguments of types BorderStyle, BorderGlyphs, or color.Color.
func (Style) BorderHorizontal ¶
BorderHorizontal toggles the visibility of the left and right border edges and optionally sets their style and color. It accepts optional arguments of types BorderStyle, BorderGlyphs, or color.Color.
func (Style) BorderLeft ¶
BorderLeft toggles the visibility of the left border edge and optionally sets its style and color. It accepts optional arguments of types BorderStyle, BorderGlyphs, or color.Color.
func (Style) BorderRight ¶
BorderRight toggles the visibility of the right border edge and optionally sets its style and color. It accepts optional arguments of types BorderStyle, BorderGlyphs, or color.Color.
func (Style) BorderTop ¶
BorderTop toggles the visibility of the top border edge and optionally sets its style and color. It accepts optional arguments of types BorderStyle, BorderGlyphs, or color.Color:
- BorderTop(true) -> enables top edge with BorderSingle
- BorderTop(true, BorderDouble) -> enables top edge with BorderDouble
- BorderTop(true, BorderDouble, c) -> enables top edge with BorderDouble and color c
func (Style) BorderVertical ¶
BorderVertical toggles the visibility of the top and bottom border edges and optionally sets their style and color. It accepts optional arguments of types BorderStyle, BorderGlyphs, or color.Color.
func (Style) Disabled ¶
Disabled registers a style override applied when PseudoDisabled is active.
func (Style) DisplayOpt ¶
DisplayOpt returns the optional value of Display.
func (Style) EvaluateMedia ¶
EvaluateMedia matches all registered media rules against the given viewport size, merges the matching rule styles, and returns the resolved style.
func (Style) EvaluateMediaContext ¶
func (s Style) EvaluateMediaContext(ctx MediaContext) Style
func (Style) EvaluatePseudo ¶
func (s Style) EvaluatePseudo(active PseudoState) Style
EvaluatePseudo matches all registered pseudo-rules against active, merges matching rule styles in declaration order, and returns the resolved style with pseudo-rules cleared.
func (Style) Flex ¶
Flex sets the grow, shrink, and basis for a flex item. It expects a mandatory grow (int), followed by optional shrink (int) and basis (Dimension):
- Flex(g) -> grow=g, shrink=1, basis=Auto
- Flex(g, s) -> grow=g, shrink=s, basis=Auto
- Flex(g, s, basis) -> grow=g, shrink=s, basis=basis
func (Style) FlexDirection ¶
func (s Style) FlexDirection(v FlexDirection) Style
FlexDirection sets the FlexDirection property.
func (Style) FlexDirectionOpt ¶
func (s Style) FlexDirectionOpt() Optional[FlexDirection]
FlexDirectionOpt returns the optional value of FlexDirection.
func (Style) FlexOpt ¶
func (s Style) FlexOpt() Optional[FlexItemValue]
FlexOpt returns the optional value of Flex.
func (Style) FlexWrapOpt ¶
FlexWrapOpt returns the optional value of FlexWrap.
func (Style) Focus ¶
Focus registers a style override applied when PseudoFocus is active.
func (Style) Foreground ¶
Foreground sets the Foreground property.
func (Style) ForegroundOpt ¶
ForegroundOpt returns the optional value of Foreground.
func (Style) Gap ¶
Gap sets the row and column gaps between flex/grid children. It expects 1 or 2 int values:
- Gap(n) -> sets both row and column gap to n
- Gap(r, c) -> sets row gap to r and column gap to c
func (Style) GridColumn ¶
func (s Style) GridColumn(v GridPlacement) Style
GridColumn sets the GridColumn property.
func (Style) GridColumnGap ¶
GridColumnGap sets the GridColumnGap property.
func (Style) GridColumnGapOpt ¶
GridColumnGapOpt returns the optional value of GridColumnGap.
func (Style) GridColumnOpt ¶
func (s Style) GridColumnOpt() Optional[GridPlacement]
GridColumnOpt returns the optional value of GridColumn.
func (Style) GridRow ¶
func (s Style) GridRow(v GridPlacement) Style
GridRow sets the GridRow property.
func (Style) GridRowGap ¶
GridRowGap sets the GridRowGap property.
func (Style) GridRowGapOpt ¶
GridRowGapOpt returns the optional value of GridRowGap.
func (Style) GridRowOpt ¶
func (s Style) GridRowOpt() Optional[GridPlacement]
GridRowOpt returns the optional value of GridRow.
func (Style) GridTemplateColumns ¶
func (s Style) GridTemplateColumns(v ...GridTrackSize) Style
GridTemplateColumns sets the column track sizing functions. It expects variadic GridTrackSize values.
func (Style) GridTemplateColumnsOpt ¶
func (s Style) GridTemplateColumnsOpt() Optional[[]GridTrackSize]
GridTemplateColumnsOpt returns the optional value of GridTemplateColumns.
func (Style) GridTemplateRows ¶
func (s Style) GridTemplateRows(v ...GridTrackSize) Style
GridTemplateRows sets the row track sizing functions. It expects variadic GridTrackSize values.
func (Style) GridTemplateRowsOpt ¶
func (s Style) GridTemplateRowsOpt() Optional[[]GridTrackSize]
GridTemplateRowsOpt returns the optional value of GridTemplateRows.
func (Style) HasMediaRules ¶
HasMediaRules returns true if the style contains conditional media rules.
func (Style) HasPseudoRules ¶
HasPseudoRules returns true if the style contains conditional pseudo-state rules.
func (Style) Hover ¶
Hover registers a style override applied when PseudoHover is active.
Example ¶
package main
import (
"fmt"
"github.com/masterkeysrd/kite/style"
)
func main() {
button := style.S().
Hover(style.S().Underline(true)).
Focus(style.S().Bold(true)).
Active(style.S().Reverse(true))
hovered := button.EvaluatePseudo(style.PseudoHover).Apply(style.Computed{})
fmt.Println("underlined:", hovered.Underline)
}
Output: underlined: true
func (Style) JustifyContent ¶
JustifyContent sets the JustifyContent property.
func (Style) JustifyContentOpt ¶
JustifyContentOpt returns the optional value of JustifyContent.
func (Style) ListStyleType ¶
func (s Style) ListStyleType(v ListStyleType) Style
ListStyleType sets the ListStyleType property.
func (Style) ListStyleTypeOpt ¶
func (s Style) ListStyleTypeOpt() Optional[ListStyleType]
ListStyleTypeOpt returns the optional value of ListStyleType.
func (Style) Margin ¶
Margin sets the outer spacing between the element's border and its siblings. It expects 1, 2, or 4 int values (CSS shorthand):
- Margin(all) -> all four sides equal
- Margin(vert, horiz) -> top/bottom = vert, left/right = horiz
- Margin(top, right, bot, left)
func (Style) MarginBottom ¶
MarginBottom sets the bottom margin.
func (Style) MarginHorizontal ¶
MarginHorizontal sets the left and right margins.
func (Style) MarginOpt ¶
func (s Style) MarginOpt() Optional[EdgeValues[int]]
MarginOpt returns the optional value of Margin.
func (Style) MarginRight ¶
MarginRight sets the right margin.
func (Style) MarginVertical ¶
MarginVertical sets the top and bottom margins.
func (Style) MarshalJSON ¶
MarshalJSON serializes only the explicitly set properties of Style.
func (Style) MaxHeightOpt ¶
MaxHeightOpt returns the optional value of MaxHeight.
func (Style) MaxWidthOpt ¶
MaxWidthOpt returns the optional value of MaxWidth.
func (Style) Media ¶
func (s Style) Media(q MediaQuery, ruleStyle Style) Style
Media registers a conditional media rule on the style. If the viewport matches the query, the ruleStyle will be merged on top of this style.
Example ¶
package main
import (
"fmt"
"github.com/masterkeysrd/kite/geom"
"github.com/masterkeysrd/kite/style"
)
func main() {
panel := style.S().
Padding(1).
Media(style.Query().MinWidth(80), style.S().Padding(3))
for _, width := range []int{40, 100} {
viewport := geom.Size{Width: width, Height: 24}
box := panel.EvaluateMedia(viewport).Apply(style.Computed{})
fmt.Printf("%d columns: padding %d\n", width, box.Padding.Left)
}
}
Output: 40 columns: padding 1 100 columns: padding 3
func (Style) Merge ¶
Merge returns a new Style where each field is taken from override if it is set, otherwise from s. Neither s nor override is mutated.
This implements field-level composition: callers can build up a final style from a base theme plus successive override layers:
final := theme.Merge(widgetDefault).Merge(userProvided)
func (Style) MinHeightOpt ¶
MinHeightOpt returns the optional value of MinHeight.
func (Style) MinWidthOpt ¶
MinWidthOpt returns the optional value of MinWidth.
func (Style) Overflow ¶
Overflow sets both OverflowX and OverflowY to v and returns the modified style.
func (Style) OverflowWrap ¶
func (s Style) OverflowWrap(v OverflowWrap) Style
OverflowWrap sets the OverflowWrap property.
func (Style) OverflowWrapOpt ¶
func (s Style) OverflowWrapOpt() Optional[OverflowWrap]
OverflowWrapOpt returns the optional value of OverflowWrap.
func (Style) OverflowXOpt ¶
OverflowXOpt returns the optional value of OverflowX.
func (Style) OverflowYOpt ¶
OverflowYOpt returns the optional value of OverflowY.
func (Style) Padding ¶
Padding sets the inner spacing between the element's content and its border. It expects 1, 2, or 4 int values (CSS shorthand):
- Padding(all) -> all four sides equal
- Padding(vert, horiz) -> top/bottom = vert, left/right = horiz
- Padding(top, right, bot, left)
func (Style) PaddingBottom ¶
PaddingBottom sets the bottom padding.
func (Style) PaddingHorizontal ¶
PaddingHorizontal sets the left and right paddings.
func (Style) PaddingLeft ¶
PaddingLeft sets the left padding.
func (Style) PaddingOpt ¶
func (s Style) PaddingOpt() Optional[EdgeValues[int]]
PaddingOpt returns the optional value of Padding.
func (Style) PaddingRight ¶
PaddingRight sets the right padding.
func (Style) PaddingVertical ¶
PaddingVertical sets the top and bottom paddings.
func (Style) Pseudo ¶
func (s Style) Pseudo(state PseudoState, ruleStyle Style) Style
Pseudo registers a conditional pseudo-state rule on the style. If all flags in state are active on the element, ruleStyle is merged on top of this style.
func (Style) ReverseOpt ¶
ReverseOpt returns the optional value of Reverse.
func (Style) ScrollbarOpt ¶
ScrollbarOpt returns the optional value of Scrollbar.
func (Style) ScrollbarThumb ¶
ScrollbarThumb sets the glyph and color for the scrollbar thumb.
func (Style) ScrollbarTrack ¶
ScrollbarTrack sets the glyph and color for the scrollbar track.
func (Style) ScrollbarX ¶
ScrollbarX enables or disables the horizontal scrollbar.
func (Style) ScrollbarY ¶
ScrollbarY enables or disables the vertical scrollbar.
func (Style) SelectionBackground ¶
SelectionBackground sets the SelectionBackground property.
func (Style) SelectionBackgroundOpt ¶
SelectionBackgroundOpt returns the optional value of SelectionBackground.
func (Style) SelectionForeground ¶
SelectionForeground sets the SelectionForeground property.
func (Style) SelectionForegroundOpt ¶
SelectionForegroundOpt returns the optional value of SelectionForeground.
func (Style) Strikethrough ¶
Strikethrough sets the Strikethrough property.
func (Style) StrikethroughOpt ¶
StrikethroughOpt returns the optional value of Strikethrough.
func (Style) TextAlignOpt ¶
TextAlignOpt returns the optional value of TextAlign.
func (Style) TextOverflow ¶
func (s Style) TextOverflow(v TextOverflow) Style
TextOverflow sets the TextOverflow property.
func (Style) TextOverflowOpt ¶
func (s Style) TextOverflowOpt() Optional[TextOverflow]
TextOverflowOpt returns the optional value of TextOverflow.
func (Style) TextWrapOpt ¶
TextWrapOpt returns the optional value of TextWrap.
func (Style) UnderlineOpt ¶
UnderlineOpt returns the optional value of Underline.
func (Style) WhiteSpace ¶
func (s Style) WhiteSpace(v WhiteSpace) Style
WhiteSpace sets the WhiteSpace property.
func (Style) WhiteSpaceOpt ¶
func (s Style) WhiteSpaceOpt() Optional[WhiteSpace]
WhiteSpaceOpt returns the optional value of WhiteSpace.
func (Style) WithoutRules ¶
WithoutRules returns a copy of s with pseudo-state and media rules removed.
func (Style) WordBreakOpt ¶
WordBreakOpt returns the optional value of WordBreak.
type TextOverflow ¶
type TextOverflow uint8
TextOverflow controls how non-wrapping text is rendered when it overflows.
const ( // TextOverflowClip clips overflowing text at the element boundary. TextOverflowClip TextOverflow = iota // TextOverflowEllipsis replaces overflowing text with "…". TextOverflowEllipsis )
type TextWrap ¶
type TextWrap uint8
TextWrap controls how text is wrapped when it exceeds the element's width.
type WhiteSpace ¶
type WhiteSpace uint8
WhiteSpace controls whether whitespace is collapsed or preserved and whether soft wrapping is allowed.
const ( // WhiteSpaceNormal collapses whitespace and allows wrapping. WhiteSpaceNormal WhiteSpace = iota // WhiteSpacePre preserves whitespace and only breaks at mandatory breaks. WhiteSpacePre // WhiteSpacePreWrap preserves whitespace and allows wrapping. WhiteSpacePreWrap // WhiteSpaceNoWrap collapses whitespace and disables soft wrapping. WhiteSpaceNoWrap )