fizzgui

package module
v0.0.0-...-bef4f46 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2018 License: BSD-2-Clause Imports: 21 Imported by: 1

README

FizzGUI

FizzGUI is an OpenGL GUI for Fizzle engine, сonstructed from EweyGewey, but reworked crucially.

UNDER CONSTRUCTION

At present, it is very much in an alpha stage with new development adding in features, widgets and possibly API breaks. Any API break should increment the minor version number and any patch release tags should remain compatible even in development 0.x versions.

Screenshots

Here's some of what's available right now in the example:

screenshot

Requirements

  • Mathgl - for 3d math
  • Freetype - for dynamic font texture generation
  • Fizzle - provides an OpenGL 3/es2/es3 abstraction
  • GLFW (v3.1) - currently GLFW is the only 'host' support for input

Differences

  • Windows were replaced on Containers, containers can not be moved and do not have a title, scrollbars(current) are not available too.
  • Containers may create various widgets, widgets are placed one by one, if there is no enough space in row, widget moves to the new row(in html it looks like a float).
  • Widget may have a fixed position
  • Smart layout system for positioning of containers and widgets
  • Some widgets may have callbacks(signals) calling on appropriated events(ex: press button)

Current Features

  • Containers
    • Text
    • Input text
    • Button
    • Checkbox
    • Progressbar
    • Images
    • Drag and Drop system

TODO

The following need to be addressed in order to start releases:

  • more widgets:
    • text wrapping
    • multi-line text editors
    • combobox
  • editbox cursor doesn't start where mouse was clicked
  • and more other

LICENSE

Original package EweyGewey is released under the BSD license. See the LICENSE file for more details.

Documentation

Index

Constants

View Source
const (
	HAlignLeft = iota
	HAlignCenter
	HAlignRight
)
View Source
const (
	VAlignTop = iota
	VAlignMiddle
	VAlignBottom
)
View Source
const (
	MouseDown = iota
	MouseUp
	MouseClick
	MouseDoubleClick
)

constants used for polling the state of a mouse button

Variables

View Source
var (
	ActiveWidget   *Widget
	HoverWidget    *Widget
	HoverContainer *Container
)
View Source
var (
	BGColorContainer = mgl32.Vec4{0.15, 0.15, 0.15, 0.75}

	BGColor         = mgl32.Vec4{0.3, 0.3, 0.3, 1}
	BGColorHover    = mgl32.Vec4{0.4, 0.4, 0.4, 1}
	BGColorSelected = mgl32.Vec4{0.5, 0.5, 0.5, 1}

	BGColorBtn      = mgl32.Vec4{0.18, 0.18, 0.18, 1}
	BGColorBtnHover = mgl32.Vec4{0.28, 0.28, 0.28, 1}

	BGColorHighlight = mgl32.Vec4{0.17, 0.4, 0.63, 1}

	TextColor         = mgl32.Vec4{0.8, 0.8, 0.8, 1}
	TextColorSelected = mgl32.Vec4{0.9, 0.9, 0.9, 1}
	TextColorHiglight = mgl32.Vec4{0.17, 0.4, 0.63, 1}

	BorderColor         = mgl32.Vec4{0.15, 0.15, 0.15, 1}
	BorderColorHiglight = mgl32.Vec4{0.17, 0.4, 0.63, 1}

	BGColorImage      = mgl32.Vec4{0.9, 0.9, 0.9, 1}
	BGColorImageHover = mgl32.Vec4{1, 1, 1, 1}
)

Default colors

View Source
var DefaultMargin = Offset{4, 4, 4, 4}
View Source
var DefaultPadding = Offset{4, 4, 4, 4}
View Source
var FontGlyphs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.,:[]{}\\|<>;\"'~`?/-+_=()*&^%$#@! "
View Source
var Keys *keyboard
View Source
var Mouse *mouse
View Source
var ShaderF = `` /* 830-byte string literal not displayed */
View Source
var ShaderV = `` /* 236-byte string literal not displayed */

Functions

func Color

func Color(r, g, b, a int) mgl32.Vec4

Color takes the color parameters as integers and returns them as a float vector.

func Construct

func Construct()

Construct loops through all of the Windows in the Manager and creates all of the widgets and their data. This function does not buffer the result to VBO or do the actual rendering -- call Draw() for that.

