Documentation
¶
Overview ¶
Package style is the stylesheet engine for visual components.
It is excluded from WebAssembly by `//go:build !wasm` so it can never reach the client binary.
Index ¶
- type Aspect
- type ColumnWidth
- type Elevation
- type Motion
- type Option
- func Animate(m Motion) Option
- func As(s Surface) Option
- func Backdrop(s Scope) Option
- func Center(max ...Size) Option
- func EdgeToEdge() Option
- func Fill() Option
- func FillCentered() Option
- func FontSize(ts TextSize) Option
- func FontWeight(w Weight) Option
- func Grid(min ColumnWidth, gap Space) Option
- func HideOverflow() Option
- func Interactive(s Surface) Option
- func KeepSize() Option
- func MediaBox(a Aspect) Option
- func Pad(s Space) Option
- func Raise(e Elevation) Option
- func RevealedBy(st widget.State) Option
- func Round(rad Radius) Option
- func Row(gap Space) Option
- func Scroll() Option
- func ScrollRow(gap Space) Option
- func Split(ratio SplitRatio, gap Space) Option
- func Stack(gap Space) Option
- func Veil() Option
- func Width(s Size) Option
- type Radius
- type Scope
- type Sheet
- func (s *Sheet) Cue(c widget.Cue, p widget.Part, opts ...Option) *Sheet
- func (s *Sheet) Part(p widget.Part, opts ...Option) *Sheet
- func (s *Sheet) Parts() []widget.Part
- func (s *Sheet) Root(opts ...Option) *Sheet
- func (s *Sheet) Stylesheet() *css.Stylesheet
- func (s *Sheet) Validate() []error
- func (s *Sheet) When(st widget.State, p widget.Part, opts ...Option) *Sheet
- type Size
- type Space
- type SplitRatio
- type Surface
- type TextSize
- type Weight
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnWidth ¶ added in v0.4.0
type ColumnWidth uint8
ColumnWidth represents minimum column width for grids.
const ( ColumnNarrow ColumnWidth = iota ColumnMedium ColumnWide )
type Motion ¶ added in v0.3.1
type Motion uint8
Motion is the transition scale. Duration is owned by CSS; here we only select the level.
type Option ¶ added in v0.4.0
type Option func(*rule)
Option is a visual option that configures a rule.
func As ¶ added in v0.4.0
As sets the surface decision (background, text, border, and radius default).
func Backdrop ¶ added in v0.3.0
Backdrop removes the element from the normal flow and stretches it over its Scope.
Example ¶
package main
import (
"github.com/tinywasm/widget"
"github.com/tinywasm/widget/style"
)
type myButton struct{}
func (b *myButton) WidgetName() widget.Name { return widget.Name("btn") }
func (b *myButton) WidgetKind() widget.Kind { return widget.Region }
func main() {
btn := &myButton{}
_ = style.For(btn).
Part("overlay", style.Backdrop(style.Viewport), style.Veil())
}
Output:
func Center ¶
Center defines a centered column with an optional maximum size (defaults to Readable).
func EdgeToEdge ¶ added in v0.4.0
func EdgeToEdge() Option
EdgeToEdge has no border radius or margin: flush against parent container.
func FillCentered ¶ added in v0.4.0
func FillCentered() Option
FillCentered fills the container with a centered child.
func Grid ¶
func Grid(min ColumnWidth, gap Space) Option
Grid defines auto-fit + minmax without a fixed number of columns.
func HideOverflow ¶ added in v0.4.0
func HideOverflow() Option
HideOverflow clips descendants (overflow: hidden).
func Interactive ¶ added in v0.4.0
Interactive applies s and derives its hover, focus, and press treatments.
Example ¶
package main
import (
"github.com/tinywasm/widget"
"github.com/tinywasm/widget/style"
)
type myButton struct{}
func (b *myButton) WidgetName() widget.Name { return widget.Name("btn") }
func (b *myButton) WidgetKind() widget.Kind { return widget.Region }
func main() {
btn := &myButton{}
_ = style.For(btn).
Root(style.Interactive(style.Primary))
}
Output:
func KeepSize ¶ added in v0.4.0
func KeepSize() Option
KeepSize does NOT reflow: maintains its size under any width.
func RevealedBy ¶ added in v0.4.0
RevealedBy binds hiding/showing the element to a widget State.
Example ¶
package main
import (
"github.com/tinywasm/widget"
"github.com/tinywasm/widget/style"
)
type myButton struct{}
func (b *myButton) WidgetName() widget.Name { return widget.Name("btn") }
func (b *myButton) WidgetKind() widget.Kind { return widget.Region }
func main() {
btn := &myButton{}
_ = style.For(btn).
Part("menu", style.RevealedBy(widget.Open))
}
Output:
func Scroll ¶ added in v0.4.0
func Scroll() Option
Scroll overflows internally instead of growing. Implies Fill().
func Split ¶
func Split(ratio SplitRatio, gap Space) Option
Split defines two panels that stack below their own width.
Example ¶
package main
import (
"github.com/tinywasm/widget"
"github.com/tinywasm/widget/style"
)
type myButton struct{}
func (b *myButton) WidgetName() widget.Name { return widget.Name("btn") }
func (b *myButton) WidgetKind() widget.Kind { return widget.Region }
func main() {
btn := &myButton{}
_ = style.For(btn).
Root(style.Split(style.SplitTwoThirds, style.Space3))
}
Output:
func Stack ¶
Stack defines a vertical rhythm with children at full width.
Example ¶
package main
import (
"github.com/tinywasm/widget"
"github.com/tinywasm/widget/style"
)
type myButton struct{}
func (b *myButton) WidgetName() widget.Name { return widget.Name("btn") }
func (b *myButton) WidgetKind() widget.Kind { return widget.Region }
func main() {
btn := &myButton{}
_ = style.For(btn).
Root(style.Stack(style.Space4))
}
Output:
type Sheet ¶
type Sheet struct {
// contains filtered or unexported fields
}
Sheet represents a scoped stylesheet for a widget.
func For ¶ added in v0.4.0
For opens the styling block for a widget.
Example ¶
package main
import (
"fmt"
"github.com/tinywasm/widget"
"github.com/tinywasm/widget/style"
)
type myButton struct{}
func (b *myButton) WidgetName() widget.Name { return widget.Name("btn") }
func (b *myButton) WidgetKind() widget.Kind { return widget.Region }
func main() {
btn := &myButton{}
sheet := style.For(btn).
Root(style.As(style.Primary))
fmt.Println(sheet.Parts())
}
Output: []
func (*Sheet) Cue ¶
Cue defines the style for a part (or Root if p is "") when the browser has a cue.
func (*Sheet) Stylesheet ¶
func (s *Sheet) Stylesheet() *css.Stylesheet
Stylesheet generates a css.Stylesheet for the Sheet.
type SplitRatio ¶ added in v0.4.0
type SplitRatio uint8
SplitRatio is the flex-grow ratio for Split partitions.
const ( SplitHalf SplitRatio = iota SplitTwoThirds SplitThreeQuarters )
type Surface ¶
type Surface uint8
Surface is a complete visual decision: background, text, and border resolved together.