slay

package module
v0.0.1-alpha20250930 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Zlib Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyCodeNone KeyCode = iota

	KeyLeft = 128 + iota
	KeyRight
	KeyUp
	KeyDown
	KeyEnter
	KeyEscape
	KeyHome
	KeyEnd
	KeyDeleteBackward
	KeyDeleteForward
	KeyPageUp
	KeyPageDown
	KeyTab
	KeySpace
	KeyCtrl
	KeyShift
	KeyAlt
	KeySuper
	KeyCommand

	KeyF1
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12
	KeyBack
)
View Source
const (
	HUE        = 0
	SATURATION = 1
	LIGHT      = 2
	ALPHA      = 3
)
View Source
const LOG_FONTS = false
View Source
const PAD_BOTTOM = 2
View Source
const PAD_LEFT = 3
View Source
const PAD_RIGHT = 1
View Source
const PAD_TOP = 0
View Source
const StretchCondensed = font.StretchCondensed
View Source
const StretchExpanded = font.StretchExpanded
View Source
const StretchExtraCondensed = font.StretchExtraCondensed
View Source
const StretchExtraExpanded = font.StretchExtraExpanded
View Source
const StretchNormal = font.StretchNormal
View Source
const StretchSemiCondensed = font.StretchSemiCondensed
View Source
const StretchSemiExpanded = font.StretchSemiExpanded
View Source
const StretchUltraCondensed = font.StretchUltraCondensed
View Source
const StretchUltraExpanded = font.StretchUltraExpanded
View Source
const StyleItalic = font.StyleItalic
View Source
const StyleNormal = font.StyleNormal
View Source
const WeightBlack = font.WeightBlack
View Source
const WeightBold = font.WeightBold
View Source
const WeightExtraBold = font.WeightExtraBold
View Source
const WeightExtraLight = font.WeightExtraLight
View Source
const WeightLight = font.WeightLight
View Source
const WeightMedium = font.WeightMedium
View Source
const WeightNormal = font.WeightNormal
View Source
const WeightSemibold = font.WeightSemibold
View Source
const WeightThin = font.WeightThin

Variables

View Source
var FrameInput struct {
	Mouse  MouseAction
	Motion Vec2 // mouse movement
	Scroll Vec2

	Key KeyCode

	Text string // text inputted this frame (could come from IME completion)

}

transient (frame level) input state

View Source
var InputState struct {
	MousePoint  Vec2
	MouseButton MouseButton

	DownKeys []KeyCode

	// control keys state
	Modifiers Modifiers

	Composition string // text being input via IME
}

persistent input state

View Source
var LayoutTime time.Duration

to be filled here

View Source
var Monospace = []string{"Noto Sans Mono", "Menlo", "Terminus", "Consolas", "Lucida Console"}
View Source
var SurfaceCount int
View Source
var TotalFrameTime time.Duration

to be filled by the backend

Functions

func Absf32

func Absf32(x float32) float32

func AutoFocus

func AutoFocus()

grab focus if this is our first render and nothing else is focused

func Blur

func Blur()

func CapAbove

func CapAbove[T cmp.Ordered](v *T, f T)

func CapBelow

func CapBelow[T cmp.Ordered](v *T, c T)

func CurrentId

func CurrentId() any

func CycleFocus

func CycleFocus(dir int)

dir should be 1 or -1, but an arbitrary number should work too ..

func CycleFocusOnTab

func CycleFocusOnTab()

func DeleteHookedData

func DeleteHookedData(data any, itemKey any)

func DirListing

func DirListing(path string) []os.DirEntry

func Element

func Element(attrs Attrs)

small helper to make code look cleaner

func ElementId

func ElementId(id any, attrs Attrs)

func FallbackFontFor

func FallbackFontFor(ch rune, aspect FontAspect) (FontId, GlyphId)

func FirstRender

func FirstRender() bool

func Focus

func Focus()

func FocusImmediate

func FocusImmediate()

func FocusImmediateOn

func FocusImmediateOn(id any)

func FocusOnClick

func FocusOnClick()

returns true if focus was received now

func GetLastId

func GetLastId() any

func GlyphOutline

func GlyphOutline(fontId FontId, glyphId GlyphId) font.GlyphOutline

