style

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Package style

The style package manages the sparse Style definitions and the fully-resolved Computed styles for the Kite framework. It implements a four-layer cascade resolution system inspired by CSS.

🏛 Architecture

Style vs Computed
  • Style: A sparse struct where every field is Optional[T]. This is the "authoring" model used by developers to set properties.
  • Computed: A fully-resolved struct with concrete values for every property. This is what the layout and paint engines read.
The Four-Layer Cascade (ADR-010)
  1. Inherited Values: Properties like Foreground and Bold flow from parent to child.
  2. Element Defaults: Tag-specific defaults (e.g., Display: Inline for <span>).
  3. Author Styles: Properties set explicitly via Style().
  4. UA-Intrinsic Styles: Mandatory properties for compound elements. Examples:
    • <textarea>: OverflowY: Auto, OverflowX: Clip.
    • <button>: Display: Flex, AlignItems: Center, JustifyContent: Center.
Simplified Fluent API

The Style type provides variadic methods for common layout properties to reduce boilerplate:

  • Gap(values ...int): Sets row and column gaps. Expects 1 or 2 int values.
    • Gap(1) sets both row and column gaps to 1.
    • Gap(1, 2) sets row gap to 1 and column gap to 2.
  • Padding(values ...int) & Margin(values ...int): Uses CSS-like shorthand. Expects 1, 2, or 4 int values.
    • Padding(1) sets all sides to 1.
    • Padding(1, 2) sets top/bottom to 1, left/right to 2.
    • Padding(1, 2, 3, 4) sets top, right, bottom, left.
  • Flex(grow int, rest ...any): Configures flex item properties. Expects a mandatory grow (int), and optional shrink (int) and basis (style.Dimension).
    • Flex(1) sets grow to 1 (shrink=1, basis=auto).
    • Flex(1, 0) sets grow to 1, shrink to 0.
    • Flex(1, 1, style.Cells(10)) sets grow, shrink, and basis.
  • GridTemplateColumns(v ...GridTrackSize) & GridTemplateRows(v ...GridTrackSize): Variadic track definitions. Expects variadic style.Dimension values.
    • GridTemplateColumns(style.Cells(10), style.Fr(1))
  • Border(args ...any): Sets border properties globally. Accepts bool, style.BorderStyle, color.Color, style.BorderGlyphs, or style.Border.
    • Border(true) enables all edges with BorderSingle.
    • Border(true, style.BorderDouble) sets style for all edges.
    • Border(true, color.Red) sets color for all edges.
    • Border(true, style.BorderGlyphs{H: "#"}) sets custom glyphs and switches to BorderCustom.
  • BorderTop, BorderRight, BorderBottom, BorderLeft, BorderHorizontal, BorderVertical: Variadic side-specific settings. Accepts optional style.BorderStyle, color.Color, or style.BorderGlyphs.
    • BorderTop(true, style.BorderDouble, color.Red)
    • BorderLeft(true, style.BorderGlyphs{V: "!"}) // Switches to BorderCustom automatically.

📜 Scrollbars (Task 036)

Scrollbars in a TUI consume precious cell space, so they are explicit opt-in decisions configured via the Scrollbar property.

Fluent API

The Style and Element types provide fluent helpers for scrollbar configuration:

  • ScrollbarX(bool): Enables or disables the horizontal scrollbar.
  • ScrollbarY(bool): Enables or disables the vertical scrollbar.
  • ScrollbarThumb(glyph rune, c color.Color): Customizes the thumb appearance.
  • ScrollbarTrack(glyph rune, c color.Color): Customizes the track appearance.
Defaults

When scrollbars are enabled but glyphs are omitted, the resolver applies sensible TUI defaults:

  • Vertical: Track │, Thumb ┃
  • Horizontal: Track ─, Thumb ━
Behavior
  • Reservation: If Overflow is Auto or Scroll AND scrollbars are enabled, the layout engine reserves 1 cell of space along the appropriate edge.
  • Auto-hide: If Overflow is Auto, space is only reserved if the content actually overflows the viewport. If ScrollbarY(true) is NOT set, OverflowAuto still allows scrolling but hides the visual indicator.
  • Rendering: Scrollbars are painted over the element's content, representing the current Scroll() offset of the logical DOM element.

📱 Media Queries & Responsive Layouts

Kite features a declarative, high-performance Media Queries system that resolves styles dynamically based on the terminal's viewport size.

