avyos.dev/pkg/graphics

package graphics

Package Overview

No package-level documentation is provided.

Export GroupCount
Constants6
Variables8
Functions3
Types17

Constants

const (
	PixelFormatBGRA   = gfxcore.PixelFormatBGRA
	PixelFormatRGBA   = gfxcore.PixelFormatRGBA
	PixelFormatRGB565 = gfxcore.PixelFormatRGB565
)
const (
	UIFontParagraph  = "paragraph"
	UIFontSubheading = "subheading"
	UIFontHeading    = "heading"
	UIFontTitle      = "title"
)
const (
	EventNone               = gfxinput.EventNone
	EventMouseMove          = gfxinput.EventMouseMove
	EventMouseButtonPress   = gfxinput.EventMouseButtonPress
	EventMouseButtonRelease = gfxinput.EventMouseButtonRelease
	EventKeyPress           = gfxinput.EventKeyPress
	EventKeyRelease         = gfxinput.EventKeyRelease
	EventFocusIn            = gfxinput.EventFocusIn
	EventFocusOut           = gfxinput.EventFocusOut
	EventQuit               = gfxinput.EventQuit
	EventResize             = gfxinput.EventResize
	EventShortcut           = gfxinput.EventShortcut
)
const (
	MouseButtonNone       = gfxinput.MouseButtonNone
	MouseButtonLeft       = gfxinput.MouseButtonLeft
	MouseButtonMiddle     = gfxinput.MouseButtonMiddle
	MouseButtonRight      = gfxinput.MouseButtonRight
	MouseButtonWheelUp    = gfxinput.MouseButtonWheelUp
	MouseButtonWheelDown  = gfxinput.MouseButtonWheelDown
	MouseButtonWheelLeft  = gfxinput.MouseButtonWheelLeft
	MouseButtonWheelRight = gfxinput.MouseButtonWheelRight
)
const (
	KeyNone       = gfxinput.KeyNone
	KeyEscape     = gfxinput.KeyEscape
	KeyBackspace  = gfxinput.KeyBackspace
	KeyTab        = gfxinput.KeyTab
	KeyEnter      = gfxinput.KeyEnter
	KeySpace      = gfxinput.KeySpace
	KeyLeft       = gfxinput.KeyLeft
	KeyRight      = gfxinput.KeyRight
	KeyUp         = gfxinput.KeyUp
	KeyDown       = gfxinput.KeyDown
	KeyHome       = gfxinput.KeyHome
	KeyEnd        = gfxinput.KeyEnd
	KeyPageUp     = gfxinput.KeyPageUp
	KeyPageDown   = gfxinput.KeyPageDown
	KeyInsert     = gfxinput.KeyInsert
	KeyDelete     = gfxinput.KeyDelete
	KeyF1         = gfxinput.KeyF1
	KeyF2         = gfxinput.KeyF2
	KeyF3         = gfxinput.KeyF3
	KeyF4         = gfxinput.KeyF4
	KeyF5         = gfxinput.KeyF5
	KeyF6         = gfxinput.KeyF6
	KeyF7         = gfxinput.KeyF7
	KeyF8         = gfxinput.KeyF8
	KeyF9         = gfxinput.KeyF9
	KeyF10        = gfxinput.KeyF10
	KeyF11        = gfxinput.KeyF11
	KeyF12        = gfxinput.KeyF12
	KeyLeftShift  = gfxinput.KeyLeftShift
	KeyRightShift = gfxinput.KeyRightShift
	KeyLeftCtrl   = gfxinput.KeyLeftCtrl
	KeyRightCtrl  = gfxinput.KeyRightCtrl
	KeyLeftAlt    = gfxinput.KeyLeftAlt
	KeyRightAlt   = gfxinput.KeyRightAlt
	KeyCapsLock   = gfxinput.KeyCapsLock
	KeyNumLock    = gfxinput.KeyNumLock
	KeyScrollLock = gfxinput.KeyScrollLock
)
const (
	ModShift    = gfxinput.ModShift
	ModCtrl     = gfxinput.ModCtrl
	ModAlt      = gfxinput.ModAlt
	ModCapsLock = gfxinput.ModCapsLock
)

Variables

