gui

package
v0.0.0-...-944e809 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gui provide the graphic user interface.

the standard coordinate system used by the gui package, is in pixel unit, the origin point (0, 0) is top left of the viewport, positive of x is right, positive of y is down, positive of z is toward the inner of screen. just like most of other GUI system in the world.

the z axis is typically useless in GUI, but it still a 3D system, can be embeded into the 3D scene in some situation.

    |/                 0 ---------- x+
  - 0 ------- x+       |
   /|                  |
  / |                  |
 /  z+                 |
y+                     y+

Index

Constants

View Source
const (
	// HintResizable is int for window has resize box
	HintResizable = winl.HintResizable

	// HintVideo is hint for window with animated (FPS video) content
	HintVideo = winl.HintVideo

	// HintPainter is hint for 2d drawing using painter algorithm
	HintPainter = winl.HintPainter
)

Variables

View Source
var (
	ErrWrongType = errors.New("Wrong type")
	ErrBadParams = errors.New("Bad params")
)

Errors

Functions

func FactoryRegister

func FactoryRegister()

FactoryRegister register creator in factory for package gui

Types

type Button

type Button struct {
	Widget
	// contains filtered or unexported fields
}

Button is button widget

func NewButton

func NewButton() *Button

NewButton create and init new Button object.

func (*Button) Class

func (p *Button) Class() string

Class name for factory

func (*Button) Font

func (btn *Button) Font() glman.Font

Font returns current font

func (*Button) Render

func (btn *Button) Render()

Render the element

func (*Button) SetFont

func (btn *Button) SetFont(f glman.Font)

SetFont set the font

func (*Button) SetText

func (btn *Button) SetText(s string)

SetText set the text label on the button

func (*Button) Text

func (btn *Button) Text() string

Text label on the button

type Color

type Color = glman.Color

Color type

type Elem

type Elem struct {
	Self interface{}
	// contains filtered or unexported fields
}

Elem class is abstract gui element

func NewElem

func NewElem() *Elem

NewElem create and init new Elem object.

func (*Elem) Bounds

func (el *Elem) Bounds() Rect

Bounds reports bounds rect of the element

func (*Elem) BoundsGLCoord

func (el *Elem) BoundsGLCoord() (rc Rect)

BoundsGLCoord reports bounds rect of the element, in OpenGL (Y-UP) coordinate.

func (*Elem) Children

func (el *Elem) Children() []IElem

Children returns child elements

func (*Elem) Class

func (p *Elem) Class() string

Class name for factory

func (*Elem) Index

func (el *Elem) Index(x IElem) int

Index of x

func (*Elem) Init

func (el *Elem) Init()

Init a new object

func (*Elem) Insert

func (el *Elem) Insert(i int, x IElem)

Insert x at index i, if i < 0 then append to the end

func (*Elem) Parent

func (el *Elem) Parent() IElem

Parent returns parent element

func (*Elem) Remove

func (el *Elem) Remove(i int) IElem

Remove child at index i

func (*Elem) RemoveAll

func (el *Elem) RemoveAll()

RemoveAll remove all children

func (*Elem) Render

func (el *Elem) Render()

Render the element

func (*Elem) SetBounds

func (el *Elem) SetBounds(rect Rect)

SetBounds set the bounds rect of the element

func (*Elem) SetParent

func (el *Elem) SetParent(p IElem)

SetParent set parent element

func (*Elem) SetWindow

func (el *Elem) SetWindow(w IWindow)

SetWindow set the owner window

func (*Elem) Window

func (el *Elem) Window() IWindow

Window reports the owner window

type IButton

type IButton interface {
	IWidget
	// Font returns current font
	Font() glman.Font
	// SetFont set the font
	SetFont(f glman.Font)
	// SetText set the text label on the button
	SetText(s string)
	// Text label on the button
	Text() string
}

IButton is interface of class Button

type IElem

type IElem interface {
	// Bounds reports bounds rect of the element
	Bounds() Rect
	// BoundsGLCoord reports bounds rect of the element, in OpenGL (Y-UP) coordinate.
	BoundsGLCoord() Rect
	// Children returns child elements
	Children() []IElem
	// Class name for factory
	Class() string
	// Index of x
	Index(x IElem) int
	// Init a new object
	Init()
	// Insert x at index i, if i < 0 then append to the end
	Insert(i int, x IElem)
	// Parent returns parent element
	Parent() IElem
	// Remove child at index i
	Remove(i int) IElem
	// RemoveAll remove all children
	RemoveAll()
	// Render the element
	Render()
	// SetBounds set the bounds rect of the element
	SetBounds(rect Rect)
	// SetParent set parent element
	SetParent(p IElem)
	// SetWindow set the owner window
	SetWindow(w IWindow)
	// Window reports the owner window
	Window() IWindow
}