Media Rules API

You can register conditional styles on any base Style builder using the Media() method:

var CardStyle = style.S().
    Width(style.Cells(30)).
    Background(color.RGBA{B: 255, A: 255}). // Blue background on small screen
    // Merge overrides when the viewport width is >= 80 cells
    Media(style.Query().MinWidth(80), style.S().
        Width(style.Cells(60)).
        Background(color.RGBA{G: 255, A: 255}), // Green background on wide screen
    )

Predefined query constraints:

  • MinWidth(w int): Match when viewport width is $\ge w$ cells.
  • MaxWidth(w int): Match when viewport width is $\le w$ cells.
  • MinHeight(h int): Match when viewport height is $\ge h$ cells.
  • MaxHeight(h int): Match when viewport height is $\le h$ cells.
Performance & Cache Invalidation
  • 0% Overhead Static Matching: Media queries avoid arbitrary functions or heap allocations during normal render loops.
  • Selective Cache Invalidation: The style resolver caches resolved styles. When the viewport is resized, the engine walks the render tree and invalidates only the subtrees containing media rules. All other nodes remain cached, resulting in zero overhead.

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

Examples

Constants

View Source
const (
	DefaultScrollbarTrackVertical   = '│'
	DefaultScrollbarThumbVertical   = '┃'
	DefaultScrollbarTrackHorizontal = '─'
	DefaultScrollbarThumbHorizontal = '━'
)

Default glyphs for scrollbars.

Variables

View Source
var Auto = Dimension{/* contains filtered or unexported fields */}

Auto is a Dimension that lets the layout engine choose the size.

View Source
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.

View Source
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.

View Source
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.

View Source
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

func Hex(hex string) color.Color

Hex parses a CSS-style hex color string via ParseHex. On invalid input, it returns opaque black (color.RGBA{A: 255}) without panicking.

func HexInt

func HexInt(v uint32) color.Color

HexInt converts a 24-bit RGB integer (0xRRGGBB) into an opaque color.Color.

func IsTerminalDefault

func IsTerminalDefault(c color.Color) bool

IsTerminalDefault reports whether c is the TerminalDefault sentinel.

func ParseHex

func ParseHex(hex string) (color.Color, error)

ParseHex parses a CSS-style hex color string in #RGB, RGB, #RRGGBB, RRGGBB, #RRGGBBAA, or RRGGBBAA format (case-insensitive).

func RGB

func RGB(r, g, b uint8) color.Color

RGB returns an opaque color with the given 8-bit red, green, and blue channels.

func RGBA

func RGBA(r, g, b, a uint8) color.Color

RGBA returns a color with the given 8-bit red, green, blue, and alpha channels.

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 EmptyBorder

func EmptyBorder() Border

EmptyBorder returns a border with no edges visible.

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) Bottom

func (b Border) Bottom(visible bool) Border

Bottom toggles the visibility of the bottom border edge.

func (Border) Color

func (b Border) Color(c color.Color) Border

Color sets the color for all border edges.

func (Border) CornerOverride

func (b Border) CornerOverride(tl, tr, bl, br string) Border

CornerOverride sets manual overrides for the four corners.

func (Border) Left

func (b Border) Left(visible bool) Border

Left toggles the visibility of the left border edge.

func (Border) Right

func (b Border) Right(visible bool) Border

Right toggles the visibility of the right border edge.

func (Border) Some

func (b Border) Some() Optional[Border]

Some wraps the border in an Optional.

func (Border) Style

func (b Border) Style(s BorderStyle) Border

Style sets the border style for all edges.

func (Border) Top

func (b Border) Top(visible bool) Border

Top toggles the visibility of the top border edge.

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

func (c *Computed) AffectsLayout(other *Computed) bool

AffectsLayout returns true if the change between c and other requires a re-layout.

func (*Computed) AffectsPaint

func (c *Computed) AffectsPaint(other *Computed) bool

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]
}

func (Cursor) Merge

func (s Cursor) Merge(override Cursor) Cursor

Merge returns a new Cursor where each set field in override overlays the corresponding field in s.

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 Cells

func Cells(n int) Dimension

Cells returns a Dimension measured in a fixed number of terminal cells.

func Fr

func Fr(f float32) Dimension

Fr returns a Dimension measured in fractional units (for flex/grid layouts).