func GlyphWidth

func GlyphWidth(fontId FontId, glyphId GlyphId) float32

func HasFocus

func HasFocus() bool

func HasFocusWithin

func HasFocusWithin() bool

func Hash

func Hash[T any](h *xxhash.Digest, v *T)

func HashSlice

func HashSlice[T any](h *xxhash.Digest, v []T)

func HashString

func HashString(h *xxhash.Digest, s string)

func HashStringHeader

func HashStringHeader(h *xxhash.Digest, s string)

func IdHasFocus

func IdHasFocus(id any) bool

func IdIsClicked

func IdIsClicked(id any) bool

func IdIsHovered

func IdIsHovered(id any) bool

func IdReceivedFocusNow

func IdReceivedFocusNow(id any) bool

func Image

func Image(fpath string, maxSize Vec2)

FIXME: we shuold be able to also specify minSize and border radius, perhaps border color too!

func InitFontSubsystem

func InitFontSubsystem()

must be called by backend before starting event loop

func IsActive

func IsActive() bool

func IsClicked

func IsClicked() bool

func IsHovered

func IsHovered() bool

func IsHoveredDirectly

func IsHoveredDirectly() bool

func IsIdHoveredDirectly

func IsIdHoveredDirectly(id any) bool

func Layout

func Layout(attrs Attrs, builder func())

func LayoutId

func LayoutId(id any, attrs Attrs, builder func())

open/close a container

func LoadImage

func LoadImage(fpath string) *image.RGBA

func LookupImage

func LookupImage(id ImageId) *image.RGBA

this function is mostly for the backend

func MainCrossAxes

func MainCrossAxes(row bool) (int, int)

func ModAttrs

func ModAttrs(fns ...func(*Attrs))

func Nil

func Nil()

func PressAction

func PressAction() bool

func ProfileNextFrame

func ProfileNextFrame(outputFilename string)

func PushSurface

func PushSurface(s Surface)

func ReadFileContent

func ReadFileContent(fpath string) []byte

func ReceivedFocusNow

func ReceivedFocusNow() bool

func RectContainsPoint

func RectContainsPoint(r Rect, p Vec2) bool

func RelId

func RelId(id any) scopeId

for when you don't want the id to be globally unique .. FIXME FIXME it does not seem like this thing actually works ..

func RequestNextFrame

func RequestNextFrame()

func RequestPaste

func RequestPaste()

func RequestTextCopy

func RequestTextCopy(text string)

func SafeTruncateUTF8

func SafeTruncateUTF8(s string, limit int) string

Generated by ChatGPT (initially)

func ScaleFactor

func ScaleFactor(fontId FontId) float32

func ScrollOnInput

func ScrollOnInput()

func SetActive

func SetActive()

func ShapedTextLayout

func ShapedTextLayout(shaped ShapedText, attrs TextAttrs, selectionFrom int, selectionTo int)

func Text

func Text(label string, attrs TextAttrs)

for now, one line only

func UnsetActive

func UnsetActive()

func Use

func Use[T any](itemKey any) *T

func UseData

func UseData[T any](data any, itemKey any) *T

Hook side data to any object FIXME perhaps this does not really belong to SLAY

func UseFontBytes

func UseFontBytes(data []byte) error

func UseFontFile

func UseFontFile(fpath string)

func UseFontFiles

func UseFontFiles(fpaths ...string)

func UseFontsDirectories

func UseFontsDirectories(dirpaths ...string)

func UseWithInit

func UseWithInit[T any](itemKey any, initFn func() *T) *T

func XAdvance

func XAdvance(fontId FontId, glyphId GlyphId) float32

Types

type Alignment

type Alignment int
const (
	AlignUnset Alignment = iota

	AlignStart
	AlignMiddle
	AlignEnd
)

type Attrs

