widget

package module
v1.1.26 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: BSD-3-Clause Imports: 2 Imported by: 9

README

widget

Package gui/widget defines the widgets and actions that can be performed on them

Principles:

* Make code using this package simple to use
* Widget names should try to match [Wikipedia Graphical widget]
* It's ok to guess. Try to do something sensible.

Documentation

Overview

2D geometry values

There are lots of issues when supporting multiple toolkit plugin geometries. The geometries vary widely especially between the graphical displays and the serial console ones. [Graphical Widget](http://en.wikipedia.org/Graphical_Widget)

To simplyfy this, we stick to using the concepts:

------------------------------        ^
|             top             |       |
|                             |       |
|  left                right  |    height
|                             |       |
|            bottom           |       |
------------------------------        v

<----------- width ---------->

This way, width & height are always positive numbers.

The qustion of (top,bottom) & (left,right) becomes problematic.

In almost every toolkit, right > left. However, top & bottom vary and a choice can not be made easily. Luckily, we maybe do not have to make that decision here and can pass that determination to the toolkits. So, we use excusively:

geom(left, right, top, bottom)
size(width, height)

Orientation

Horizontal means layout widgets like books on a bookshelf

---------------------------------
| W | W | W | W | W | W | W | W |
| i | i | i | i | i | i | i | i |
| d | d | d | d | d | d | d | d |
| g | g | g | g | g | g | g | g |
| e | e | e | e | e | e | e | e |
| t | t | t | t | t | t | t | t |
---------------------------------

Vertical means layout widgets like books in a stack

----------
| Widget |
----------
| Widget |
----------
| Widget |
----------
| Widget |
----------

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(A any) bool

work like unix os.Exec() ? everything other than 0 is false

func GetInt

func GetInt(A any) int

work like unix? everything other than 0 is false

func GetString

func GetString(A any) string

Types

type Action

type Action struct {
	ActionType ActionType
	WidgetType WidgetType

	WidgetId int
	ParentId int

	State State

	// Text string  // what is visable to the user
	ProgName string // a name useful for programming

	// most primitive widgets just store a single thing
	Value any

	// how to arrange widgets
	Direction Orientation

	// All the strings for things like dropdown menus
	// They must be sent in display order
	// These must be unique
	Strings []string

	Range RangeType

	// RETHINK / REDO EVERYTHING BELOW HERE
	// This is used for things like a slider(0,100)
	X int
	Y int

	// This is for the grid size & widget position
	W   int
	H   int
	AtW int
	AtH int

	// Make widgets fill up the space available
	Expand bool
}

type ActionType

type ActionType int // Add, SetText, Click, Hide, Append, Delete, etc
const (
	Add ActionType = iota + 1
	Delete
	SetText
	AddText
	Checked
	Show
	Hide
	Enable
	Disable
	SetMargin
	Margin
	Unmargin
	SetPad
	Pad
	Unpad
	SetExpand
	Append
	Move
	Dump
	User         // the user did something (mouse, keyboard, etc)
	ToolkitLoad  // attempts to load a new toolkit
	ToolkitInit  // initializes the toolkit
	ToolkitClose // closes the toolkit
	ToolkitPanic
	Heartbeat
	CloseWindow
	UserQuit    // the user closed the GUI
	EnableDebug // open the debugging window
)

func (ActionType) String

func (s ActionType) String() string

type Geom

type Geom struct {
	Left   any
	Right  any
	Top    any
	Bottom any
}

type GridOffset

type GridOffset struct {
	X int
	Y int
}

type GridSize

type GridSize struct {
	Width  int
	Height int
}

type Orientation

type Orientation int

Horizontal means layout widgets like books on a bookshelf

---------------------------------
| W | W | W | W | W | W | W | W |
| i | i | i | i | i | i | i | i |
| d | d | d | d | d | d | d | d |
| g | g | g | g | g | g | g | g |
| e | e | e | e | e | e | e | e |
| t | t | t | t | t | t | t | t |
---------------------------------

Vertical means layout widgets like books in a stack

----------
| Widget |
----------
| Widget |
----------
| Widget |
----------
| Widget |
----------
const (
	Horizontal Orientation = iota
	Vertical
)

func (Orientation) String

func (s Orientation) String() string

type RangeType

type RangeType struct {
	Low  int
	High int
}

Range(1, 10) includes the values 1 and 10 almost all toolkits use integers so there doesn't seem to be a good idea to use 'type any' here as it just makes things more complicated for no good reason

type Size

type Size struct {
	Width  any
	Height any
}

type State

type State struct {
	// This is a unmodifiable string that is displayed to the user.
	Label string

	// most primitive widgets just store a single thing
	// it is the default value
	DefaultS  string
	CurrentS  string
	CurrentI  int
	NewString string

	// how to arrange widgets
	Direction Orientation

	// for widgets that have on/off things
	Checked bool

	//
	// This is complicated. We must send a list of all the widgets
	// in the binary tree to the toolkits because some toolkits
	// must make the widgets exist and then hide them.
	//
	// However, when a widget is not visable, no updates to the
	// widget is sent to the toolkit and no events from the
	// widget are valid back to the program
	//
	Visable bool

	// this tells the toolkit to hide the widget from being displayed
	// again, this is different than Visable. The hidden state is
	// specifically ONLY for the gui toolkit
	Hidden bool

	// is the widget usable by the user?
	Enable bool

	// if false, pack things as tightly as possible
	Pad bool

	// trys to fill up available space
	Expand bool

	// for toolkits with borderless window options
	Borderless bool

	// All the strings for things like dropdown menus
	// They must be sent in display order
	// These must be unique
	Strings []string

	// for widgets that use a range
	Range RangeType

	Geom Geom
	Size Size

	GridSize   GridSize
	GridOffset GridOffset

	// This is for the grid size & widget position
	W   int
	H   int
	AtW int
	AtH int

	// a name useful for programming and the debugger.
	// It is not intended to be displayed to the user
	ProgName string
}

Range(1, 10) includes the values 1 and 10 almost all toolkits use integers so there doesn't seem to be a good idea to use 'type any' here as it just makes things more complicated for no good reason

type WidgetType

type WidgetType int // Button, Menu, Checkbox, etc.
const (
	Unknown WidgetType = iota + 1
	Root               // the master 'root' node of the binary tree
	Flag               // used to send configuration values to plugins
	Window             // in certain gui's (ncurses), these are tabs
	Tab                // internally, this is a window
	Frame              // deprecate?
	Grid               // like drawers in a chest
	Group              // like the 'Appetizers' section on a menu
	Box                // a vertical or horizontal stack of widgets
	Button
	Checkbox // select 'on' or 'off'
	Dropdown
	Combobox // dropdown with edit=true
	Label
	Textbox   // is this a Label with edit=true
	Slider    // like a progress bar
	Spinner   // like setting the oven temperature
	Separator // TODO
	Image     // TODO
	Area      // TODO
	Form      // TODO
	Font      // TODO
	Color     // TODO
	Dialog    // TODO
	Stdout    // can be used to capture and display log output
)

func (WidgetType) String

func (s WidgetType) String() string

Jump to

Keyboard shortcuts

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