func Percent

func Percent(pct float32) Dimension

Percent returns a Dimension measured as a percentage of the parent dimension. For example Percent(50) means 50 %.

func (Dimension) CellsValue

func (d Dimension) CellsValue() int

CellsValue returns the fixed cell count. Only valid when Kind() == KindCells; returns 0 otherwise.

func (Dimension) FrValue

func (d Dimension) FrValue() float32

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

func (d Dimension) MarshalJSON() ([]byte, error)

MarshalJSON serializes Dimension as a human-readable string (e.g. "auto", "20px", "100%", "1fr", "content", "max-content").

func (Dimension) PercentValue

func (d Dimension) PercentValue() float32

PercentValue returns the percentage. Only valid when Kind() == KindPercent; returns 0 otherwise.

func (Dimension) String

func (d Dimension) String() string

String returns a human-readable representation of the dimension.

func (*Dimension) UnmarshalJSON

func (d *Dimension) UnmarshalJSON(data []byte) error

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 renders the element as a table footer group.
	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

type FlexItemValue struct {
	Grow   int
	Shrink int
	Basis  Dimension
}

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 FlexWrap

type FlexWrap uint8

FlexWrap controls whether flex items wrap onto multiple lines.

const (
	// FlexNoWrap keeps all items on one line (default).
	FlexNoWrap FlexWrap = iota
	// FlexWrapOn wraps items onto new lines when the line overflows.
	FlexWrapOn
)

type GapValue

type GapValue struct {
	Row    int
	Column int
}

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.

func Gap

func Gap(values ...int) GapValue

Gap returns a GapValue.

  • Gap(n) → {Row: n, Column: n}
  • Gap(r, c) → {Row: r, Column: c}

Any other arity panics.

type GridPlacement

type GridPlacement struct {
	Span  int
	Start int
	End   int
}

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.

func Span

func Span(n int) GridPlacement

Span creates a GridPlacement that spans n tracks.

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 None

func None[T any]() Optional[T]

None returns an unset Optional.

func Some

func Some[T any](v T) Optional[T]

Some returns an Optional with v set.

func (Optional[T]) Get

func (o Optional[T]) Get() (T, bool)

Get returns the stored value and a boolean indicating if it is set.

func (Optional[T]) IsSet

func (o Optional[T]) IsSet() bool

IsSet reports whether a value has been explicitly set.

func (Optional[T]) MarshalJSON

func (o Optional[T]) MarshalJSON() ([]byte, error)

func (Optional[T]) Merge

func (o Optional[T]) Merge(other Optional[T]) Optional[T]

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 (o *Optional[T]) UnmarshalJSON(data []byte) error

func (*Optional[T]) Unset

func (o *Optional[T]) Unset()

Unset clears the value and marks the Optional as unset.

func (Optional[T]) UnwrapOr

func (o Optional[T]) UnwrapOr(fallback T) T

UnwrapOr returns the stored value if it is set, otherwise it returns fallback.

func (Optional[T]) Value

func (o Optional[T]) Value() T

Value returns the stored value. If the Optional is unset the zero value of T is returned.

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.

func (Scrollbar) Merge

func (s Scrollbar) Merge(override Scrollbar) Scrollbar

Merge returns a new Scrollbar where each set field in override overlays the corresponding field in s.

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

func NewSheet(entries map[string]Style) (*Sheet, error)

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

func (s *Sheet) Get(name string) Style

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.

func (*Sheet) Has

func (s *Sheet) Has(name string) bool

Has reports whether name is registered in the sheet.

func (*Sheet) Len

func (s *Sheet) Len() int

Len returns the number of entries in 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

func (s Style) Active(ruleStyle Style) Style

Active registers a style override applied when PseudoActive is active.

func (Style) AlignContent

func (s Style) AlignContent(v Align) Style

AlignContent sets the AlignContent property.

func (Style) AlignContentOpt

func (s Style) AlignContentOpt() Optional[Align]

AlignContentOpt returns the optional value of AlignContent.

func (Style) AlignItems

func (s Style) AlignItems(v Align) Style

AlignItems sets the AlignItems property.

func (Style) AlignItemsOpt

func (s Style) AlignItemsOpt() Optional[Align]

AlignItemsOpt returns the optional value of AlignItems.

func (Style) AlignSelf

func (s Style) AlignSelf(v Align) Style