var (
	ColorBlack       = gfxcore.ColorBlack
	ColorWhite       = gfxcore.ColorWhite
	ColorRed         = gfxcore.ColorRed
	ColorGreen       = gfxcore.ColorGreen
	ColorBlue        = gfxcore.ColorBlue
	ColorGray        = gfxcore.ColorGray
	ColorLightGray   = gfxcore.ColorLightGray
	ColorDarkGray    = gfxcore.ColorDarkGray
	ColorTransparent = gfxcore.ColorTransparent

	NewColor    = gfxcore.NewColor
	NewColorRGB = gfxcore.NewColorRGB
	NewColorHex = gfxcore.NewColorHex
	NewRect     = gfxcore.NewRect
	NewBuffer   = gfxcore.NewBuffer
)
var AvyosDark = gfxtheme.AvyosDark
var AvyosLight = gfxtheme.AvyosLight
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 = gfxtheme.AvyosLight
var MayurDark = AvyosDark
var MayurLight = AvyosLight

Backwards-compatible aliases.

Functions

func ResolveIconPath(name string, size int) string

ResolveIconPath returns the best icon file path for name+size. Falls back to help.{svg,png} if the requested icon is missing.

func SetUIFont(role string, font *Font)

SetUIFont sets a font for a logical UI text role.

func SetUIFonts(fonts map[string]*Font)

SetUIFonts sets multiple UI role fonts at once.

Types

Backend

type Backend = gfxinput.Backend

BaseWidget

type BaseWidget struct {
	// contains filtered or unexported fields
}

BaseWidget provides common functionality for widgets.

Functions

func NewBaseWidget() BaseWidget

NewBaseWidget creates a new base widget.

Methods

func (w *BaseWidget) Bounds() Rect

Bounds returns the widget's bounds.

func (w *BaseWidget) IsDirty() bool

IsDirty returns true if the widget needs to be redrawn.

func (w *BaseWidget) IsFocused() bool

IsFocused returns true if the widget has focus.

func (w *BaseWidget) IsVisible() bool

IsVisible returns true if the widget is visible.

func (w *BaseWidget) MarkClean()

MarkClean marks the widget as not needing a redraw.

func (w *BaseWidget) MarkDirty()

MarkDirty marks the widget as needing a redraw.

func (w *BaseWidget) MinSize() Point

MinSize returns the minimum size the widget needs.

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 (w *BaseWidget) SetBounds(r Rect)

SetBounds sets the widget's bounds.

func (w *BaseWidget) SetFocused(focused bool)

SetFocused sets the focus state of the widget.

func (w *BaseWidget) SetMinSize(size Point)

SetMinSize sets the minimum size for the widget.

func (w *BaseWidget) SetVisible(visible bool)

SetVisible sets the visibility of the widget.

Buffer

type Buffer = gfxcore.Buffer

Functions

func DecodeImageToBuffer(path string, reqSize int) (*Buffer, error)

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(name string, size int) (*Buffer, error)

LoadIcon loads an icon by name and size as a graphics.Buffer.

Color

type Color = gfxcore.Color

Event

type Event = gfxinput.Event

EventType

type EventType = gfxinput.EventType

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.

Functions

func LoadTTFFont(ttf []byte, opts *gfxfont.Options) (*Font, error)

LoadTTFFont creates a graphics.Font from raw TTF bytes.

func LoadTTFFontFile(path string, opts *gfxfont.Options) (*Font, error)

LoadTTFFontFile creates a graphics.Font from a TTF file path.

func NewDefaultTTFFont(opts *gfxfont.Options) (*Font, error)

NewDefaultTTFFont creates a graphics.Font using gofont/goregular.

func NewTTFFont(face *gfxfont.Font) *Font

NewTTFFont wraps a shaped TTF face for the graphics renderer.

func UIFont(role string) *Font

UIFont returns the font for a UI role, falling back to the default font.

Methods

func (f *Font) Close() error

Close releases font resources when supported by the backing renderer.

func (f *Font) DrawGlyph(buf *Buffer, r rune, x, y int, fg, bg Color)

DrawGlyph draws a single character glyph to a buffer.

func (f *Font) DrawText(buf *Buffer, text string, x, y int, fg, bg Color)

DrawText draws text to a buffer at the given position.

func (f *Font) TextHeight(text string) int

TextHeight returns the height of text in pixels.

func (f *Font) TextWidth(text string) int

TextWidth returns the width of text in pixels.

InputHandler

type InputHandler = gfxinput.InputHandler

Key

type Key = gfxinput.Key

Modifiers

type Modifiers = gfxinput.Modifiers

MouseButton

type MouseButton = gfxinput.MouseButton

PixelFormat

type PixelFormat = gfxcore.PixelFormat

Point

type Point = gfxcore.Point

Rect

type Rect = gfxcore.Rect

TextAlign

type TextAlign int

TextAlign represents text alignment.

Constants

const (
	AlignLeft TextAlign = iota
	AlignCenter
	AlignRight
)

Theme

type Theme = gfxtheme.Theme

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.