draw2dui

package module
v0.0.0-...-328342c Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2016 License: BSD-2-Clause Imports: 4 Imported by: 0

README

draw2dui

GoDoc

**NOTICE** This library is very young, and may be subject to API breaking changes. It should stabilize within the next few weeks. **NOTICE**

Package draw2dui offers useful tools for drawing and handling UIs in Golang using draw2d with OpenGL.

Installation

Install golang. To install or update the package draw2dui on your system, run:

go get -u github.com/redstarcoder/draw2dui

Building

These are instructions for building on Linux. This library should be able to compile on whatever you can make gl and glfw compile on though.

Target: Linux

go build

Target: Windows

First install mingw, then run something like this:

CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows go build

Acknowledgments

Documentation

Overview

Copyright (c) 2016, redstarcoder Package draw2dui offers useful tools for drawing and handling UIs in Golang using draw2d with OpenGL.

Copyright (c) 2016, redstarcoder

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NameWidget

func NameWidget(w string) string

NameWidget returns a unique widget name. It is thread-safe.

Types

type Event

type Event int

Event is for widget events

const (
	// EventNone means the widget returned normally
	EventNone Event = iota
	// EventNext means the next widget should be selected
	EventNext
	// EventPrevious means the previous widget should be sekected
	EventPrevious
	// EventExit means the widget or the application should be closed
	EventExit
	// EventConfirm means the user has confirmed an action (typically they hit enter)
	EventConfirm
	// EventAction means the user modified the widget in some way (changed a dropdown, changed text)
	EventAction
	// EventSelect means the widget was selected
	EventSelected
	// EventHasCursor means the widget currently controls the cursor
	EventHasCursor
)

type Widget

type Widget interface {
	// Name returns the widget's name
	Name() string
	// Draw draws the widget, selected determines if the widget displays as selected or not, and forceRedraw
	// forces a full redraw of the widget.
	Draw(selected, forceRedraw bool)
	// Handle processes the widget's idle actions, selected determines if the widget behaves as selected or
	// not. Returns if it needs a draw or not.
	Handle(selected bool) bool
	// KeyPress has the widget process a KeyPress event
	KeyPress(key glfw.Key, action glfw.Action, mods glfw.ModifierKey) Event
	// CharPress has the widget process a character
	CharPress(char rune) Event
	// MMove has the widget process a MouseMove event
	MMove(xpos, ypos float64) Event
	// MClick has the widget process a MouseClick event
	MClick(xpos, ypos float64, button glfw.MouseButton, action glfw.Action, mods glfw.ModifierKey) Event
	// SetPos changes the widget's x, y coordinates
	SetPos(x, y float64)
	// GetPos retrieves the widget's x, y coordinates
	GetPos() (float64, float64)
	// SetDimensions changes the widget's width and height
	SetDimensions(w, h float64)
	// GetDimensions returns the widget's width and height
	GetDimensions() (float64, float64)
	// IsInside checks if point x, y is inside of the widget's boundaries
	IsInside(x, y float64) bool
	// SetString sets the widget's string, if it supports it
	SetString(s string)
	// GetString returns a string, if the widget supports it
	GetString() string
	// SetInt sets the widget's int, if it supports it
	SetInt(i int)
	// GetInt returns an int, if the widget supports it
	GetInt() int
	// SetData sets the widget's data if it supports it. This must be a type supported by the widget.
	SetData(d interface{})
	// GetData returns an interface{}, if the widget supports it
	GetData() interface{}
	// SetEnabled enables or disables the widget
	SetEnabled(enabled bool)
	// GetEnabled returns whether the widget is enabled or not
	GetEnabled() bool
}

Widget is an interface for draw2dui widgets

type WidgetCollection

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

WidgetCollection is a struct for managing many widgets at once. It has many helper methods for handling mouse and keyboard events.

func NewWidgetCollection

func NewWidgetCollection(gc *draw2d.GraphicContext, window *glfw.Window, widgets ...Widget) *WidgetCollection

NewWidgetCollection creates a new widget collection and registers all the widgets

func (*WidgetCollection) CharPress

func (wc *WidgetCollection) CharPress(char rune) (Widget, Event)

CharPress has the selected widget process a character, returning the selected widget and the event if it isn't EventNone.

func (*WidgetCollection) Draw

func (wc *WidgetCollection) Draw()

Draw draws all the widgets to the screen

func (*WidgetCollection) Handle

func (wc *WidgetCollection) Handle() (redraw bool)

Handle processes all the idle events for every widget in the collection. Returns whether it requests a call to WidgetCollection.Draw or not.

func (*WidgetCollection) KeyPress

func (wc *WidgetCollection) KeyPress(key glfw.Key, action glfw.Action, mods glfw.ModifierKey) (Widget, Event)

KeyPress has the selected widget process a KeyPress event, returning the selected widget and the event if it isn't EventNone.

func (*WidgetCollection) MClick

func (wc *WidgetCollection) MClick(button glfw.MouseButton, action glfw.Action, mods glfw.ModifierKey) (Widget, Event)

MClick has the all widgets in the collection process a MouseClick event, returning the a widget and event if it isn't EventNone.

func (*WidgetCollection) MMove

func (wc *WidgetCollection) MMove(xpos, ypos float64) (widget Widget, event Event)

MMove has all the widgets in the collection process a MouseMove event, returning the a widget and event if the cursor changes. Always returns the moused-over widget, unless there isn't one, then it returns a widget that returned EventAction, if any.

func (*WidgetCollection) Refresh

func (wc *WidgetCollection) Refresh()

Refresh should be called when a window refresh occurs (See: glfw.RefreshCallback)

func (*WidgetCollection) Register

func (wc *WidgetCollection) Register(widget Widget)

Register adds a widget to the collection

func (*WidgetCollection) Reshape

func (wc *WidgetCollection) Reshape(w, h int)

Reshape should be called whenever the draw2d.GraphicContext is resized TODO handle w & h

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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