func DelContainer

func DelContainer(ptr *Container)

func GetFirstCmd

func GetFirstCmd(z uint8) *cmdList

GetFirstCmd create new cmd and insert in to first element

func GetLastCmd

func GetLastCmd(z uint8) *cmdList

GetLastCmd will return the last non-custom cmdList

func Init

func Init(glfwWindow *glfw.Window, graphProv graphics.GraphicsProvider) error

Init gui

func ParseSize

func ParseSize(val string) (i float32, percent bool)

ParseSize parse string value to float and percent bool

Types

type Callback

type Callback func(wgt *Widget)

type Container

type Container struct {
	ID               string
	Hidden           bool
	AutoAdjustHeight bool

	//not yet ready
	ShowScrollBar  bool
	IsScrollable   bool
	ScrollBarWidth float32
	ScrollOffset   float32

	FontName string
	Style    Style
	Layout   *Layout

	Zorder uint8

	Widgets []*Widget
}

Container represents a collection of widgets in the user interface.

func NewContainer

func NewContainer(id string, x, y, w, h string) *Container

NewContainer creates new container for widgets x,y,w,h is string size ex: "80%", "200px"...

func (*Container) Close

func (c *Container) Close()

Close function remove this window from window slice

func (*Container) NewButton

func (c *Container) NewButton(text string, f Callback) *Widget

func (*Container) NewCheckbox

func (c *Container) NewCheckbox(value *bool, f Callback) *Widget

func (*Container) NewImg

func (c *Container) NewImg(img *Texture, x, y, w, h string) *Widget

func (*Container) NewInput

func (c *Container) NewInput(id string, text *string, f Callback) *Widget

NewInput creates an editbox control that changes the value string.

func (*Container) NewProgressBar

func (c *Container) NewProgressBar(value *float32, min, max float32, f Callback) *Widget

func (*Container) NewRow

func (c *Container) NewRow() *Widget

simple row

func (*Container) NewSlot

func (c *Container) NewSlot(group *DADGroup, id string, x, y, w, h string, f DADCallback) *DADSlot

NewSlot - create new drag and drop slot and call callback on it

func (*Container) NewText

func (c *Container) NewText(text string) *Widget

type Cursor

type Cursor struct {
	Layout *Layout

	X float32
	Y float32
	// contains filtered or unexported fields
}

Cursor provide point to widgets position

func (*Cursor) NextRow

func (cursor *Cursor) NextRow()

type DADCallback

type DADCallback func(item *DADItem, slot *DADSlot, prev *DADSlot) bool

DADCallback call when item place to slot, in argument: item, slot and item value, boolean returned value allows place item to this slot or not

type DADGroup

type DADGroup struct {
	*Container

	ID string

	Slots []*DADSlot
	Items []*DADItem
	// contains filtered or unexported fields
}

DADGroup compound slot and items

func NewDragAndDropGroup

func NewDragAndDropGroup(id string) *DADGroup

NewDragAndDropGroup create new drag and drop group

func (*DADGroup) NewItem

func (group *DADGroup) NewItem(id, img string, data interface{}) *DADItem

NewItem - create new DADItem

type DADItem

type DADItem struct {
	*Widget

	Slot  *DADSlot
	Group *DADGroup
}

DADItem it is movable item

type DADSlot

type DADSlot struct {
	*Widget

	Item  *DADItem
	Group *DADGroup
	// contains filtered or unexported fields
}

DADSlot is slot for place drag and drop item

func (*DADSlot) PlaceItem

func (slot *DADSlot) PlaceItem(item *DADItem)

type Font

type Font struct {
	Texture     graphics.Texture
	TextureSize int
	Glyphs      string
	GlyphHeight float32
	GlyphWidth  float32
	// contains filtered or unexported fields
}

Font contains data regarding a font and the texture that was created with the specified set of glyphs. It can then be used to create renderable string objects.

func GetFont

func GetFont(name string) *Font

GetFont attempts to get the font by name from the Manager's collection It returns the font on success or nil on failure.

func LoadFont

func LoadFont(name string, fontBytes []byte, scaleInt int, glyphs string) (*Font, error)

func NewFont

func NewFont(name string, fontFilepath string, scaleInt int, glyphs string) (*Font, error)