AlignSelf sets the AlignSelf property.

func (Style) AlignSelfOpt

func (s Style) AlignSelfOpt() Optional[Align]

AlignSelfOpt returns the optional value of AlignSelf.

func (Style) Apply

func (s Style) Apply(base Computed) Computed

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

func (s Style) Background(v color.Color) Style

Background sets the Background property.

func (Style) BackgroundOpt

func (s Style) BackgroundOpt() Optional[color.Color]

BackgroundOpt returns the optional value of Background.

func (Style) Bold

func (s Style) Bold(v bool) Style

Bold sets the Bold property.

func (Style) BoldOpt

func (s Style) BoldOpt() Optional[bool]

BoldOpt returns the optional value of Bold.

func (Style) Border

func (s Style) Border(args ...any) Style

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

func (s Style) BorderBottom(visible bool, args ...any) Style

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

func (s Style) BorderHorizontal(visible bool, args ...any) Style

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

func (s Style) BorderLeft(visible bool, args ...any) Style

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) BorderOpt

func (s Style) BorderOpt() Optional[Border]

BorderOpt returns the optional value of Border.

func (Style) BorderRight

func (s Style) BorderRight(visible bool, args ...any) Style

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

func (s Style) BorderTop(visible bool, args ...any) Style

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

func (s Style) BorderVertical(visible bool, args ...any) Style

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) Cursor

func (s Style) Cursor(v Cursor) Style

Cursor sets the Cursor property.

func (Style) CursorOpt

func (s Style) CursorOpt() Optional[Cursor]

CursorOpt returns the optional value of Cursor.

func (Style) Disabled

func (s Style) Disabled(ruleStyle Style) Style

Disabled registers a style override applied when PseudoDisabled is active.

func (Style) Display

func (s Style) Display(v Display) Style

Display sets the Display property.

func (Style) DisplayOpt

func (s Style) DisplayOpt() Optional[Display]

DisplayOpt returns the optional value of Display.

func (Style) Equal

func (s Style) Equal(other Style) bool

Equal reports whether s and other are equal.

func (Style) EvaluateMedia

func (s Style) EvaluateMedia(viewport geom.Size) Style

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

func (s Style) Flex(grow int, rest ...any) Style

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) FlexWrap

func (s Style) FlexWrap(v FlexWrap) Style

FlexWrap sets the FlexWrap property.

func (Style) FlexWrapOpt

func (s Style) FlexWrapOpt() Optional[FlexWrap]

FlexWrapOpt returns the optional value of FlexWrap.

func (Style) Focus

func (s Style) Focus(ruleStyle Style) Style

Focus registers a style override applied when PseudoFocus is active.

func (Style) Foreground

func (s Style) Foreground(v color.Color) Style

Foreground sets the Foreground property.

func (Style) ForegroundOpt

func (s Style) ForegroundOpt() Optional[color.Color]

ForegroundOpt returns the optional value of Foreground.

func (Style) Gap

func (s Style) Gap(values ...int) Style

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) GapOpt

func (s Style) GapOpt() Optional[GapValue]

GapOpt returns the optional value of Gap.

func (Style) GridColumn

func (s Style) GridColumn(v GridPlacement) Style

GridColumn sets the GridColumn property.

func (Style) GridColumnGap

func (s Style) GridColumnGap(v int) Style

GridColumnGap sets the GridColumnGap property.

func (Style) GridColumnGapOpt

func (s Style) GridColumnGapOpt() Optional[int]

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

func (s Style) GridRowGap(v int) Style

GridRowGap sets the GridRowGap property.

func (Style) GridRowGapOpt

func (s Style) GridRowGapOpt() Optional[int]

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

func (s Style) HasMediaRules() bool

HasMediaRules returns true if the style contains conditional media rules.

func (Style) HasPseudoRules

func (s Style) HasPseudoRules() bool

HasPseudoRules returns true if the style contains conditional pseudo-state rules.

func (Style) Height

func (s Style) Height(v Dimension) Style

Height sets the Height property.

func (Style) HeightOpt

func (s Style) HeightOpt() Optional[Dimension]

HeightOpt returns the optional value of Height.

func (Style) Hover

func (s Style) Hover(ruleStyle Style) Style

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) Italic

func (s Style) Italic(v bool) Style

Italic sets the Italic property.

func (Style) ItalicOpt