type Attrs struct {

	// padding order is: top right bottom left
	Padding Vec4

	Gap float32

	// 0 means opaque, 1 means transperant (opacity = 1)
	// using this instead of opacity because the zero value is the good default
	Transperancy float32

	MainAlign  Alignment
	CrossAlign Alignment

	// properties for self with respect to parent!
	Grow      float32
	SelfAlign Alignment // override the parent's cross-align setting

	MinSize Vec2
	MaxSize Vec2

	Float Vec2

	Background Vec4
	Gradient   Vec4 // diff applied to background

	Border

	Shadow

	Corners Vec4

	// flags
	// Layout things ..
	Row          bool
	Wrap         bool
	ExpandAcross bool
	Floats       bool
	// size is not determined by content but by size constraints, flex growth, and cross axis expansion
	ExtrinsicSize bool

	// Event things
	ClickThrough bool
	Focusable    bool // items that can receive focus via clicking or tab-cycling

	// clip content drawn outside container boundaries
	// defaults to no clipping, because clip by default can have some undesirable side effects
	Clip bool

	// When certain interactions feel off if animated
	NoAnimate bool
}

type Border

type Border struct {
	BorderColor Vec4
	BorderWidth f32
}

type ClipStackOp

type ClipStackOp int
const (
	ClipPush ClipStackOp
	ClipPop
)

type Color

type Color = color.NRGBA

type Container

type Container struct {
	Id any
	Attrs
	// contains filtered or unexported fields
}

type Direction

type Direction byte
const (
	LTR Direction = iota
	RTL
)

func ParagraphBidi

func ParagraphBidi(txt string) []Direction

works with a single line of text, not an article with multiple paragraphs!

type FaceLookupKey

type FaceLookupKey struct {
	Family string
	Aspect FontAspect
}

type Font

type Font = font.Face

func GetParsedFont

func GetParsedFont(f FontId) *Font

type FontAspect

type FontAspect = font.Aspect

func DefaultFontAspect

func DefaultFontAspect() FontAspect

type FontFace

type FontFace struct {
	FontId FontId

	FaceLookupKey

	Filepath string

	// Inverted "Units Per eM"
	InvUPM float32

	// Extents
	Ascender  float32
	Descender float32
	LineGap   float32
	// contains filtered or unexported fields
}

FontFace holds some generic traits/info about the font face

func GetFace

func GetFace(f FontId) FontFace

type FontId

type FontId int32

func LookupFace

func LookupFace(key FaceLookupKey) FontId

type FrameFn

type FrameFn func()

type FrameOutputData

type FrameOutputData struct {
	Surfaces []Surface

	Copy  string // things we want to put into the clipboard
	Paste bool   // to request a clipboard read!

	NextFrameRequested bool
	FrameHasChanges    bool
}

func RunFrameFn

func RunFrameFn(frameFn FrameFn) FrameOutputData

RunFrame is meant to be called by the app & rendering backend

type Glyph

type Glyph struct {
	FontId   FontId
	GlyphId  GlyphId
	Cluster  int32
	Offset   Vec2
	XAdvance float32
	Width    float32

	// FIXME should this be here?
	Direction Direction
}

type GlyphId

type GlyphId = opentype.GID

func LookupGlyph

func LookupGlyph(fontId FontId, ch rune) GlyphId

type GlyphSegmentProps

type GlyphSegmentProps struct {
	Dir Direction
	// contains filtered or unexported fields
}

type GlyphsSegment

type GlyphsSegment struct {
	GlyphSegmentProps
	Width  float32
	Height float32
	Glyphs []Glyph
}

type Handle

type Handle int32

type HookEntryKey

type HookEntryKey struct {
	Data    any // container id
	ItemKey any
}

type HoverableArtifacts

type HoverableArtifacts struct {
	Rect      Rect
	Container *Container
}

type ImageId

type ImageId uint32

FIXME we need to manage images in a way that allows them to be added and removed dynamically without interfering with caching! in other words, we need to use a handles system!

func GetImageId

func GetImageId(fpath string) ImageId

type KeyCode

type KeyCode byte
const (
	Key0 KeyCode = '0' + iota
	Key1
	Key2
	Key3
	Key4
	Key5
	Key6
	Key7
	Key8
	Key9
)
const (
	// ascii table order
	KeyA KeyCode = 'A' + iota
	KeyB
	KeyC
	KeyD
	KeyE
	KeyF
	KeyG
	KeyH
	KeyI
	KeyJ
	KeyK
	KeyL
	KeyM
	KeyN
	KeyO
	KeyP
	KeyQ
	KeyR
	KeyS
	KeyT
	KeyU
	KeyV
	KeyW
	KeyX
	KeyY
	KeyZ
)

