Documentation
¶
Index ¶
- Constants
- Variables
- func ResolveIconPath(name string, size int) string
- func SetUIFont(role string, font *Font)
- func SetUIFonts(fonts map[string]*Font)
- type Backend
- type BaseWidget
- func (w *BaseWidget) Bounds() Rect
- func (w *BaseWidget) IsDirty() bool
- func (w *BaseWidget) IsFocused() bool
- func (w *BaseWidget) IsVisible() bool
- func (w *BaseWidget) MarkClean()
- func (w *BaseWidget) MarkDirty()
- func (w *BaseWidget) MinSize() Point
- func (w *BaseWidget) SelfDirty() bool
- func (w *BaseWidget) SetBounds(r Rect)
- func (w *BaseWidget) SetFocused(focused bool)
- func (w *BaseWidget) SetMinSize(size Point)
- func (w *BaseWidget) SetVisible(visible bool)
- type Buffer
- func (b *Buffer) Blit(src *Buffer, x, y int)
- func (b *Buffer) BlitOpaque(src *Buffer, x, y int)
- func (b *Buffer) BlitOpaqueRect(src *Buffer, srcRect Rect, x, y int)
- func (b *Buffer) BlitRect(src *Buffer, srcRect Rect, x, y int)
- func (b *Buffer) BlitScaled(src *Buffer, srcRect, dstRect Rect)
- func (b *Buffer) Clear(c Color)
- func (b *Buffer) ClearClip()
- func (b *Buffer) Clip() (Rect, bool)
- func (b *Buffer) DrawLine(x0, y0, x1, y1 int, c Color)
- func (b *Buffer) DrawRect(r Rect, c Color)
- func (b *Buffer) DrawRoundedRect(r Rect, radius int, c Color)
- func (b *Buffer) FillRect(r Rect, c Color)
- func (b *Buffer) FillRoundedRect(r Rect, radius int, c Color)
- func (b *Buffer) GetPixel(x, y int) Color
- func (b *Buffer) SetClip(r Rect)
- func (b *Buffer) SetPixel(x, y int, c Color)
- func (b *Buffer) SubBuffer(r Rect) *Buffer
- type Color
- type Event
- type EventType
- type Font
- type InputHandler
- type Key
- type Modifiers
- type MouseButton
- type PixelFormat
- type Point
- type Rect
- func (r Rect) Center() Point
- func (r Rect) Contains(p Point) bool
- func (r Rect) ContainsXY(x, y int) bool
- func (r Rect) Inset(top, right, bottom, left int) Rect
- func (r Rect) InsetAll(amount int) Rect
- func (r Rect) Intersection(other Rect) Rect
- func (r Rect) Intersects(other Rect) bool
- func (r Rect) IsEmpty() bool
- func (r Rect) Position() Point
- func (r Rect) Size() Point
- func (r Rect) Union(other Rect) Rect
- type TextAlign
- type Theme
- type Widget
Constants ¶
const ( UIFontParagraph = "paragraph" UIFontSubheading = "subheading" UIFontHeading = "heading" UIFontTitle = "title" )
Variables ¶
var ( ColorBlack = Color{0, 0, 0, 255} ColorWhite = Color{255, 255, 255, 255} ColorRed = Color{255, 0, 0, 255} ColorGreen = Color{0, 255, 0, 255} ColorBlue = Color{0, 0, 255, 255} ColorGray = Color{128, 128, 128, 255} ColorLightGray = Color{200, 200, 200, 255} ColorDarkGray = Color{64, 64, 64, 255} ColorTransparent = Color{0, 0, 0, 0} )
Common colors
var AvyosDark = Theme{ Background: NewColorHex(0x0B1220), Foreground: NewColorHex(0xEAF0FF), Primary: NewColorHex(0x3B7CFF), PrimaryHover: NewColorHex(0x3871E3), PrimaryActive: NewColorHex(0x2F67D1), Secondary: NewColorHex(0x1A2744B8), Border: NewColorHex(0xEAF0FF1F), BorderFocused: NewColorHex(0x3B7CFF73), InputBackground: NewColorHex(0x1A2744B8), InputForeground: NewColorHex(0xEAF0FF), ButtonText: NewColorHex(0xFFFFFFF2), SurfaceGlass: NewColorHex(0x121B2FB8), SurfaceRaised: NewColorHex(0x18233DD1), SurfaceSidebar: NewColorHex(0x0F1830C2), StrokeDivider: NewColorHex(0xEAF0FF14), TextSecondary: NewColorHex(0xB7C2DA), TextMuted: NewColorHex(0x8F9AB4), TextDisabled: NewColorHex(0xEAF0FF66), ControlHover: NewColorHex(0x223255C7), ControlPressed: NewColorHex(0x2A3D66D1), AccentSubtle: NewColorHex(0x3B7CFF2E), Success: NewColorHex(0x2FBF6D), Warning: NewColorHex(0xFF8A3D), Danger: NewColorHex(0xFF4D5E), BorderRadius: 10, }
var AvyosLight = Theme{ Background: NewColorHex(0xEEF2FA), Foreground: NewColorHex(0x121A2B), Primary: NewColorHex(0x2F6BFF), PrimaryHover: NewColorHex(0x2A5FE7), PrimaryActive: NewColorHex(0x2455D0), Secondary: NewColorHex(0xFFFFFFB2), Border: NewColorHex(0x1B2A4A24), BorderFocused: NewColorHex(0x2F6BFF59), InputBackground: NewColorHex(0xFFFFFFB2), InputForeground: NewColorHex(0x121A2B), ButtonText: NewColorHex(0xFFFFFFF2), SurfaceGlass: NewColorHex(0xF7F9FFB8), SurfaceRaised: NewColorHex(0xFFFFFFD1), SurfaceSidebar: NewColorHex(0xF3F6FFC2), StrokeDivider: NewColorHex(0x1B2A4A1A), TextSecondary: NewColorHex(0x3A4963), TextMuted: NewColorHex(0x63708A), TextDisabled: NewColorHex(0x121A2B59), ControlHover: NewColorHex(0xFFFFFFD1), ControlPressed: NewColorHex(0xDCE6FFB2), AccentSubtle: NewColorHex(0x2F6BFF24), Success: NewColorHex(0x2FBF6D), Warning: NewColorHex(0xFF8A3D), Danger: NewColorHex(0xFF4D5E), BorderRadius: 10, }
var BitmapFont = &Font{
Width: 8,
Height: 16,
FirstRun: 32,
LastRun: 126,
Glyphs: defaultGlyphs,
}
BitmapFont is the built-in 8x16 bitmap font.
var DefaultFont = BitmapFont
DefaultFont is the active font used by graphics and UI.
var DefaultTheme = AvyosLight
DefaultTheme is the default color theme.
var MayurDark = AvyosDark
var MayurLight = AvyosLight
Backwards-compatible aliases.
Functions ¶
func ResolveIconPath ¶
ResolveIconPath returns the best icon file path for name+size. Falls back to help.png if the requested icon is missing.
func SetUIFonts ¶
SetUIFonts sets multiple UI role fonts at once.
Types ¶
type Backend ¶
type Backend interface {
Open() error
Close() error
Size() (width, height int)
Buffer() *Buffer
Flush() error
FlushRect(Rect) error
Info() string
HasSystemCursor() bool
}
Backend is the display backend interface. Implementations include framebuffer (Linux /dev/fb0) and Wayland.
type BaseWidget ¶
type BaseWidget struct {
// contains filtered or unexported fields
}
BaseWidget provides common functionality for widgets.
func (*BaseWidget) IsDirty ¶
func (w *BaseWidget) IsDirty() bool
IsDirty returns true if the widget needs to be redrawn.
func (*BaseWidget) IsFocused ¶
func (w *BaseWidget) IsFocused() bool
IsFocused returns true if the widget has focus.
func (*BaseWidget) IsVisible ¶
func (w *BaseWidget) IsVisible() bool
IsVisible returns true if the widget is visible.
func (*BaseWidget) MarkClean ¶
func (w *BaseWidget) MarkClean()
MarkClean marks the widget as not needing a redraw.
func (*BaseWidget) MarkDirty ¶
func (w *BaseWidget) MarkDirty()
MarkDirty marks the widget as needing a redraw.
func (*BaseWidget) MinSize ¶
func (w *BaseWidget) MinSize() Point
MinSize returns the minimum size the widget needs.
func (*BaseWidget) SelfDirty ¶
func (w *BaseWidget) SelfDirty() bool
SelfDirty returns true if the widget itself needs a redraw. Containers can use this to distinguish their own dirty state from children.
func (*BaseWidget) SetBounds ¶
func (w *BaseWidget) SetBounds(r Rect)
SetBounds sets the widget's bounds.
func (*BaseWidget) SetFocused ¶
func (w *BaseWidget) SetFocused(focused bool)
SetFocused sets the focus state of the widget.
func (*BaseWidget) SetMinSize ¶
func (w *BaseWidget) SetMinSize(size Point)
SetMinSize sets the minimum size for the widget.
func (*BaseWidget) SetVisible ¶
func (w *BaseWidget) SetVisible(visible bool)
SetVisible sets the visibility of the widget.
type Buffer ¶
type Buffer struct {
Width int
Height int
Stride int
Format PixelFormat
Data []byte
// contains filtered or unexported fields
}
Buffer represents a pixel buffer for drawing.
func DecodeImageToBuffer ¶
DecodeImageToBuffer decodes raster formats directly and rasterizes SVG files. reqSize is used for SVG rasterization. If <= 0, a size is inferred from SVG metadata.
func LoadIcon ¶
LoadIcon loads an icon by name and size as a graphics.Buffer. If the icon does not exist, it falls back to help.png.
func (*Buffer) BlitOpaque ¶
BlitOpaque copies a source buffer onto this buffer, treating all pixels as fully opaque. This is useful for compositing surfaces with undefined alpha (e.g. XRGB8888).
func (*Buffer) BlitOpaqueRect ¶
BlitOpaqueRect copies a region of a source buffer onto this buffer, treating all source pixels as fully opaque.
func (*Buffer) BlitScaled ¶
BlitScaled copies a rectangular region of a source buffer onto this buffer, scaling to fit the destination rectangle using bilinear sampling.
func (*Buffer) DrawRoundedRect ¶
DrawRoundedRect draws a rounded rectangle outline.
func (*Buffer) FillRoundedRect ¶
FillRoundedRect fills a rectangle with rounded corners.
func (*Buffer) SetClip ¶
SetClip restricts subsequent drawing operations to the given rectangle. The clip is intersected with the buffer bounds.
type Color ¶
type Color struct {
R, G, B, A uint8
}
Color represents an RGBA color.
func NewColorHex ¶
NewColorHex creates a color from a hex value (0xRRGGBB or 0xRRGGBBAA).
func NewColorRGB ¶
NewColorRGB creates a new opaque color from RGB values.
type Event ¶
type Event struct {
Type EventType
// Mouse events
X, Y int
MouseButton MouseButton
// Keyboard events
Key Key
Rune rune
Modifiers Modifiers
}
Event represents an input event.
type Font ¶
type Font struct {
Width int
Height int
Glyphs map[rune][]byte
FirstRun rune
LastRun rune
// contains filtered or unexported fields
}
Font represents either a bitmap font or a vector TTF-backed font.
func LoadTTFFont ¶
LoadTTFFont creates a graphics.Font from raw TTF bytes.
func LoadTTFFontFile ¶
LoadTTFFontFile creates a graphics.Font from a TTF file path.
func NewDefaultTTFFont ¶
NewDefaultTTFFont creates a graphics.Font using gofont/goregular.
func NewTTFFont ¶
NewTTFFont wraps a shaped TTF face for the graphics renderer.
func (*Font) TextHeight ¶
TextHeight returns the height of text in pixels.
type InputHandler ¶
type InputHandler interface {
Open() error
Start()
Close() error
Poll() *Event
MousePosition() (x, y int)
SetScreenSize(width, height int)
}
InputHandler is the input handler interface. Implementations include evdev (Linux raw input) and Wayland seat.
type Key ¶
type Key int
Key represents a keyboard key.
const ( KeyNone Key = iota KeyEscape KeyBackspace KeyTab KeyEnter KeySpace KeyLeft KeyRight KeyUp KeyDown KeyHome KeyEnd KeyPageUp KeyPageDown KeyInsert KeyDelete KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyLeftShift KeyRightShift KeyLeftCtrl KeyRightCtrl KeyLeftAlt KeyRightAlt KeyCapsLock KeyNumLock KeyScrollLock )
type MouseButton ¶
type MouseButton int
MouseButton represents a mouse button.
const ( MouseButtonNone MouseButton = iota MouseButtonLeft MouseButtonMiddle MouseButtonRight MouseButtonWheelUp MouseButtonWheelDown MouseButtonWheelLeft MouseButtonWheelRight )
type PixelFormat ¶
type PixelFormat int
PixelFormat represents the pixel format of a buffer.
const ( PixelFormatBGRA PixelFormat = iota PixelFormatRGBA PixelFormatRGB565 )
type Rect ¶
Rect represents a rectangle with position and size.
func (Rect) ContainsXY ¶
ContainsXY returns true if the coordinates are inside the rectangle.
func (Rect) Intersection ¶
Intersection returns the intersection of two rectangles.
func (Rect) Intersects ¶
Intersects returns true if this rectangle intersects with another.
type Theme ¶
type Theme struct {
Background Color
Foreground Color
Primary Color
PrimaryHover Color
PrimaryActive Color
Secondary Color
Border Color
BorderFocused Color
InputBackground Color
InputForeground Color
ButtonText Color
SurfaceGlass Color
SurfaceRaised Color
SurfaceSidebar Color
StrokeDivider Color
TextSecondary Color
TextMuted Color
TextDisabled Color
ControlHover Color
ControlPressed Color
AccentSubtle Color
Success Color
Warning Color
Danger Color
BorderRadius int
}
Theme holds the colors used for rendering widgets.
type Widget ¶
type Widget interface {
Draw(buf *Buffer)
Bounds() Rect
SetBounds(r Rect)
MinSize() Point
HandleEvent(ev Event) bool
SetFocused(focused bool)
IsFocused() bool
IsDirty() bool
MarkClean()
SetVisible(visible bool)
IsVisible() bool
}
Widget is the interface that all widgets must implement.