NewFont loads the font from a file and 'registers' it with the UI manager.

func (*Font) CreateText

func (f *Font) CreateText(pos mgl.Vec2, color mgl.Vec4, msg string) *RenderData

CreateText makes a new renderable object from the supplied string using the data in the font. The data is returned as a RenderData object.

func (*Font) CreateTextAdv

func (f *Font) CreateTextAdv(pos mgl.Vec2, color mgl.Vec4, maxWidth float32, charOffset int, cursorPosition int, s string) *RenderData

CreateText makes a new renderable object from the supplied string using the data in the font. The string returned will be the maximum amount of the msg that fits the specified maxWidth (if greater than 0.0) starting at the charOffset specified. The data is returned as a RenderData object.

func (*Font) Destroy

func (f *Font) Destroy()

Destroy releases the OpenGL texture for the font.

func (*Font) GetCurrentScale

func (f *Font) GetCurrentScale() float32

GetCurrentScale returns the scale value for the font based on the current Manager's resolution vs the resolution the UI was designed for.

func (*Font) GetRenderSize

func (f *Font) GetRenderSize(s string) (float32, float32, float32)

GetRenderSize returns the width and height necessary in pixels for the font to display a string. The third return value is the advance height the string.

func (*Font) OffsetFloor

func (f *Font) OffsetFloor(msg string, offset float32) float32

OffsetFloor returns the maximum width offset that will fit between characters that is still smaller than the offset passed in.

func (*Font) OffsetForIndex

func (f *Font) OffsetForIndex(msg string, stopIndex int) float32

OffsetForIndex returns the width offset that will fit just before the `stopIndex` number character in the msg.

func (*Font) OffsetForIndexAdv

func (f *Font) OffsetForIndexAdv(msg string, charStartIndex int, stopIndex int) float32

OffsetForIndexAdv returns the width offset that will fit just before the `stopIndex` number character in the msg, starting at charStartIndex.

type HAlign

type HAlign int

type KeyEvent

type KeyEvent struct {
	KeyCode glfw.Key

	Shift bool
	Ctrl  bool
	Alt   bool
	Super bool
}

KeyEvent contains keyCode, rune and pressed key modifiers

type Layout

type Layout struct {
	HAlign HAlign
	VAlign VAlign

	PositionFixed bool
	Square        bool

	//value fot position content into this layout
	X float32 //content X
	Y float32 //content Y
	W float32 //max content width
	H float32 //max content height

	Padding Offset
	Margin  Offset
	// contains filtered or unexported fields
}

Layout is reresentation of object size position and other options

func NewLayout

func NewLayout(x, y, w, h string, parent *Layout) *Layout

func NewLayoutZero

func NewLayoutZero(parent *Layout) *Layout

func (*Layout) AddOffsets

func (l *Layout) AddOffsets(w, h float32) (float32, float32)

func (*Layout) ContainsPoint

func (l *Layout) ContainsPoint(x, y float32) bool

func (*Layout) GetBackgroundRect

func (l *Layout) GetBackgroundRect() (r Rect)

func (*Layout) GetContentRect

func (l *Layout) GetContentRect() (r Rect)

func (*Layout) GetTextPosCenter

func (l *Layout) GetTextPosCenter(w, h float32) (textPos mgl32.Vec2)

func (*Layout) GetTextPosLeft

func (l *Layout) GetTextPosLeft(h float32) (textPos mgl32.Vec2)

func (*Layout) GetTextPosRight

func (l *Layout) GetTextPosRight(w, h float32) (textPos mgl32.Vec2)

func (*Layout) SetCursor

func (l *Layout) SetCursor(cursor *Cursor)

func (*Layout) SetHeight

func (l *Layout) SetHeight(val string)

func (*Layout) SetMaxSize

func (l *Layout) SetMaxSize(w, h float32)

func (*Layout) SetMinSize

func (l *Layout) SetMinSize(w, h float32)