IElem is interface of class Elem

type IPane

type IPane interface {
	IWidget
	// Is3D reports whether pane is 3D scene
	Is3D() bool
	// SetState from string
	SetState(data []byte) error
	// State to string
	State() ([]byte, error)
}

IPane is interface of class Pane

type IPane3D

type IPane3D interface {
	IPane
	// Frustum set projection to special frustum
	Frustum(left float32, right float32, bottom float32, top float32, near float32, far float32)
	// LookAt set view matrix to look at special point
	LookAt(eye Vec3, lookAt Vec3, up Vec3)
	// Ortho set projection to orthographic
	Ortho(xMin float32, xMax float32, yMin float32, yMax float32, zMin float32, zMax float32)
	// Perspective set projection to perspective
	Perspective(fovy float32, aspect float32, near float32, far float32)
}

IPane3D is interface of class Pane3D

type ITestPane

type ITestPane interface {
	IPane
}

ITestPane is interface of class TestPane

type ITestPane3D

type ITestPane3D interface {
	IPane3D
}

ITestPane3D is interface of class TestPane3D

type IWidget

type IWidget interface {
	IElem
}

IWidget is interface of class Widget

type IWindow

type IWindow interface {
	winl.IWindow
	// Layout return current split layout
	Layout() *WndLayout
	// ObjID returns the object id
	ObjID() string
	// OnSkin handle the skin change event
	OnSkin()
	// Render the scene
	Render()
	// SetLayout set the split layout
	SetLayout(wl *WndLayout) error
	// SetObjID set the object id
	SetObjID(id string)
	// SetState from string
	SetState(data []byte) error
	// State to string
	State() ([]byte, error)
}

IWindow is interface of class Window

type Mat4

type Mat4 = geom.Mat4

Mat4 type

type Pane

type Pane struct {
	Widget
}

Pane is compound widget typically use as split area in window.

func NewPane

func NewPane() *Pane

NewPane create and init new Pane object.

func (*Pane) Class

func (p *Pane) Class() string

Class name for factory

func (*Pane) Is3D

func (pn *Pane) Is3D() bool

Is3D reports whether pane is 3D scene

func (*Pane) SetState

func (pn *Pane) SetState(data []byte) error

SetState from string

func (*Pane) State

func (pn *Pane) State() ([]byte, error)

State to string

type Pane3D

type Pane3D struct {
	Pane
	MatP geom.Mat4
	MatV geom.Mat4
}

Pane3D is a pane for 3D scene

func NewPane3D

func NewPane3D() *Pane3D

NewPane3D create and init new Pane3D object.

func (*Pane3D) Class

func (p *Pane3D) Class() string

Class name for factory

func (*Pane3D) Frustum

func (pn *Pane3D) Frustum(left float32, right float32, bottom float32, top float32, near float32, far float32)

Frustum set projection to special frustum

func (*Pane3D) Init

func (pn *Pane3D) Init()

Init a new object

func (*Pane3D) Is3D

func (pn *Pane3D) Is3D() bool

Is3D reports whether pane is 3D scene

func (*Pane3D) LookAt

func (pn *Pane3D) LookAt(eye Vec3, lookAt Vec3, up Vec3)

LookAt set view matrix to look at special point

func (*Pane3D) Ortho

func (pn *Pane3D) Ortho(xMin float32, xMax float32, yMin float32, yMax float32, zMin float32, zMax float32)

Ortho set projection to orthographic

func (*Pane3D) Perspective

func (pn *Pane3D) Perspective(fovy float32, aspect float32, near float32, far float32)

Perspective set projection to perspective

func (*Pane3D) Render

func (pn *Pane3D) Render()

Render the pane

func (*Pane3D) SetState

func (pn *Pane3D) SetState(data []byte) error

SetState from string

func (*Pane3D) State

func (pn *Pane3D) State() ([]byte, error)

State to string

type Rect

type Rect = geom.Rect

Rect type

type TestPane

type TestPane struct {
	Pane
	// contains filtered or unexported fields
}

TestPane is a pane for testing

func NewTestPane

func NewTestPane() *TestPane

NewTestPane create and init new TestPane object.

func (*TestPane) Class

func (p *TestPane) Class() string

Class name for factory

func (*TestPane) Init

func (pn *TestPane) Init()

Init a new object

func (*TestPane) SetState

func (pn *TestPane) SetState(data []byte) error

SetState from string

