Documentation ¶
Index ¶
- Constants
- func InitWidget(parent Widget, w Widget)
- func LoadTTF(path string, size float64) (font.Face, error)
- func PrintWidgets(w Widget, indent string)
- func RGB(r, g, b float64) color.Color
- func RGBA(r, g, b, a float64) color.Color
- type Align
- type Base
- type Button
- type Charset
- type ImageSheetConfig
- type Interactive
- type Panel
- func (p *Panel) Close()
- func (p *Panel) DrawImageAndText(textColor color.Color)
- func (p *Panel) Equals(w Widget) bool
- func (p *Panel) Foster(ch Widget)
- func (p *Panel) GetPanel() *Panel
- func (p *Panel) GlobalRect() (r Rect)
- func (p *Panel) MyTheme() *Theme
- func (p *Panel) Paint()
- func (p *Panel) Place(rel Vec)
- func (p *Panel) ProcessKeys()
- func (p *Panel) ProcessMouse(wu Widget)
- func (p *Panel) Render()
- func (p *Panel) WidgetUnder(pos Vec) Widget
- type PlainRect
- type PushButton
- type Rect
- func (r Rect) AlignToPoint(dst Vec, al Align) Vec
- func (r Rect) AlignToRect(dst Rect, al Align) Vec
- func (r Rect) Center() Vec
- func (r Rect) Contains(u Vec) bool
- func (r Rect) Expanded(d float64) Rect
- func (r Rect) Extended(left, bottom, right, top float64) Rect
- func (r Rect) H() float64
- func (r Rect) Moved(delta Vec) Rect
- func (r Rect) Size() Vec
- func (r Rect) W() float64
- type SheetConfig
- type Surface
- type SurfaceConfig
- type TexturedPanel
- type Theme
- type ThemeDrawer
- type ThemeDrawerKey
- type Vec
- type Widget
Constants ¶
const ( MouseButton1 = Button(pixelgl.MouseButton1) MouseButton2 = Button(pixelgl.MouseButton2) MouseButton3 = Button(pixelgl.MouseButton3) MouseButton4 = Button(pixelgl.MouseButton4) MouseButton5 = Button(pixelgl.MouseButton5) MouseButton6 = Button(pixelgl.MouseButton6) MouseButton7 = Button(pixelgl.MouseButton7) MouseButton8 = Button(pixelgl.MouseButton8) MouseButtonLast = Button(pixelgl.MouseButtonLast) MouseButtonLeft = Button(pixelgl.MouseButtonLeft) MouseButtonRight = Button(pixelgl.MouseButtonRight) MouseButtonMiddle = Button(pixelgl.MouseButtonMiddle) )
List of all mouse buttons.
const ( KeyUnknown = Button(pixelgl.KeyUnknown) KeySpace = Button(pixelgl.KeySpace) KeyApostrophe = Button(pixelgl.KeyApostrophe) KeyComma = Button(pixelgl.KeyComma) KeyMinus = Button(pixelgl.KeyMinus) KeyPeriod = Button(pixelgl.KeyPeriod) KeySlash = Button(pixelgl.KeySlash) Key0 = Button(pixelgl.Key0) Key1 = Button(pixelgl.Key1) Key2 = Button(pixelgl.Key2) Key3 = Button(pixelgl.Key3) Key4 = Button(pixelgl.Key4) Key5 = Button(pixelgl.Key5) Key6 = Button(pixelgl.Key6) Key7 = Button(pixelgl.Key7) Key8 = Button(pixelgl.Key8) Key9 = Button(pixelgl.Key9) KeySemicolon = Button(pixelgl.KeySemicolon) KeyEqual = Button(pixelgl.KeyEqual) KeyA = Button(pixelgl.KeyA) KeyB = Button(pixelgl.KeyB) KeyC = Button(pixelgl.KeyC) KeyD = Button(pixelgl.KeyD) KeyE = Button(pixelgl.KeyE) KeyF = Button(pixelgl.KeyF) KeyG = Button(pixelgl.KeyG) KeyH = Button(pixelgl.KeyH) KeyI = Button(pixelgl.KeyI) KeyJ = Button(pixelgl.KeyJ) KeyK = Button(pixelgl.KeyK) KeyL = Button(pixelgl.KeyL) KeyM = Button(pixelgl.KeyM) KeyN = Button(pixelgl.KeyN) KeyO = Button(pixelgl.KeyO) KeyP = Button(pixelgl.KeyP) KeyQ = Button(pixelgl.KeyQ) KeyR = Button(pixelgl.KeyR) KeyS = Button(pixelgl.KeyS) KeyT = Button(pixelgl.KeyT) KeyU = Button(pixelgl.KeyU) KeyV = Button(pixelgl.KeyV) KeyW = Button(pixelgl.KeyW) KeyX = Button(pixelgl.KeyX) KeyY = Button(pixelgl.KeyY) KeyZ = Button(pixelgl.KeyZ) KeyLeftBracket = Button(pixelgl.KeyLeftBracket) KeyBackslash = Button(pixelgl.KeyBackslash) KeyRightBracket = Button(pixelgl.KeyRightBracket) KeyGraveAccent = Button(pixelgl.KeyGraveAccent) KeyWorld1 = Button(pixelgl.KeyWorld1) KeyWorld2 = Button(pixelgl.KeyWorld2) KeyEscape = Button(pixelgl.KeyEscape) KeyEnter = Button(pixelgl.KeyEnter) KeyTab = Button(pixelgl.KeyTab) KeyBackspace = Button(pixelgl.KeyBackspace) KeyInsert = Button(pixelgl.KeyInsert) KeyDelete = Button(pixelgl.KeyDelete) KeyRight = Button(pixelgl.KeyRight) KeyLeft = Button(pixelgl.KeyLeft) KeyDown = Button(pixelgl.KeyDown) KeyUp = Button(pixelgl.KeyUp) KeyPageUp = Button(pixelgl.KeyPageUp) KeyPageDown = Button(pixelgl.KeyPageDown) KeyHome = Button(pixelgl.KeyHome) KeyEnd = Button(pixelgl.KeyEnd) KeyCapsLock = Button(pixelgl.KeyCapsLock) KeyScrollLock = Button(pixelgl.KeyScrollLock) KeyNumLock = Button(pixelgl.KeyNumLock) KeyPrintScreen = Button(pixelgl.KeyPrintScreen) KeyPause = Button(pixelgl.KeyPause) KeyF1 = Button(pixelgl.KeyF1) KeyF2 = Button(pixelgl.KeyF2) KeyF3 = Button(pixelgl.KeyF3) KeyF4 = Button(pixelgl.KeyF4) KeyF5 = Button(pixelgl.KeyF5) KeyF6 = Button(pixelgl.KeyF6) KeyF7 = Button(pixelgl.KeyF7) KeyF8 = Button(pixelgl.KeyF8) KeyF9 = Button(pixelgl.KeyF9) KeyF10 = Button(pixelgl.KeyF10) KeyF11 = Button(pixelgl.KeyF11) KeyF12 = Button(pixelgl.KeyF12) KeyF13 = Button(pixelgl.KeyF13) KeyF14 = Button(pixelgl.KeyF14) KeyF15 = Button(pixelgl.KeyF15) KeyF16 = Button(pixelgl.KeyF16) KeyF17 = Button(pixelgl.KeyF17) KeyF18 = Button(pixelgl.KeyF18) KeyF19 = Button(pixelgl.KeyF19) KeyF20 = Button(pixelgl.KeyF20) KeyF21 = Button(pixelgl.KeyF21) KeyF22 = Button(pixelgl.KeyF22) KeyF23 = Button(pixelgl.KeyF23) KeyF24 = Button(pixelgl.KeyF24) KeyF25 = Button(pixelgl.KeyF25) KeyKP0 = Button(pixelgl.KeyKP0) KeyKP1 = Button(pixelgl.KeyKP1) KeyKP2 = Button(pixelgl.KeyKP2) KeyKP3 = Button(pixelgl.KeyKP3) KeyKP4 = Button(pixelgl.KeyKP4) KeyKP5 = Button(pixelgl.KeyKP5) KeyKP6 = Button(pixelgl.KeyKP6) KeyKP7 = Button(pixelgl.KeyKP7) KeyKP8 = Button(pixelgl.KeyKP8) KeyKP9 = Button(pixelgl.KeyKP9) KeyKPDecimal = Button(pixelgl.KeyKPDecimal) KeyKPDivide = Button(pixelgl.KeyKPDivide) KeyKPMultiply = Button(pixelgl.KeyKPMultiply) KeyKPSubtract = Button(pixelgl.KeyKPSubtract) KeyKPAdd = Button(pixelgl.KeyKPAdd) KeyKPEnter = Button(pixelgl.KeyKPEnter) KeyKPEqual = Button(pixelgl.KeyKPEqual) KeyLeftShift = Button(pixelgl.KeyLeftShift) KeyLeftControl = Button(pixelgl.KeyLeftControl) KeyLeftAlt = Button(pixelgl.KeyLeftAlt) KeyLeftSuper = Button(pixelgl.KeyLeftSuper) KeyRightShift = Button(pixelgl.KeyRightShift) KeyRightControl = Button(pixelgl.KeyRightControl) KeyRightAlt = Button(pixelgl.KeyRightAlt) KeyRightSuper = Button(pixelgl.KeyRightSuper) KeyMenu = Button(pixelgl.KeyMenu) KeyLast = Button(pixelgl.KeyLast) )
List of all keyboard buttons.
Variables ¶
This section is empty.
Functions ¶
func InitWidget ¶ added in v0.0.2
InitWidget initializes specific Widget behavior which must be repeated in all panel descendants by actual type: - sets up virtual; - attaches widget to parent; - derives surface.
func PrintWidgets ¶ added in v0.0.2
PrintWidgets prints a tree of widgets for debugging.
Types ¶
type Align ¶ added in v0.0.2
type Align int
Align defines object alignment relative to parent.
const ( // AlignDefault is default align (center in most cases) AlignDefault Align = 0 // AlignLeft ... AlignLeft Align = 1 // AlignRight ... AlignRight Align = 2 // AlignTop ... AlignTop Align = 3 // AlignBottom ... AlignBottom Align = 4 // AlignTopLeft ... AlignTopLeft Align = 5 // AlignTopRight ... AlignTopRight Align = 6 // AlignBottomLeft ... AlignBottomLeft Align = 7 // AlignBottomRight ... AlignBottomRight Align = 8 // AlignCenter is explicit center alignment AlignCenter Align = 10 )
type Base ¶
type Base struct { Theme *Theme Rect Rect Text string TextAlign Align Tooltip string Disabled bool Image string ImageAlign Align // If true, widget is invisible (but children are). // OnDraw is still called and can paint. Phantom bool }
Base is collection of initializable fields for widget.
type Button ¶
type Button int
Button is button or key code. This is equal to pixelgl (and GLFW) codes.
type Charset ¶ added in v0.0.2
type Charset struct { }
Charset represents character set for use in fonts
type ImageSheetConfig ¶ added in v0.0.2
type ImageSheetConfig struct { // Either atlas or file should be set. // If atlas is nil, file is used as filename to load image. Atlas image.Image // File is the name of the image file to load. File string `json:"file"` // Sheets containing continuous line of uniform sized subimages. Sheets []SheetConfig `json:"sheets"` }
ImageSheetConfig contains configuration for sheets containing subimages (sprites). OpenGL allows limited number of textures to be loaded into videocard memory. Because of that, images are loaded as atlases -- a big texture containing a lot of subimages. Sheet is a continous line of images of same width and height within atlas. Atlas can hold multiple sheets.
func LoadImages ¶ added in v0.0.2
func LoadImages(configFileName string) (ImageSheetConfig, error)
LoadImages loads JSON images config file and image it refers. See theme JSON files for example.
type Interactive ¶
type Interactive struct { OnMouseIn func() OnMouseOut func() OnMouseMove func() OnMouseDown func(button Button) OnMouseUp func(button Button) OnMouseClick func(button Button) OnMouseWheel func() OnKeys func() bool }
Interactive is entity that responds to input (mouse or keyboard).
type Panel ¶
type Panel struct { Parent Widget Children []Widget // Virt is interface by which virtual calls can be made, // i. e. this panel might be embedded to button, then // Render calls panel's version, but virt.Render will call // button's one. // Of course, every embedding type must assign itself // to virt to make this work. // WARNING: Virt is required to be used in place of // Widget interface values in any of Panel and // it's derivative types methods. Otherwise "slicing" will // happen and Widget will be in fact Panel (or the type that // used pointer to self when creating value of Widget type) // instead of derivative type. This may have some side-effects, // although comparision is already handled by Equals method. Virt Widget // Base is panel's base. Base // True if pointer is inside the widget PointerInside bool // Interactive provides response to input events. Interactive // Custom drawing function. Called from Paint. OnDraw func() // Graphics surface. Surface Surface }
Panel is simple widget with background color and border. It can contain text and/or image.
func (*Panel) DrawImageAndText ¶ added in v0.0.2
DrawImageAndText draws image and/or text according to alignment.
func (*Panel) Equals ¶ added in v0.0.2
Equals checks if panel and passed widget are both the same object
func (*Panel) Foster ¶
Foster reconnects widget to this parent, removing it from previous parent if needed.
func (*Panel) GlobalRect ¶
GlobalRect is absolute widget rectangle (screen coords).
func (*Panel) Place ¶
Place moves Widget to position relative to it's parent. Positive numbers set position relative to left/bottom edges of parent. Negative -- to right/top.
func (*Panel) ProcessKeys ¶
func (p *Panel) ProcessKeys()
ProcessKeys calls keyboard handlers on the widget hierarchy. If any widget reports, that key is processed, event propagation stops.
func (*Panel) ProcessMouse ¶
ProcessMouse generates mouse events based on change in mouse coords. wu holds top widget under mouse.
func (*Panel) WidgetUnder ¶ added in v0.0.2
WidgetUnder finds widget that is under given pointer coordinates
type PlainRect ¶ added in v0.0.2
type PlainRect struct { BackColor color.Color BorderSize float64 BorderInset float64 BorderColor color.Color }
PlainRect draws plain rectangle with optional color.
type PushButton ¶
PushButton is pressable and optionally, checkable (TODO), button.
func NewPushButton ¶
func NewPushButton(parent Widget, b Base) *PushButton
NewPushButton creates new button.
func (*PushButton) Paint ¶ added in v0.0.2
func (pb *PushButton) Paint()
Paint draws the widget without children.
type Rect ¶
type Rect struct {
Min, Max Vec
}
Rect describes rectangular area on surface.
func (Rect) AlignToPoint ¶ added in v0.0.2
AlignToPoint returns a Vec that src Rect have to be moved by in order to align relative to dst Point given alignments alh, alv.
func (Rect) AlignToRect ¶ added in v0.0.2
AlignToRect returns a Vec that src Rect have to be moved by in order to align relative to dst Rect given alignments alh, alv.
func (Rect) Contains ¶
Contains checks whether a vector u is contained within this Rect (including it's borders).
func (Rect) Expanded ¶
Expanded returns expanded rectangle by given distance in pixels. If d is negative, rectangle is shrunk instead.
func (Rect) Extended ¶ added in v0.0.2
Extended returns expanded rectangle by given distances in pixels. If distance is negative, rectangle is shrunk instead.
type SheetConfig ¶ added in v0.0.2
type SheetConfig struct { XOffset float64 `json:"x_offset"` YOffset float64 `json:"y_offset"` W float64 `json:"width"` H float64 `json:"height"` Names []string `json:"names"` }
SheetConfig is configuration for oine sheet
type Surface ¶
type Surface interface { // Run main loop (blocking) Run() // Set function to be called at every screen update. SetEvents(handler func()) // Get root widget to use as parent to other UI elements Root() Widget // Set current tooltip SetToolTip(tooltip string) // Show widget as popup. Popups are closed if mouse is // clicked outside of any popup widget, or // if escape is pressed. Mouse click that closed popup // is not otherwise processed. PopUp(w Widget) // Close popups added after this widget. // If passed nil, closes all popups. PopDownTo(w Widget) // Returns true, if there are any active popups. IsPopUpMode() bool // Returns true, if widget or any of its parents is popup. IsPopUp(w Widget) bool // PopUpUnder returns widget from popup list (if any), // if it's under pointer coords PopUpUnder(pos Vec) Widget // Draw functions DrawFillRect(r Rect, col color.Color) DrawRect(r Rect, col color.Color, thick float64) // Font is a font name that was previously initialized. // alh, alv -- horizontal and vertical text alignment (see Aling type) DrawText(msg, font string, r Rect, col color.Color, al Align) GetTextRect(msg, font string) Rect // Draws image centered around pos. DrawImage(name string, pos Vec, col color.Color) // Draws image aligned relative to rect. DrawImageAligned(name string, rect Rect, al Align, col color.Color) // Draw image into target rectangle. DrawImageStretched(name string, rect Rect, col color.Color) // Mouse & keyboard MousePos() Vec PrevMousePos() Vec ClickMousePos() Vec JustPressed(button Button) bool JustReleased(button Button) bool MouseScroll() Vec // Load and init TTF font that will be known under given name InitTTF(fontName, fileName string, size float64, charset Charset) error // Load and init images from sheet described by JSON file InitImages(configFileName string) error // Get size of the previously loaded image GetImageSize(name string) (Vec, error) // Init images from sheet described by config structure. // Images will be named as described in configuration. // DrawImage can be used with corresponding image names. // If JSON sheets configuration file exists, // you may want to use InitImages method. InitImageSheets(config ImageSheetConfig) error SetTheme(theme Theme) GetTheme() *Theme }
Surface is an interface representing surface (graphical layer) to draw on.
type SurfaceConfig ¶
type SurfaceConfig struct { // Window specific options -- only applicable // to primary surface. Title string WindowGeometry Rect IconFile string FPS int // Surface options PixelSize float64 BackColor color.Color }
SurfaceConfig contains configuration for surface.
type TexturedPanel ¶ added in v0.0.2
type TexturedPanel struct { // Prefix of image name for the parts of panel. // By adding -tl, -t, -tr, // -l, -c, -r, // -bl, -b, -br // to this, image name of the part is formed. ImagePrefix string // Use tiling instead of stretching for these parts: // l, r, c, t, b. TileHorizontal bool TileVertical bool // Set this to some color to tint texture. Color color.Color }
TexturedPanel contains info needed to draw texturized panel of arbitrary size.
func (TexturedPanel) Draw ¶ added in v0.0.2
func (tp TexturedPanel) Draw(s Surface, rect Rect)
Draw ...
type Theme ¶ added in v0.0.2
type Theme struct { // Font name used for titles (panels, buttons, etc) TitleFont string TooltipFont string TextColor color.Color DisabledTextColor color.Color TooltipColor color.Color // Pad to insert between border and text in autosized panels Pad float64 // Drawers Drawers map[ThemeDrawerKey]ThemeDrawer }
Theme contains info for rendering widgets
type ThemeDrawer ¶ added in v0.0.2
ThemeDrawer is interface to draw rectangular panels.
type ThemeDrawerKey ¶ added in v0.0.2
type ThemeDrawerKey string
ThemeDrawerKey is used to select appropriate drawer based on widget and it's flags
const ( ThemePanel ThemeDrawerKey = "p" ThemePanelDisabled ThemeDrawerKey = "p-d" ThemeButton ThemeDrawerKey = "b" ThemeButtonDisabled ThemeDrawerKey = "b-d" ThemeButtonHL ThemeDrawerKey = "b-h" ThemeButtonActive ThemeDrawerKey = "b-a" ThemeTooltip ThemeDrawerKey = "tip" )
type Vec ¶
type Vec struct {
X, Y float64
}
Vec decribes point or vector on surface.
type Widget ¶
type Widget interface { // This should be redefined in derived types Paint() // Panel implementation of these should be sufficient GetPanel() *Panel Equals(w Widget) bool Close() Foster(ch Widget) Render() ProcessMouse(wu Widget) ProcessKeys() WidgetUnder(pos Vec) Widget GlobalRect() Rect Place(rel Vec) // contains filtered or unexported methods }
Widget is an interface for widgets functionality. This is implemented by Panel type. Derived types must embed *Panel type to inherit this interface.