SetMinSize it`s width and height if incoming value more then exists

func (*Layout) SetWidth

func (l *Layout) SetWidth(val string)

func (*Layout) SetX

func (l *Layout) SetX(val string)

func (*Layout) SetY

func (l *Layout) SetY(val string)

func (*Layout) SummOffsets

func (l *Layout) SummOffsets() (o Offset)

func (*Layout) Update

func (l *Layout) Update()

Update layout values, should be call each frame

type Offset

type Offset struct {
	L, T, R, B float32
}

Offset is alternative of slice mgl32.Vec4

func (Offset) Vec4

func (o Offset) Vec4() mgl32.Vec4

Vec4 - convert offset to mgl32.Vec4

type Rect

type Rect struct {
	TLX float32
	TLY float32
	BRX float32
	BRY float32

	W float32
	H float32
}

type RenderData

type RenderData struct {
	ComboBuffer         []float32 // the combo VBO data (vert/uv/color)
	IndexBuffer         []uint32  // the element index VBO data
	Faces               uint32    // the number of faces in the text string
	Width               float32   // the width in pixels of the text string
	Height              float32   // the height in pixels of the text string
	AdvanceHeight       float32   // the amount of pixels to move the pen in the verticle direction
	CursorOverflowRight bool      // whether or not the cursor was too far to the right for string width
}

RenderData is a structure containing the raw OpenGL VBO data needed to render a text string for a given texture.

type STATE

type STATE int
const (
	STATE_NORMAL STATE = iota
	STATE_ACTIVE
	STATE_CHECKED
)

type Size

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

Size contains universial reresentation for fixed and percent sizes

func NewSize

func NewSize(val string, min, max float32) (s Size)

NewSize return Size object contains value(ex:"100%","50px",etc) and potiner on maxValue for calculate percent value

type Style

type Style struct {
	TextColor       mgl32.Vec4
	BackgroundColor mgl32.Vec4

	BorderColor mgl32.Vec4
	BorderWidth float32

	Texture *Texture
	// contains filtered or unexported fields
}
var (
	DefaultContainerStyle Style
	DefaultTextStyle      Style

	DefaultBtnStyle       Style
	DefaultBtnStyleHover  Style
	DefaultBtnStyleActive Style

	DefaultInputStyle       Style
	DefaultInputStyleActive Style

	DefaultDaDItemStyle      Style
	DefaultDaDItemStyleHover Style
)

Default styles

func NewStyle

func NewStyle(textColor, bgColor, borderColor mgl32.Vec4, borderWidth float32) Style

func NewStyleTexture

func NewStyleTexture(tc *Texture, bgColor mgl32.Vec4) Style

type TALIGN

type TALIGN int
const (
	TALIGN_LEFT TALIGN = iota
	TALIGN_CENTER
	TALIGN_RIGHT
)

type Texture

type Texture struct {
	Tex    graphicsprovider.Texture
	Offset mgl32.Vec4
}

func NewTextureImg

func NewTextureImg(img string) (*Texture, error)

type TexturePack

type TexturePack struct {
	Width, Height float32
	Tex           graphicsprovider.Texture
}

func NewTexturePack

func NewTexturePack(img string) (*TexturePack, error)

func (*TexturePack) NewChunk

func (tp *TexturePack) NewChunk(x0, y0, x1, y1 float32) *Texture

type VAlign

type VAlign int

type Widget

type Widget struct {
	ID string

	Hidden bool

	Text      string
	TextAlign TALIGN
	Font      *Font

	Texture *Texture //Global widget texture

	Style       Style
	StyleHover  Style
	StyleActive Style

	State STATE

	Zorder uint8 //initial value
	Z      uint8 //current working value

	Layout    *Layout
	Container *Container

	OnActive   Callback
	OnKeyEnter Callback

	ConstructorData interface{}
	Constructor     WidgetConstructor

	UserData interface{}
	// contains filtered or unexported fields
}

func (*Widget) Destroy

func (wgt *Widget) Destroy()

func (*Widget) IsActive

func (wgt *Widget) IsActive() bool

func (*Widget) IsClick

func (wgt *Widget) IsClick() (click bool, onWidget bool)

func (*Widget) IsHover

func (wgt *Widget) IsHover() bool

func (*Widget) IsMouseDown

func (wgt *Widget) IsMouseDown() (down bool, onWidget bool)

func (*Widget) SetStyles

func (wgt *Widget) SetStyles(normal, hover, active Style, tex *Texture)

type WidgetConstructor

type WidgetConstructor func() Style

Directories

Path Synopsis
examples
new

Jump to

Keyboard shortcuts

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