func (s Style) ItalicOpt() Optional[bool]

ItalicOpt returns the optional value of Italic.

func (Style) JustifyContent

func (s Style) JustifyContent(v Justify) Style

JustifyContent sets the JustifyContent property.

func (Style) JustifyContentOpt

func (s Style) JustifyContentOpt() Optional[Justify]

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

func (s Style) Margin(values ...int) Style

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

func (s Style) MarginBottom(v int) Style

MarginBottom sets the bottom margin.

func (Style) MarginHorizontal

func (s Style) MarginHorizontal(v int) Style

MarginHorizontal sets the left and right margins.

func (Style) MarginLeft

func (s Style) MarginLeft(v int) Style

MarginLeft sets the left margin.

func (Style) MarginOpt

func (s Style) MarginOpt() Optional[EdgeValues[int]]

MarginOpt returns the optional value of Margin.

func (Style) MarginRight

func (s Style) MarginRight(v int) Style

MarginRight sets the right margin.

func (Style) MarginTop

func (s Style) MarginTop(v int) Style

MarginTop sets the top margin.

func (Style) MarginVertical

func (s Style) MarginVertical(v int) Style

MarginVertical sets the top and bottom margins.

func (Style) MarshalJSON

func (s Style) MarshalJSON() ([]byte, error)

MarshalJSON serializes only the explicitly set properties of Style.

func (Style) MaxHeight

func (s Style) MaxHeight(v Dimension) Style

MaxHeight sets the MaxHeight property.

func (Style) MaxHeightOpt

func (s Style) MaxHeightOpt() Optional[Dimension]

MaxHeightOpt returns the optional value of MaxHeight.

func (Style) MaxWidth

func (s Style) MaxWidth(v Dimension) Style

MaxWidth sets the MaxWidth property.

func (Style) MaxWidthOpt

func (s Style) MaxWidthOpt() Optional[Dimension]

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

func (s Style) Merge(override Style) Style

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) MinHeight

func (s Style) MinHeight(v Dimension) Style

MinHeight sets the MinHeight property.

func (Style) MinHeightOpt

func (s Style) MinHeightOpt() Optional[Dimension]

MinHeightOpt returns the optional value of MinHeight.

func (Style) MinWidth

func (s Style) MinWidth(v Dimension) Style

MinWidth sets the MinWidth property.

func (Style) MinWidthOpt

func (s Style) MinWidthOpt() Optional[Dimension]

MinWidthOpt returns the optional value of MinWidth.

func (Style) Order

func (s Style) Order(v int) Style

Order sets the Order property.

func (Style) OrderOpt

func (s Style) OrderOpt() Optional[int]

OrderOpt returns the optional value of Order.

func (Style) Overflow

func (s Style) Overflow(v Overflow) Style

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) OverflowX

func (s Style) OverflowX(v Overflow) Style

OverflowX sets the OverflowX property.

func (Style) OverflowXOpt

func (s Style) OverflowXOpt() Optional[Overflow]

OverflowXOpt returns the optional value of OverflowX.

func (Style) OverflowY

func (s Style) OverflowY(v Overflow) Style

OverflowY sets the OverflowY property.

func (Style) OverflowYOpt

func (s Style) OverflowYOpt() Optional[Overflow]

OverflowYOpt returns the optional value of OverflowY.

func (Style) Padding

func (s Style) Padding(values ...int) Style

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

func (s Style) PaddingBottom(v int) Style

PaddingBottom sets the bottom padding.

func (Style) PaddingHorizontal

func (s Style) PaddingHorizontal(v int) Style

PaddingHorizontal sets the left and right paddings.

func (Style) PaddingLeft

func (s Style) PaddingLeft(v int) Style

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

func (s Style) PaddingRight(v int) Style

PaddingRight sets the right padding.

func (Style) PaddingTop

func (s Style) PaddingTop(v int) Style

PaddingTop sets the top padding.

func (Style) PaddingVertical

func (s Style) PaddingVertical(v int) Style

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) Reverse

func (s Style) Reverse(v bool) Style

Reverse sets the Reverse property.

func (Style) ReverseOpt

func (s Style) ReverseOpt() Optional[bool]

ReverseOpt returns the optional value of Reverse.

func (Style) Scrollbar

func (s Style) Scrollbar(v Scrollbar) Style

Scrollbar sets the Scrollbar property.

func (Style) ScrollbarOpt