type KeyCombo

type KeyCombo struct {
	Key KeyCode
	Mod Modifiers
}

func ActiveCombo

func ActiveCombo() KeyCombo

func Combo

func Combo(key KeyCode, mod Modifiers) KeyCombo

type Modifiers

type Modifiers uint32
const (
	ModCtrl Modifiers = 1 << iota
	ModCmd
	ModShift
	ModAlt
	ModSuper
)

mirrors the values in gioui

const ModNone Modifiers = 0

type MouseAction

type MouseAction uint8
const (
	MouseClick MouseAction = 1 + iota
	MouseRelease
)

type MouseButton

type MouseButton uint8
const (
	MousePrimary MouseButton = iota
	MouseSecondary
	MouseTertiary
)

mirrors the values in gioui

type Rect

type Rect struct {
	Origin Vec2
	Size   Vec2
}

func GetContentRect

func GetContentRect() Rect

func GetContentRectOf

func GetContentRectOf(id any) Rect

func GetResolvedRectOf

func GetResolvedRectOf(target any) Rect

func GetScreenRect

func GetScreenRect() Rect

Get the screen rect of the current element from the previous frame data

func GetScreenRectOf

func GetScreenRectOf(target any) Rect

func RectIntersect

func RectIntersect(r1 Rect, r2 Rect) Rect

type RenderData

type RenderData struct {
	Attrs

	ResolvedSize   Vec2
	RelativeOrigin Vec2
	ResolvedOrigin Vec2
	// contains filtered or unexported fields
}

func GetRenderData

func GetRenderData() RenderData

func GetRenderDataOf

func GetRenderDataOf(id any) RenderData

type Shadow

type Shadow struct {
	Offset Vec2
	Blur   f32
	Alpha  f32
}

type ShadowMapKey

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

type ShapedText

type ShapedText struct {
	Runes   []rune
	BaseDir Direction
	Lines   []ShapedTextLine
}

func ShapeText

func ShapeText(text string, attrs TextAttrs) ShapedText

type ShapedTextLine

type ShapedTextLine struct {
	Segments []GlyphsSegment
	Width    float32
	Height   float32
}

type Stretch

type Stretch = font.Stretch

type Style

type Style = font.Style

type Surface

type Surface struct {
	Rect    Rect
	Color1  Vec4
	Color2  Vec4
	Corners Vec4 // corner radius

	Stroke     float32 // for borders!
	ImageId    ImageId
	ImageScale bool // if set, scales image down to fit surface!

	FontId      FontId
	GlyphId     GlyphId
	GlyphOffset Vec2

	Clip ClipStackOp

	Transperancy    float32
	PopTransperancy bool
}

type TextAttrs

type TextAttrs struct {
	TextStyle

	MaxWidth f32
}

func DefaultTextAttrs

func DefaultTextAttrs() TextAttrs

type TextLayout

type TextLayout struct {
	Segments []GlyphsSegment
}

type TextStyle

type TextStyle struct {
	Families []string
	FontAspect

	Color Vec4
	Size  f32
}

func DefaultTextStyle

func DefaultTextStyle() TextStyle

type Vec2

type Vec2 = [2]f32
var CaretPos Vec2

applications can set this to make the IME box appears in the right place

var WindowSize Vec2

to be set by backend

func GetAvailableSize

func GetAvailableSize() Vec2

func GetResolvedSize

func GetResolvedSize() Vec2

func PadSize

func PadSize(padding Vec4) Vec2

func Vec2Add

func Vec2Add(v1 Vec2, v2 Vec2) Vec2

func Vec2Mul

func Vec2Mul(v1 Vec2, f float32) Vec2

func Vec2Sub

func Vec2Sub(v1 Vec2, v2 Vec2) Vec2

type Vec4

type Vec4 = [4]f32

func N4

func N4(v f32) Vec4

func PaddingVH

func PaddingVH(v float32, h float32) Vec4

func Vec4Add

func Vec4Add(v1 Vec4, v2 Vec4) Vec4

func Vec4Sub

func Vec4Sub(v1 Vec4, v2 Vec4) Vec4

type Weight

type Weight = font.Weight

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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