dynamic_gui_config

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

README

Dynamic Config for Go

This go package gives users the option to dynamically adjust variables in an graphical environment. It uses the andlabs ui library for showing the GUI.

Supported platforms

The package OS support is restricted only by its UI framework. In the future it might be possible to create an platform agnostic library such that multiple UI libraries can be used. For now only Windows and Linux on x86-64 are supported. On Windows, make sure cgo is supported.

Installation

Install the package by running:

go get github.com/timbeurskens/dynamic_gui_config

Usage

Examples can be found in the examples directory.

type ApplicationConfig struct {
	SomeFloatValue    float64 `uiconf:"{\"name\":\"float value:\",\"min\":0,\"max\":1,\"resolution\":100}"`
	SomeBool          bool
}

var Config = ApplicationConfig{
	SomeFloatValue: 0.5,
	SomeBool:       true,
}

func main() {
	config.Start("config", 640, 400)

	_ = config.Register("config", &Config)

	config.Show()

	ticker := time.NewTicker(time.Second)

	for range ticker.C {
		log.Println(Config)
	}
}

Supported types

Custom types

Known issues

Exit code -1073741511 (0xC0000139) on Windows

Solution: make sure to include a windows manifest file your application (e.g. import _ github.com/andlabs/ui/winmanifest)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hide

func Hide()

Hide hides the configuration window

func NewTab

func NewTab(name string, handle ValueControl)

NewTab creates a new tab in the configuration window

func Register

func Register(name string, config interface{}) error

Register adds the given struct pointer to the graphical interface as a new tab

func Show

func Show()

Show displays the configuration window

func Start

func Start(windowname string, width, height int)

Start starts the configuration thread and sets up the window handles it returns when setup is done and the handles are initialized

func StartDefaults

func StartDefaults()

StartDefaults is an alias for Start("config", 640, 400)

func Stop

func Stop()

Stop triggers the program to quit

Types

type CloseFunc

type CloseFunc func() error

CloseFunc is a function type implementing the io.Closer interface

func (CloseFunc) Close

func (c CloseFunc) Close() error

Close runs given the close function

type ControlCloseWrapper

type ControlCloseWrapper struct {
	Child        ui.Control
	CloseHandles []io.Closer
}

ControlCloseWrapper acts as a ui.Control and supports close functions. This can be used to wrap a control and run a close function when the control gets destroyed.

func NewControlCloseWrapper

func NewControlCloseWrapper(child ui.Control) *ControlCloseWrapper

NewControlCloseWrapper creates a ControlCloseWrapper with the given control type as child element

func (*ControlCloseWrapper) AddClosers

func (c *ControlCloseWrapper) AddClosers(closer ...io.Closer)

AddClosers adds the given io.Closer objects to the ControlCloseWrapper container

func (ControlCloseWrapper) Destroy

func (c ControlCloseWrapper) Destroy()

func (ControlCloseWrapper) Disable

func (c ControlCloseWrapper) Disable()

func (ControlCloseWrapper) Enable

func (c ControlCloseWrapper) Enable()

func (ControlCloseWrapper) Enabled

func (c ControlCloseWrapper) Enabled() bool

func (ControlCloseWrapper) Handle

func (c ControlCloseWrapper) Handle() uintptr

func (ControlCloseWrapper) Hide

func (c ControlCloseWrapper) Hide()

func (ControlCloseWrapper) LibuiControl

func (c ControlCloseWrapper) LibuiControl() uintptr

func (ControlCloseWrapper) Show

func (c ControlCloseWrapper) Show()

func (ControlCloseWrapper) Visible

func (c ControlCloseWrapper) Visible() bool

type Label

type Label string

Label represents a ui.Label type.

func (Label) Create

func (l Label) Create() ui.Control

Create creates the ui.Control object in the ui thread

type LabeledGuiField

type LabeledGuiField struct {
	Label   ValueControl
	Factory ValueControl
}

func (LabeledGuiField) Create

func (l LabeledGuiField) Create() ui.Control

type StrictValueControlFunc

type StrictValueControlFunc func() (ui.Control, error)

StrictValueControlFunc is a variant of ValueControlFunc which panics when the function returns an error

func (StrictValueControlFunc) Create

func (s StrictValueControlFunc) Create() ui.Control

Create implements ValueControl

type StructTagProperties

type StructTagProperties struct {
	Name       Label   `json:"name,omitempty"`
	Type       string  `json:"type,omitempty"`
	Min        int     `json:"min,omitempty"`
	Max        int     `json:"max,omitempty"`
	Resolution int     `json:"resolution,omitempty"`
	Horizontal bool    `json:"horizontal,omitempty"`
	Index      int     `json:"index,omitempty"`
	Labels     []Label `json:"labels,omitempty"`
}

StructTagProperties represents the values supported in a uiconf struct tag

func DefaultProperties

func DefaultProperties() StructTagProperties

func ParseStructTag

func ParseStructTag(tag string) (properties StructTagProperties, err error)

ParseStructTag returns a new StructTagProperties object with the contents from tag

func (*StructTagProperties) Parse

func (properties *StructTagProperties) Parse(tag string) error

Parse decodes the json format tag string into the current properties pointer

type UpdateNotifier

type UpdateNotifier interface {
	// OnValueChanged will be called when the user changes the value using the graphical interface
	OnValueChanged()
}

UpdateNotifier is an interface type a user can implement to get notified when a value changes

type ValueControl

type ValueControl interface {
	Create() ui.Control
}

ValueControl specifies an object which can create a ui.Control

func MakeValueControl

func MakeValueControl(object interface{}) (ValueControl, error)

func MakeValueControlFromValue

func MakeValueControlFromValue(value reflect.Value, properties StructTagProperties) (ValueControl, error)

type ValueControlFunc

type ValueControlFunc func() ui.Control

ValueControlFunc accepts functions that create ui.Control objects the wrapping functions will be run in the ui thread

func (ValueControlFunc) Create

func (v ValueControlFunc) Create() ui.Control

Create implements ValueControl

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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