func (s Style) ScrollbarOpt() Optional[Scrollbar]

ScrollbarOpt returns the optional value of Scrollbar.

func (Style) ScrollbarThumb

func (s Style) ScrollbarThumb(glyph rune, c color.Color) Style

ScrollbarThumb sets the glyph and color for the scrollbar thumb.

func (Style) ScrollbarTrack

func (s Style) ScrollbarTrack(glyph rune, c color.Color) Style

ScrollbarTrack sets the glyph and color for the scrollbar track.

func (Style) ScrollbarX

func (s Style) ScrollbarX(v bool) Style

ScrollbarX enables or disables the horizontal scrollbar.

func (Style) ScrollbarY

func (s Style) ScrollbarY(v bool) Style

ScrollbarY enables or disables the vertical scrollbar.

func (Style) SelectionBackground

func (s Style) SelectionBackground(v color.Color) Style

SelectionBackground sets the SelectionBackground property.

func (Style) SelectionBackgroundOpt

func (s Style) SelectionBackgroundOpt() Optional[color.Color]

SelectionBackgroundOpt returns the optional value of SelectionBackground.

func (Style) SelectionForeground

func (s Style) SelectionForeground(v color.Color) Style

SelectionForeground sets the SelectionForeground property.

func (Style) SelectionForegroundOpt

func (s Style) SelectionForegroundOpt() Optional[color.Color]

SelectionForegroundOpt returns the optional value of SelectionForeground.

func (Style) Strikethrough

func (s Style) Strikethrough(v bool) Style

Strikethrough sets the Strikethrough property.

func (Style) StrikethroughOpt

func (s Style) StrikethroughOpt() Optional[bool]

StrikethroughOpt returns the optional value of Strikethrough.

func (Style) TextAlign

func (s Style) TextAlign(v TextAlign) Style

TextAlign sets the TextAlign property.

func (Style) TextAlignOpt

func (s Style) TextAlignOpt() Optional[TextAlign]

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) TextWrap

func (s Style) TextWrap(v TextWrap) Style

TextWrap sets the TextWrap property.

func (Style) TextWrapOpt

func (s Style) TextWrapOpt() Optional[TextWrap]

TextWrapOpt returns the optional value of TextWrap.

func (Style) Underline

func (s Style) Underline(v bool) Style

Underline sets the Underline property.

func (Style) UnderlineOpt

func (s Style) UnderlineOpt() Optional[bool]

UnderlineOpt returns the optional value of Underline.

func (Style) When

func (s Style) When(cond bool, other Style) Style

When returns s.Merge(other) when cond is true, or s unchanged when false.

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) Width

func (s Style) Width(v Dimension) Style

Width sets the Width property.

func (Style) WidthOpt

func (s Style) WidthOpt() Optional[Dimension]

WidthOpt returns the optional value of Width.

func (Style) WithoutRules

func (s Style) WithoutRules() Style

WithoutRules returns a copy of s with pseudo-state and media rules removed.

func (Style) WordBreak

func (s Style) WordBreak(v WordBreak) Style

WordBreak sets the WordBreak property.

func (Style) WordBreakOpt

func (s Style) WordBreakOpt() Optional[WordBreak]

WordBreakOpt returns the optional value of WordBreak.

type TextAlign

type TextAlign uint8

TextAlign controls horizontal text alignment within a block.

const (
	// TextAlignLeft aligns text to the left edge.
	TextAlignLeft TextAlign = iota
	// TextAlignCenter centers text horizontally.
	TextAlignCenter
	// TextAlignRight aligns text to the right edge.
	TextAlignRight
)

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.

const (
	// TextWrapWord wraps at word boundaries.
	TextWrapWord TextWrap = iota
	// TextWrapChar wraps at any character boundary.
	TextWrapChar
	// TextWrapNone disables wrapping; text may overflow.
	TextWrapNone
)

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
)

type WordBreak

type WordBreak uint8

WordBreak controls whether grapheme-cluster boundaries may be used as soft break opportunities.

const (
	// WordBreakNormal breaks at the shaper's soft / mandatory opportunities.
	WordBreakNormal WordBreak = iota
	// WordBreakBreakAll allows a break before every grapheme cluster.
	WordBreakBreakAll
	// WordBreakKeepAll suppresses BreakAnywhere opportunities.
	WordBreakKeepAll
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL