gui

package module
v0.0.0-...-9fe45fa Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 9 Imported by: 0

README

goo

A simple GUI library using SDL written in Go.

more docs coming soon

Installation

go get github.com/jessehorne/goo

Documentation

For now, see examples/.

License

See LICENSE

Documentation

Index

Constants

View Source
const ALIGN_CENTER = 0 // margin, padding and center alignment
View Source
const ALIGN_FREE = 1 // no automated position adjustment

Variables

View Source
var BUTTON_LIGHT = HexToColor("5DA7DB")
View Source
var BUTTON_LIGHTER = HexToColor("81C6E8")
View Source
var BUTTON_PRIMARY = HexToColor("5837D0")
View Source
var BUTTON_SECONDARY = HexToColor("7DE5ED")
View Source
var COLOR_BLACK = RGBAToColor(0, 0, 0, 0)
View Source
var COLOR_BLUE = RGBAToColor(0, 0, 255, 0)
View Source
var COLOR_CLEAR = RGBAToColor(50, 0, 0, 0)
View Source
var COLOR_GREEN = RGBAToColor(0, 255, 0, 0)
View Source
var COLOR_GREY = RGBAToColor(155, 155, 155, 0)
View Source
var COLOR_PRIMARY_DARK = RGBAToColor(27, 47, 51, 0)
View Source
var COLOR_PRIMARY_LIGHT = RGBAToColor(57, 77, 81, 0)
View Source
var COLOR_RED = RGBAToColor(255, 0, 0, 50)
View Source
var COLOR_WHITE = RGBAToColor(255, 255, 255, 0)
View Source
var COLOR_WHITE_ALPHA = RGBAToColor(255, 255, 255, 30)
View Source
var CharsLower = "abcdefghijklmnopqrstuvwxyz`1234567890-=[]\\;',./"
View Source
var CharsTypeable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ`1234567890-=[]\\;',./"
View Source
var CharsUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?"
View Source
var Color = COLOR_WHITE // current draw color for many things such as primitives and font text
View Source
var FontSize int32 = 14
View Source
var FontSizeRange = []int32{8, 14, 20, 24, 32, 36, 40, 48, 52}
View Source
var FontStyle = "normal" // can be regular or light
View Source
var Fonts = make(map[string]map[int32]*Font)
View Source
var THEME_BLUE_50 = HexToColor("0a84ff")
View Source
var THEME_BLUE_60 = HexToColor("0060df")
View Source
var THEME_BLUE_70 = HexToColor("003eaa")
View Source
var THEME_BLUE_80 = HexToColor("16213E")
View Source
var THEME_BLUE_85 = HexToColor("27324F")
View Source
var THEME_BLUE_90 = HexToColor("1A1A2E")

Functions

func BBox

func BBox(r1 sdl.Rect, r2 sdl.Rect) bool

func Cleanup

func Cleanup()

func ClearScreen

func ClearScreen()

func ColorToRGBA

func ColorToRGBA(c sdl.Color) (uint8, uint8, uint8, uint8)

ColorToRGBA returns the correct RGBA values because it's mixed up somehow

func DrawFilledRect

func DrawFilledRect(rect *sdl.Rect)

func DrawImage

func DrawImage(img *Image, x int32, y int32)

func DrawLineRect

func DrawLineRect(rect *sdl.Rect)

func GetTextSize

func GetTextSize(s string) (int, int)

func HexToColor

func HexToColor(hex string) sdl.Color

func Init

func Init(app *App) error

Init sets up pointers to everything that will be used for drawing and so on

func InitFonts

func InitFonts() error

func KeyboardEvent

func KeyboardEvent(cs []*Container, keyType uint32, key sdl.Keysym)

func LoadFont

func LoadFont(fontStyle string, path string, fontSize int32) error

func LoadFontRanges

func LoadFontRanges(fontStyle string, r []int32) error

func MouseButtonEvent

func MouseButtonEvent(cs []*Container, event *sdl.MouseButtonEvent)

func Print

func Print(s string, x int32, y int32) error

func PrintInsideRect

func PrintInsideRect(s string, x int32, y int32, rect *sdl.Rect) error

func RGBAToColor

func RGBAToColor(r uint8, g uint8, b uint8, a uint8) sdl.Color

RGBAToColor returns the correct sdl.Color because it's mixed up somehow

func RedrawAllContainers

func RedrawAllContainers(cs []*Container)

func RedrawContainer

func RedrawContainer(c *Container)

func ResetClipRect

func ResetClipRect()

func SetColor

func SetColor(color sdl.Color)

func SetFont

func SetFont(fontStyle string, fontSize int32) error

func UpdateHoverStateForAllContainers

func UpdateHoverStateForAllContainers(cs []*Container)

func UpdateMousePos

func UpdateMousePos(x int32, y int32)

Types

type App

type App struct {
	Title           string
	ScreenWidth     int32
	ScreenHeight    int32
	Containers      []*Container
	Running         bool
	MouseX          int32
	MouseY          int32
	BackgroundColor sdl.Color
}
var A *App

func NewApp

func NewApp(title string, w int32, h int32) (*App, error)

func (*App) AddContainer

func (a *App) AddContainer(c *Container)

func (*App) Close

func (s *App) Close()

func (*App) RunLoop

func (a *App) RunLoop()

func (*App) SetBackgroundColor

func (a *App) SetBackgroundColor(c sdl.Color)

func (*App) SetTitle

func (a *App) SetTitle(title string)

type Container

type Container struct {
	X               int32
	Y               int32
	Width           int32
	Height          int32
	BackgroundColor sdl.Color
	OutlineColor    sdl.Color
	Elements        []interface{}
	ElementOffsetX  int32
	Alignment       uint8
	AlignMargin     int32
}

func NewContainer

func NewContainer(x int32, y int32, w int32, h int32) *Container

func (*Container) AddElement

func (c *Container) AddElement(e interface{})

func (*Container) AlignElementsCenter

func (c *Container) AlignElementsCenter()

func (*Container) Draw

func (c *Container) Draw()

func (*Container) ResetHoverStates

func (c *Container) ResetHoverStates()

func (*Container) SetAlignment

func (c *Container) SetAlignment(a uint8)

func (*Container) SetBackgroundColor

func (c *Container) SetBackgroundColor(newColor sdl.Color)

func (*Container) SetOutlineColor

func (c *Container) SetOutlineColor(newColor sdl.Color)

type Element

type Element interface {
	Draw()
	Trigger()
	GetPos() (int32, int32)   // get position inside container
	SetPos(x int32, y int32)  // set position inside container
	GetSize() (int32, int32)  // get size of element
	SetSize(w int32, h int32) // set size of element
	SetHover(which bool)      // sets whether mouse is hovering over an element
	KeyboardEvent(keyType uint32, key sdl.Keysym)
	MouseButtonEvent(event *sdl.MouseButtonEvent)
}

Element represents all drawable objects. Other libraries call these "widgets"

type Font

type Font struct {
	Font     *ttf.Font
	FontSize int32
}

func CurrentFont

func CurrentFont() *Font

type Image

type Image struct {
	X       int32
	Y       int32
	Width   int32
	Height  int32
	Texture *sdl.Texture
}

func NewImageFromSVG

func NewImageFromSVG(path string, x int32, y int32, w int32, h int32) (*Image, error)

type ImgButton

type ImgButton struct {
	X               int32
	Y               int32
	Width           int32
	Height          int32
	BackgroundColor sdl.Color
	OutlineColor    sdl.Color
	MarginX         int32
	MarginY         int32
	PaddingX        int32
	PaddingY        int32
	IsHovering      bool
	IsHolding       bool
	Image           *Image
	Callback        func(b *ImgButton)
}

func NewImgButton

func NewImgButton(path string, x int32, y int32) (*ImgButton, error)

func (*ImgButton) Draw

func (b *ImgButton) Draw()

func (*ImgButton) GetPos

func (b *ImgButton) GetPos() (int32, int32)

func (*ImgButton) GetSize

func (b *ImgButton) GetSize() (int32, int32)

func (*ImgButton) KeyboardEvent

func (b *ImgButton) KeyboardEvent(keyType uint32, key sdl.Keysym)

func (*ImgButton) MouseButtonEvent

func (b *ImgButton) MouseButtonEvent(event *sdl.MouseButtonEvent)

func (*ImgButton) SetCallback

func (b *ImgButton) SetCallback(f func(i *ImgButton))

func (*ImgButton) SetHolding

func (b *ImgButton) SetHolding(which bool)

func (*ImgButton) SetHover

func (b *ImgButton) SetHover(which bool)

func (*ImgButton) SetMargin

func (b *ImgButton) SetMargin(x int32, y int32)

func (*ImgButton) SetPadding

func (b *ImgButton) SetPadding(x int32, y int32)

func (*ImgButton) SetPos

func (b *ImgButton) SetPos(x int32, y int32)

func (*ImgButton) SetSize

func (b *ImgButton) SetSize(w int32, h int32)

func (*ImgButton) Trigger

func (b *ImgButton) Trigger()

type Label

type Label struct {
	Text       string
	X          int32
	Y          int32
	Width      int32
	Height     int32
	Color      sdl.Color
	IsHovering bool
	FontStyle  string
	FontSize   int32
}

func NewLabel

func NewLabel(text string, fontSize int32, x int32, y int32) *Label

func (*Label) Draw

func (l *Label) Draw()

func (*Label) GetPos

func (l *Label) GetPos() (int32, int32)

func (*Label) GetSize

func (l *Label) GetSize() (int32, int32)

func (*Label) KeyboardEvent

func (l *Label) KeyboardEvent(keyType uint32, key sdl.Keysym)

func (*Label) MouseButtonEvent

func (l *Label) MouseButtonEvent(event *sdl.MouseButtonEvent)

func (*Label) SetFont

func (l *Label) SetFont(fontStyle string, fontSize int32)

func (*Label) SetHover

func (l *Label) SetHover(which bool)

func (*Label) SetPos

func (l *Label) SetPos(x int32, y int32)

func (*Label) SetSize

func (l *Label) SetSize(w int32, h int32)

func (*Label) Trigger

func (l *Label) Trigger()

type OneLineInput

type OneLineInput struct {
	X                 int32
	Y                 int32
	Width             int32
	Height            int32
	BackgroundColor   sdl.Color
	OutlineColor      sdl.Color
	TextColor         sdl.Color
	HighlightColor    sdl.Color
	PlaceholderColor  sdl.Color
	CursorPos         int32
	CursorX           int32
	MaxChars          int32
	Text              string
	Placeholder       string
	HighlightStartPos int32
	HighlightEndPos   int32
	MarginX           int32
	MarginY           int32
	PaddingX          int32
	PaddingY          int32
	Active            bool
	IsHovering        bool
	IsHoldingShift    bool
	Callback          func(i *OneLineInput)
	Font              *Font
	FontStyle         string
	FontSize          int32
}

func NewOneLineInput

func NewOneLineInput(placeholder string, x int32, y int32, w int32, h int32) *OneLineInput

func (*OneLineInput) AddText

func (i *OneLineInput) AddText(t string)

func (*OneLineInput) Backspace

func (i *OneLineInput) Backspace()

func (*OneLineInput) ClearText

func (i *OneLineInput) ClearText()

func (*OneLineInput) Draw

func (i *OneLineInput) Draw()

func (*OneLineInput) GetPos

func (i *OneLineInput) GetPos() (int32, int32)

func (*OneLineInput) GetSize

func (i *OneLineInput) GetSize() (int32, int32)

func (*OneLineInput) KeyboardEvent

func (i *OneLineInput) KeyboardEvent(t uint32, key sdl.Keysym)

func (*OneLineInput) MouseButtonEvent

func (i *OneLineInput) MouseButtonEvent(event *sdl.MouseButtonEvent)

func (*OneLineInput) MoveCursor

func (i *OneLineInput) MoveCursor(pos int32)

func (*OneLineInput) SetActive

func (i *OneLineInput) SetActive(which bool)

func (*OneLineInput) SetCallback

func (i *OneLineInput) SetCallback(f func(i *OneLineInput))

func (*OneLineInput) SetFont

func (i *OneLineInput) SetFont(fontStyle string, fontSize int32)

func (*OneLineInput) SetHover

func (i *OneLineInput) SetHover(which bool)

func (*OneLineInput) SetPos

func (i *OneLineInput) SetPos(x int32, y int32)

func (*OneLineInput) SetSize

func (i *OneLineInput) SetSize(w int32, h int32)

func (*OneLineInput) Trigger

func (i *OneLineInput) Trigger()

type TextButton

type TextButton struct {
	X               int32
	Y               int32
	Width           int32
	Height          int32
	BackgroundColor sdl.Color
	OutlineColor    sdl.Color
	MarginX         int32
	MarginY         int32
	PaddingX        int32
	PaddingY        int32
	Text            string
	IsHovering      bool
	IsHolding       bool
	Callback        func(i *TextButton)
	FontStyle       string
	FontSize        int32
}

func NewTextButton

func NewTextButton(t string, x int32, y int32) *TextButton

func (*TextButton) Draw

func (b *TextButton) Draw()

func (*TextButton) GetPos

func (b *TextButton) GetPos() (int32, int32)

func (*TextButton) GetSize

func (b *TextButton) GetSize() (int32, int32)

func (*TextButton) KeyboardEvent

func (b *TextButton) KeyboardEvent(keyType uint32, key sdl.Keysym)

func (*TextButton) MouseButtonEvent

func (b *TextButton) MouseButtonEvent(event *sdl.MouseButtonEvent)

func (*TextButton) SetCallback

func (b *TextButton) SetCallback(f func(i *TextButton))

func (*TextButton) SetFont

func (b *TextButton) SetFont(fontStyle string, fontSize int32)

func (*TextButton) SetHolding

func (b *TextButton) SetHolding(which bool)

func (*TextButton) SetHover

func (b *TextButton) SetHover(which bool)

func (*TextButton) SetMargin

func (b *TextButton) SetMargin(x int32, y int32)

func (*TextButton) SetPadding

func (b *TextButton) SetPadding(x int32, y int32)

func (*TextButton) SetPos

func (b *TextButton) SetPos(x int32, y int32)

func (*TextButton) SetSize

func (b *TextButton) SetSize(w int32, h int32)

func (*TextButton) Trigger

func (b *TextButton) Trigger()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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