func (*TestPane) State

func (pn *TestPane) State() ([]byte, error)

State to string

type TestPane3D

type TestPane3D struct {
	Pane3D
}

TestPane3D is a pane for 3D scene

func NewTestPane3D

func NewTestPane3D() *TestPane3D

NewTestPane3D create and init new TestPane3D object.

func (*TestPane3D) Class

func (p *TestPane3D) Class() string

Class name for factory

func (*TestPane3D) Init

func (pn *TestPane3D) Init()

Init a new object

func (*TestPane3D) SetState

func (pn *TestPane3D) SetState(data []byte) error

SetState from string

func (*TestPane3D) State

func (pn *TestPane3D) State() ([]byte, error)

State to string

type Vec2

type Vec2 = geom.Vec2

Vec2 type

type Vec3

type Vec3 = geom.Vec3

Vec3 type

type Vec4

type Vec4 = geom.Vec4

Vec4 type

type Widget

type Widget struct {
	Elem
}

Widget is gui control which can handle user input.

func NewWidget

func NewWidget() *Widget

NewWidget create and init new Widget object.

func (*Widget) Class

func (p *Widget) Class() string

Class name for factory

type Window

type Window struct {

	// Window is underlying winl.Window
	winl.Window // super
	// contains filtered or unexported fields
}

Window class wrap operating systems's window object.

func NewWindow

func NewWindow() *Window

NewWindow create and init new Window object.

func (*Window) Class

func (p *Window) Class() string

Class name for factory

func (*Window) Layout

func (w *Window) Layout() *WndLayout

Layout return current split layout

func (*Window) ObjID

func (w *Window) ObjID() string

ObjID returns the object id

func (*Window) OnCreate

func (w *Window) OnCreate()

OnCreate event handler

func (*Window) OnDestroy

func (w *Window) OnDestroy()

OnDestroy event handler

func (*Window) OnExpose

func (w *Window) OnExpose(x, y, width, height float32)

OnExpose event handler

func (*Window) OnMouseEnter

func (w *Window) OnMouseEnter(x, y float32)

OnMouseEnter event handler

func (*Window) OnMouseLeave

func (w *Window) OnMouseLeave(x, y float32)

OnMouseLeave event handler

func (*Window) OnMouseMove

func (w *Window) OnMouseMove(x, y float32)

OnMouseMove event handler

func (*Window) OnMousePress

func (w *Window) OnMousePress(btn int, x, y float32)

OnMousePress event handler

func (*Window) OnMouseRelease

func (w *Window) OnMouseRelease(btn int, x, y float32)

OnMouseRelease event handler

func (*Window) OnMouseWheel

func (w *Window) OnMouseWheel(vert bool, dz float32)

OnMouseWheel event handler

func (*Window) OnResize

func (w *Window) OnResize(width, height float32)

OnResize event handler

func (*Window) OnSkin

func (w *Window) OnSkin()

OnSkin handle the skin change event

func (*Window) Render

func (w *Window) Render()

Render the scene

func (*Window) SetLayout

func (w *Window) SetLayout(wl *WndLayout) error

SetLayout set the split layout

func (*Window) SetObjID

func (w *Window) SetObjID(id string)

SetObjID set the object id

func (*Window) SetState

func (w *Window) SetState(data []byte) error

SetState from string

func (*Window) State

func (w *Window) State() ([]byte, error)

State to string

type WndLayout

type WndLayout struct {
	Vert  bool    `json:"vert,omitempty"`  // split direction
	Sp    float32 `json:"split,omitempty"` // split position
	Pane  IPane   `json:"-"`               // associated pane
	Class string  `json:"class,omitempty"` // pane' class
	Param string  `json:"param,omitempty"` // params for create pane

	L *WndLayout `json:"left,omitempty"`  // left or top child
	R *WndLayout `json:"right,omitempty"` // right or bottom child
	// contains filtered or unexported fields
}

WndLayout is tree structure split window into multipile panes

func (*WndLayout) CalcLayout

func (wl *WndLayout) CalcLayout(ss float32)

CalcLayout recursive calc wl.rc, and set to wl.Pane if any

func (*WndLayout) IsLeaf

func (wl *WndLayout) IsLeaf() bool

IsLeaf report whether wl is leaf node

func (*WndLayout) Render

func (wl *WndLayout) Render(filter func(IPane) bool)

Render the layout tree

func (*WndLayout) SetState

func (wl *WndLayout) SetState(data []byte) error

SetState from string

func (*WndLayout) State

func (wl *WndLayout) State() ([]byte, error)

State to string

Jump to

Keyboard shortcuts

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