ui

package module
v0.0.0-...-e2f5304 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2016 License: MIT Imports: 5 Imported by: 0

README

ui: platform-native GUI library for Go

Update 5 June 2016: You can FINALLY go get this package!

go get should work out of the box for the following configurations:

  • darwin/amd64
  • linux/386
  • linux/amd64
  • linux/arm (only tested on a Raspberry Pi 2)
  • windows/386
  • windows/amd64

Everything is now fully static — no DLLs or shared objects anymore!

Note that these might not fully work right now, as the libui Alpha 3.1 API isn't fully implemented yet, and there might be residual binding problems. Hopefully none which require an Alpha 3.2...

New README

This is a library that aims to provide simple GUI software development in Go.

It is based on my libui, a simple cross-platform library that does the same thing, but written in C. You must include this library in your binary distributions.

It runs on/requires:

  • Windows: cgo, Windows Vista SP2 with Platform Update and newer
  • Mac OS X: cgo, Mac OS X 10.8 and newer
  • other Unixes: cgo, GTK+ 3.10 and newer

It also requires Go 1.6 or newer (due to various bugs in cgo that were fixed only starting with 1.6).

(this README needs some work)

Installation

Documentation

The in-code documentation needs improvement. I have written a tutorial in the Wiki.

Updates

Documentation

Overview

20 april 2016

Index

Constants

View Source
const DefaultMiterLimit = 10.0

TODO document

Variables

This section is empty.

Functions

func LibuiControlDestroy

func LibuiControlDestroy(c uintptr)

LibuiControlDestroy allows implementations of Control to call the libui function uiControlDestroy.

func LibuiControlDisable

func LibuiControlDisable(c uintptr)

LibuiControlDisable allows implementations of Control to call the libui function uiControlDisable.

func LibuiControlEnable

func LibuiControlEnable(c uintptr)

LibuiControlEnable allows implementations of Control to call the libui function uiControlEnable.

func LibuiControlHandle

func LibuiControlHandle(c uintptr) uintptr

LibuiControlHandle allows implementations of Control to call the libui function uiControlHandle.

func LibuiControlHide

func LibuiControlHide(c uintptr)

LibuiControlHide allows implementations of Control to call the libui function uiControlHide.

func LibuiControlShow

func LibuiControlShow(c uintptr)

LibuiControlShow allows implementations of Control to call the libui function uiControlShow.

func LibuiFreeText

func LibuiFreeText(c uintptr)

LibuiFreeText allows implementations of Control to call the libui function uiFreeText.

func Main

func Main(f func()) error

Main initializes package ui, runs f to set up the program, and executes the GUI main loop. f should set up the program's initial state: open the main window, create controls, and set up events. It should then return, at which point Main will process events until Quit is called, at which point Main will return nil. If package ui fails to initialize, Main returns an appropriate error.

func MsgBox

func MsgBox(w *Window, title string, description string)

func MsgBoxError

func MsgBoxError(w *Window, title string, description string)

TODO

func OnShouldQuit

func OnShouldQuit(f func() bool)

OnShouldQuit schedules f to be exeucted when the OS wants the program to quit or when a Quit menu item has been clicked. Only one function may be registered at a time. If the function returns true, Quit will be called. If the function returns false, or if OnShouldQuit is never called. Quit will not be called and the OS will be told that the program needs to continue running.

func OpenFile

func OpenFile(w *Window) string

func QueueMain

func QueueMain(f func())

QueueMain queues f to be executed on the GUI thread when next possible. It returns immediately; that is, it does not wait for the function to actually be executed. QueueMain is the only function that can be called from other goroutines, and its primary purpose is to allow communication between other goroutines and the GUI thread. Calling QueueMain after Quit has been called results in undefined behavior.

func Quit

func Quit()

Quit queues a return from Main. It does not exit the program. It also does not immediately cause Main to return; Main will return when it next can. Quit must be called from the GUI thread.

func SaveFile

func SaveFile(w *Window) string

Types

type Align

type Align int
const (
	AlignFill Align = iota
	AlignStart
	AlignCenter
	AlignEnd
)

type Area

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

Area is a Control that represents a blank canvas that a program can draw on as it wishes. Areas also receive keyboard and mouse events, and programs can react to those as they see fit. Drawing and event handling are handled through an instance of a type that implements AreaHandler that every Area has; see AreaHandler for details.

There are two types of areas. Non-scrolling areas are rectangular and have no scrollbars. Programs can draw on and get mouse events from any point in the Area, and the size of the Area is decided by package ui itself, according to the layout of controls in the Window the Area is located in and the size of said Window. There is no way to query the Area's size or be notified when its size changes; instead, you are given the area size as part of the draw and mouse event handlers, for use solely within those handlers.

Scrolling areas have horziontal and vertical scrollbars. The amount that can be scrolled is determined by the area's size, which is decided by the programmer (both when creating the Area and by a call to SetSize). Only a portion of the Area is visible at any time; drawing and mouse events are automatically adjusted to match what portion is visible, so you do not have to worry about scrolling in your event handlers. AreaHandler has more information.

The internal coordinate system of an Area is points, which are floating-point and device-independent. For more details, see AreaHandler. The size of a scrolling Area must be an exact integer number of points (that is, you cannot have an Area that is 32.5 points tall) and thus the parameters to NewScrollingArea and SetSize are ints. All other instances of points in parameters and structures (including sizes of drawn objects) are float64s.

func NewArea

func NewArea(handler AreaHandler) *Area

NewArea creates a new non-scrolling Area.

func NewScrollingArea

func NewScrollingArea(handler AreaHandler, width int, height int) *Area

NewScrollingArea creates a new scrolling Area of the given size, in points.

func (*Area) Destroy

func (a *Area) Destroy()

Destroy destroys the Area.

func (*Area) Disable

func (a *Area) Disable()

Disable disables the Area.

func (*Area) Enable

func (a *Area) Enable()

Enable enables the Area.

func (*Area) Handle

func (a *Area) Handle() uintptr

Handle returns the OS-level handle associated with this Area. On Windows this is an HWND of a libui-internal class. On GTK+ this is a pointer to a GtkScrolledWindow with a GtkViewport as its child. The child of the viewport is the GtkDrawingArea that provides the Area itself. On OS X this is a pointer to a NSScrollView whose document view is the NSView that provides the Area itself.

func (*Area) Hide

func (a *Area) Hide()

Hide hides the Area.

func (*Area) LibuiControl

func (a *Area) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Area. This is only used by package ui itself and should not be called by programs.

func (*Area) QueueRedrawAll

func (a *Area) QueueRedrawAll()

QueueRedrawAll queues the entire Area for redraw. The Area is not redrawn before this function returns; it is redrawn when next possible.

func (*Area) ScrollTo

func (a *Area) ScrollTo(x float64, y float64, width float64, height float64)

ScrollTo scrolls the Area to show the given rectangle; what this means is implementation-defined, but you can safely assume that as much of the given rectangle as possible will be visible after this call. (TODO verify this on OS X) ScrollTo panics if called on a non-scrolling Area.

func (*Area) SetSize

func (a *Area) SetSize(width int, height int)

SetSize sets the size of a scrolling Area to the given size, in points. SetSize panics if called on a non-scrolling Area.

func (*Area) Show

func (a *Area) Show()

Show shows the Area.

type AreaDrawParams

type AreaDrawParams struct {
	// Context is the drawing context to draw on. See DrawContext
	// for how to draw.
	Context *DrawContext

	// AreaWidth and AreaHeight provide the size of the Area for
	// non-scrolling Areas. For scrolling Areas both values are zero.
	//
	// To reiterate the AreaHandler documentation, do NOT save
	// these values for later; they can change without generating
	// an event.
	AreaWidth  float64
	AreaHeight float64

	// These four fields define the rectangle that needs to be
	// redrawn. The system will not draw anything outside this
	// rectangle, but you can make your drawing faster if you
	// also stay within the lines.
	ClipX      float64
	ClipY      float64
	ClipWidth  float64
	ClipHeight float64
}

AreaDrawParams provides a drawing context that can be used to draw on an Area and tells you where to draw. See AreaHandler for introductory information.

type AreaHandler

type AreaHandler interface {
	// Draw is sent when a part of the Area needs to be drawn.
	// dp will contain a drawing context to draw on, the rectangle
	// that needs to be drawn in, and (for a non-scrolling area) the
	// size of the area. The rectangle that needs to be drawn will
	// have been cleared by the system prior to drawing, so you are
	// always working on a clean slate.
	//
	// If you call Save on the drawing context, you must call Release
	// before returning from Draw, and the number of calls to Save
	// and Release must match. Failure to do so results in undefined
	// behavior.
	Draw(a *Area, dp *AreaDrawParams)

	// MouseEvent is called when the mouse moves over the Area
	// or when a mouse button is pressed or released. See
	// AreaMouseEvent for more details.
	//
	// If a mouse button is being held, MouseEvents will continue to
	// be generated, even if the mouse is not within the area. On
	// some systems, the system can interrupt this behavior;
	// see DragBroken.
	MouseEvent(a *Area, me *AreaMouseEvent)

	// MouseCrossed is called when the mouse either enters or
	// leaves the Area. It is called even if the mouse buttons are being
	// held (see MouseEvent above). If the mouse has entered the
	// Area, left is false; if it has left the Area, left is true.
	//
	// If, when the Area is first shown, the mouse is already inside
	// the Area, MouseCrossed will be called with left=false.
	// TODO what about future shows?
	MouseCrossed(a *Area, left bool)

	// DragBroken is called if a mouse drag is interrupted by the
	// system. As noted above, when a mouse button is held,
	// MouseEvent will continue to be called, even if the mouse is
	// outside the Area. On some systems, this behavior can be
	// stopped by the system itself for a variety of reasons. This
	// method is provided to allow your program to cope with the
	// loss of the mouse in this case. You should cope by cancelling
	// whatever drag-related operation you were doing.
	//
	// Note that this is only generated on some systems under
	// specific conditions. Do not implement behavior that only
	// takes effect when DragBroken is called.
	DragBroken(a *Area)

	// KeyEvent is called when a key is pressed while the Area has
	// keyboard focus (if the Area has been tabbed into or if the
	// mouse has been clicked on it). See AreaKeyEvent for specifics.
	//
	// Because some keyboard events are handled by the system
	// (for instance, menu accelerators and global hotkeys), you
	// must return whether you handled the key event; return true
	// if you did or false if you did not. If you wish to ignore the
	// keyboard outright, the correct implementation of KeyEvent is
	// 	func (h *MyHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
	// 		return false
	// 	}
	// DO NOT RETURN TRUE UNCONDITIONALLY FROM THIS
	// METHOD. BAD THINGS WILL HAPPEN IF YOU DO.
	KeyEvent(a *Area, ke *AreaKeyEvent) (handled bool)
}

AreaHandler defines the functionality needed for handling events from an Area. Each of the methods on AreaHandler is called from the GUI thread, and every parameter (other than the Area itself) should be assumed to only be valid during the life of the method call (so for instance, do not save AreaDrawParams.AreaWidth, as that might change without generating an event).

Coordinates to Draw and MouseEvent are given in points. Points are generic, floating-point, device-independent coordinates with (0,0) at the top left corner. You never have to worry about the mapping between points and pixels; simply draw everything using points and you get nice effects like looking sharp on high-DPI monitors for free. Proper documentation on the matter is being written. In the meantime, there are several referenes to this kind of drawing, most notably on Apple's website: https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html#//apple_ref/doc/uid/TP40012302-CH4-SW1

For a scrolling Area, points are automatically offset by the scroll position. So if the mouse moves to position (5,5) while the horizontal scrollbar is at position 10 and the horizontal scrollbar is at position 20, the coordinate stored in the AreaMouseEvent structure is (15,25). The same applies to drawing.

type AreaKeyEvent

type AreaKeyEvent struct {
	Key       rune
	ExtKey    ExtKey
	Modifier  Modifiers
	Modifiers Modifiers
	Up        bool
}

TODO document all these

type AreaMouseEvent

type AreaMouseEvent struct {
	X float64
	Y float64

	// AreaWidth and AreaHeight provide the size of the Area for
	// non-scrolling Areas. For scrolling Areas both values are zero.
	//
	// To reiterate the AreaHandler documentation, do NOT save
	// these values for later; they can change without generating
	// an event.
	AreaWidth  float64
	AreaHeight float64

	Down      uint
	Up        uint
	Count     uint
	Modifiers Modifiers
	Held      []uint
}

TODO document all these

TODO note that in the case of a drag, X and Y can be out of bounds, or in the event of a scrolling area, in places that are not visible

type At

type At int
const (
	AtLeading At = iota
	AtTop
	AtTrailing
	AtBottom
)

type Box

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

Box is a Control that holds a group of Controls horizontally or vertically. If horizontally, then all controls have the same height. If vertically, then all controls have the same width. By default, each control has its preferred width (horizontal) or height (vertical); if a control is marked "stretchy", it will take whatever space is left over. If multiple controls are marked stretchy, they will be given equal shares of the leftover space. There can also be space between each control ("padding").

func NewHorizontalBox

func NewHorizontalBox() *Box

NewHorizontalBox creates a new horizontal Box.

func NewVerticalBox

func NewVerticalBox() *Box

NewVerticalBox creates a new vertical Box.

func (*Box) Append

func (b *Box) Append(child Control, stretchy bool)

Append adds the given control to the end of the Box.

func (*Box) Delete

func (b *Box) Delete(n int)

Delete deletes the nth control of the Box.

func (*Box) Destroy

func (b *Box) Destroy()

Destroy destroys the Box. If the Box has children, Destroy calls Destroy on those Controls as well.

func (*Box) Disable

func (b *Box) Disable()

Disable disables the Box.

func (*Box) Enable

func (b *Box) Enable()

Enable enables the Box.

func (*Box) Handle

func (b *Box) Handle() uintptr

Handle returns the OS-level handle associated with this Box. On Windows this is an HWND of a libui-internal class. On GTK+ this is a pointer to a GtkBox. On OS X this is a pointer to a NSView.

func (*Box) Hide

func (b *Box) Hide()

Hide hides the Box.

func (*Box) LibuiControl

func (b *Box) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Box. This is only used by package ui itself and should not be called by programs.

func (*Box) Padded

func (b *Box) Padded() bool

Padded returns whether there is space between each control of the Box.

func (*Box) SetPadded

func (b *Box) SetPadded(padded bool)

SetPadded controls whether there is space between each control of the Box. The size of the padding is determined by the OS and its best practices.

func (*Box) Show

func (b *Box) Show()

Show shows the Box.

type Brush

type Brush struct {
	Type BrushType

	// If Type is Solid.
	// TODO
	R float64
	G float64
	B float64
	A float64

	// If Type is LinearGradient or RadialGradient.
	// TODO
	X0          float64 // start point for both
	Y0          float64
	X1          float64 // linear: end point; radial: circle center
	Y1          float64
	OuterRadius float64 // for radial gradients only
	Stops       []GradientStop
}

TODO

type BrushType

type BrushType int

BrushType defines the various types of brushes.

TODO disclaimer

const (
	Solid BrushType = iota
	LinearGradient
	RadialGradient
	Image // presently unimplemented
)

type Button

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

Button is a Control that represents a button that the user can click to perform an action. A Button has a text label that should describe what the button does.

func NewButton

func NewButton(text string) *Button

NewButton creates a new Button with the given text as its label.

func (*Button) Destroy

func (b *Button) Destroy()

Destroy destroys the Button.

func (*Button) Disable

func (b *Button) Disable()

Disable disables the Button.

func (*Button) Enable

func (b *Button) Enable()

Enable enables the Button.

func (*Button) Handle

func (b *Button) Handle() uintptr

Handle returns the OS-level handle associated with this Button. On Windows this is an HWND of a standard Windows API BUTTON class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkButton. On OS X this is a pointer to a NSButton.

func (*Button) Hide

func (b *Button) Hide()

Hide hides the Button.

func (*Button) LibuiControl

func (b *Button) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Button. This is only used by package ui itself and should not be called by programs.

func (*Button) OnClicked

func (b *Button) OnClicked(f func(*Button))

OnClicked registers f to be run when the user clicks the Button. Only one function can be registered at a time.

func (*Button) SetText

func (b *Button) SetText(text string)

SetText sets the Button's text to text.

func (*Button) Show

func (b *Button) Show()

Show shows the Button.

func (*Button) Text

func (b *Button) Text() string

Text returns the Button's text.

type Checkbox

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

Checkbox is a Control that represents a box with a text label at its side. When the user clicks the checkbox, a check mark will appear in the box; clicking it again removes the check.

func NewCheckbox

func NewCheckbox(text string) *Checkbox

NewCheckbox creates a new Checkbox with the given text as its label.

func (*Checkbox) Checked

func (c *Checkbox) Checked() bool

Checked returns whether the Checkbox is checked.

func (*Checkbox) Destroy

func (c *Checkbox) Destroy()

Destroy destroys the Checkbox.

func (*Checkbox) Disable

func (c *Checkbox) Disable()

Disable disables the Checkbox.

func (*Checkbox) Enable

func (c *Checkbox) Enable()

Enable enables the Checkbox.

func (*Checkbox) Handle

func (c *Checkbox) Handle() uintptr

Handle returns the OS-level handle associated with this Checkbox. On Windows this is an HWND of a standard Windows API BUTTON class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkCheckButton. On OS X this is a pointer to a NSButton.

func (*Checkbox) Hide

func (c *Checkbox) Hide()

Hide hides the Checkbox.

func (*Checkbox) LibuiControl

func (c *Checkbox) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*Checkbox) OnToggled

func (c *Checkbox) OnToggled(f func(*Checkbox))

OnToggled registers f to be run when the user clicks the Checkbox. Only one function can be registered at a time.

func (*Checkbox) SetChecked

func (c *Checkbox) SetChecked(checked bool)

SetChecked sets whether the Checkbox is checked.

func (*Checkbox) SetText

func (c *Checkbox) SetText(text string)

SetText sets the Checkbox's text to text.

func (*Checkbox) Show

func (c *Checkbox) Show()

Show shows the Checkbox.

func (*Checkbox) Text

func (c *Checkbox) Text() string

Text returns the Checkbox's text.

type Combobox

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

Combobox is a Control that represents a drop-down list of strings that the user can choose one of at any time. An editable Combobox also has an entry field that the user can type an alternate choice into.

func NewCombobox

func NewCombobox() *Combobox

NewCombobox creates a new Combobox. This Combobox is not editable.

func (*Combobox) Append

func (c *Combobox) Append(text string)

Append adds the named item to the end of the Combobox.

func (*Combobox) Destroy

func (c *Combobox) Destroy()

TODO // NewEditableCombobox creates a new editable Combobox.

func NewEditableCombobox() *Combobox {
	c := new(Combobox)

	c.c = C.uiNewEditableCombobox()
	c.co = (*C.uiControl)(unsafe.Pointer(c.c))

	C.realuiComboboxOnSelected(c.c)
	comboboxes[c.c] = c

	return c
}

Destroy destroys the Combobox.

func (*Combobox) Disable

func (c *Combobox) Disable()

Disable disables the Combobox.

func (*Combobox) Enable

func (c *Combobox) Enable()

Enable enables the Combobox.

func (*Combobox) Handle

func (c *Combobox) Handle() uintptr

Handle returns the OS-level handle associated with this Combobox. On Windows this is an HWND of a standard Windows API COMBOBOX class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkComboBoxText. On OS X this is a pointer to a NSComboBox for editable Comboboxes and to a NSPopUpButton for noneditable Comboboxes.

func (*Combobox) Hide

func (c *Combobox) Hide()

Hide hides the Combobox.

func (*Combobox) LibuiControl

func (c *Combobox) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*Combobox) OnSelected

func (c *Combobox) OnSelected(f func(*Combobox))

OnSelected registers f to be run when the user selects an item in the Combobox. Only one function can be registered at a time.

func (*Combobox) Selected

func (c *Combobox) Selected() int

Selected returns the index of the currently selected item in the Combobox, or -1 if nothing is selected.

func (*Combobox) SetSelected

func (c *Combobox) SetSelected(index int)

SetChecked sets the currently select item in the Combobox to index. If index is -1 no item will be selected.

func (*Combobox) Show

func (c *Combobox) Show()

Show shows the Combobox.

type Control

type Control interface {
	// Destroy destroys the Control.
	//
	// Implementations should do any necessary cleanup,
	// then call LibuiControlDestroy.
	Destroy()

	// LibuiControl returns the libui uiControl pointer that backs
	// the Control. This is only used by package ui itself and should
	// not be called by programs.
	LibuiControl() uintptr

	// Handle returns the OS-level handle that backs the
	// Control. On OSs that use reference counting for
	// controls, Handle does not increment the reference
	// count; you are sharing package ui's reference.
	//
	// Implementations should call LibuiControlHandle and
	// document exactly what kind of handle is returned.
	Handle() uintptr

	// Show shows the Control.
	//
	// Implementations should call LibuiControlShow.
	Show()

	// Hide shows the Control. Hidden controls do not participate
	// in layout (that is, Box, Grid, etc. does not reserve space for
	// hidden controls).
	//
	// Implementations should call LibuiControlHide.
	Hide()

	// Enable enables the Control.
	//
	// Implementations should call LibuiControlEnable.
	Enable()

	// Disable disables the Control.
	//
	// Implementations should call LibuiControlDisable.
	Disable()
}

Control represents a GUI control. It provdes methods common to all Controls.

To create a new Control, implement the control on the libui side, then provide access to that control on the Go side via an implementation of Control as described.

type DateTimePicker

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

DateTimePicker is a Control that represents a field where the user can enter a date and/or a time.

func NewDatePicker

func NewDatePicker() *DateTimePicker

NewDatePicker creates a new DateTimePicker that shows only a date.

func NewDateTimePicker

func NewDateTimePicker() *DateTimePicker

NewDateTimePicker creates a new DateTimePicker that shows both a date and a time.

func NewTimePicker

func NewTimePicker() *DateTimePicker

NewTimePicker creates a new DateTimePicker that shows only a time.

func (*DateTimePicker) Destroy

func (d *DateTimePicker) Destroy()

Destroy destroys the DateTimePicker.

func (*DateTimePicker) Disable

func (d *DateTimePicker) Disable()

Disable disables the DateTimePicker.

func (*DateTimePicker) Enable

func (d *DateTimePicker) Enable()

Enable enables the DateTimePicker.

func (*DateTimePicker) Handle

func (d *DateTimePicker) Handle() uintptr

Handle returns the OS-level handle associated with this DateTimePicker. On Windows this is an HWND of a standard Windows API DATETIMEPICK_CLASS class (as provided by Common Controls version 6). On GTK+ this is a pointer to a libui-internal class. On OS X this is a pointer to a NSDatePicker.

func (*DateTimePicker) Hide

func (d *DateTimePicker) Hide()

Hide hides the DateTimePicker.

func (*DateTimePicker) LibuiControl

func (d *DateTimePicker) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*DateTimePicker) Show

func (d *DateTimePicker) Show()

Show shows the DateTimePicker.

type DrawContext

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

DrawContext represents a drawing surface that you can draw to. At present the only DrawContexts are surfaces associated with Areas and are provided by package ui; see AreaDrawParams.

func (*DrawContext) Clip

func (c *DrawContext) Clip(p *Path)

TODO

func (*DrawContext) Fill

func (c *DrawContext) Fill(p *Path, b *Brush)

TODO

func (*DrawContext) Restore

func (c *DrawContext) Restore()

TODO

func (*DrawContext) Save

func (c *DrawContext) Save()

TODO

func (*DrawContext) Stroke

func (c *DrawContext) Stroke(p *Path, b *Brush, sp *StrokeParams)

TODO

func (*DrawContext) Text

func (c *DrawContext) Text(x float64, y float64, layout *TextLayout)

Text draws the given TextLayout onto c at the given point. The point refers to the top-left corner of the text. (TODO bounding box or typographical extent?)

func (*DrawContext) Transform

func (c *DrawContext) Transform(m *Matrix)

TODO

type Entry

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

Entry is a Control that represents a space that the user can type a single line of text into.

func NewEntry

func NewEntry() *Entry

NewEntry creates a new Entry.

func NewPasswordEntry

func NewPasswordEntry() *Entry

NewPasswordEntry creates a new Entry suitable for entering passwords.

func NewSearchEntry

func NewSearchEntry() *Entry

NewSearchEntry creates a new Entry suitable for searching.

func (*Entry) Destroy

func (e *Entry) Destroy()

Destroy destroys the Entry.

func (*Entry) Disable

func (e *Entry) Disable()

Disable disables the Entry.

func (*Entry) Enable

func (e *Entry) Enable()

Enable enables the Entry.

func (*Entry) Handle

func (e *Entry) Handle() uintptr

Handle returns the OS-level handle associated with this Entry. On Windows this is an HWND of a standard Windows API EDIT class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkEntry. On OS X this is a pointer to a NSTextField.

func (*Entry) Hide

func (e *Entry) Hide()

Hide hides the Entry.

func (*Entry) LibuiControl

func (e *Entry) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*Entry) OnChanged

func (e *Entry) OnChanged(f func(*Entry))

OnChanged registers f to be run when the user makes a change to the Entry. Only one function can be registered at a time.

func (*Entry) ReadOnly

func (e *Entry) ReadOnly() bool

ReadOnly returns whether the Entry can be changed.

func (*Entry) SetReadOnly

func (e *Entry) SetReadOnly(ro bool)

SetReadOnly sets whether the Entry can be changed.

func (*Entry) SetText

func (e *Entry) SetText(text string)

SetText sets the Entry's text to text.

func (*Entry) Show

func (e *Entry) Show()

Show shows the Entry.

func (*Entry) Text

func (e *Entry) Text() string

Text returns the Entry's text.

type ExtKey

type ExtKey int

TODO document

Note: these must be numerically identical to their libui equivalents.

const (
	Escape ExtKey = iota + 1
	Insert        // equivalent to "Help" on Apple keyboards
	Delete
	Home
	End
	PageUp
	PageDown
	Up
	Down
	Left
	Right
	F1 // F1..F12 are guaranteed to be consecutive
	F2
	F3
	F4
	F5
	F6
	F7
	F8
	F9
	F10
	F11
	F12
	N0 // numpad keys; independent of Num Lock state
	N1 // N0..N9 are guaranteed to be consecutive
	N2
	N3
	N4
	N5
	N6
	N7
	N8
	N9
	NDot
	NEnter
	NAdd
	NSubtract
	NMultiply
	NDivide
)

type FillMode

type FillMode uint

TODO

TODO disclaimer

const (
	Winding FillMode = iota
	Alternate
)

type Font

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

Font represents an actual font that can be drawn with.

func LoadClosestFont

func LoadClosestFont(desc *FontDescriptor) *Font

LoadClosestFont loads a Font.

You pass the properties of the ideal font you want to load in the FontDescriptor you pass to this function. If the requested font is not available on the system, the closest matching font is used. This means that, for instance, if you specify a Weight of TextWeightUltraHeavy and the heaviest weight available for the chosen font family is actually TextWeightBold, that will be used instead. The specific details of font matching beyond this description are implementation defined. This also means that getting a descriptor back out of a Font may return a different desriptor.

TODO guarantee that passing *that* back into LoadClosestFont() returns the same font

func (*Font) Describe

func (f *Font) Describe() *FontDescriptor

Describe returns the FontDescriptor that most closely matches this Font. TODO guarantees about idempotency TODO rewrite that first sentence

func (*Font) Free

func (f *Font) Free()

Free destroys a Font. After calling Free the Font cannot be used.

func (*Font) Handle

func (f *Font) Handle() uintptr

Handle returns the OS font object that backs this Font. On OSs that use reference counting for font objects, Handle does not increment the reference count; you are sharing package ui's reference.

On Windows this is a pointer to an IDWriteFont.

On Unix systems this is a pointer to a PangoFont.

On OS X this is a CTFontRef.

func (*Font) Metrics

func (f *Font) Metrics() *FontMetrics

Metrics returns metrics about the given Font.

type FontDescriptor

type FontDescriptor struct {
	Family  string
	Size    float64 // as a text size, for instance 12 for a 12-point font
	Weight  TextWeight
	Italic  TextItalic
	Stretch TextStretch
}

FontDescriptor describes a Font.

type FontFamilies

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

FontFamilies represents an enumerator over the font families available for use by package ui. A FontFamilies object behaves similarly to a []string, except that since family names are loaded on demand (depending on the operating system), it is not an actual []string. You call ListFontFamilies to obtain a FontFamilies object, which should reflect the available fonts at the time of the call (TODO verify). Use NumFamilies to get the number of families, and Family to get the name of a given family by index. When finished, call Free.

There is no guarantee that the list of families is sorted. You will need to do sorting yourself if you need it.

TODO thread affinity

func ListFontFamilies

func ListFontFamilies() *FontFamilies

ListFontFamilies creates a new FontFamilies object ready for use.

func (*FontFamilies) Family

func (f *FontFamilies) Family(n int) string

Family returns the name of the nth family in the list.

func (*FontFamilies) Free

func (f *FontFamilies) Free()

Free destroys a FontFamilies. After calling Free, the FontFamilies cannot be used.

func (*FontFamilies) NumFamilies

func (f *FontFamilies) NumFamilies() int

NumFamilies returns the number of font families available.

type FontMetrics

type FontMetrics struct {
	// Ascent is the ascent of the font; that is, the distance from
	// the top of the character cell to the baseline.
	Ascent float64

	// Descent is the descent of the font; that is, the distance from
	// the baseline to the bottom of the character cell. The sum of
	// Ascent and Descent is the height of the character cell (and
	// thus, the maximum height of a line of text).
	Descent float64

	// Leading is the amount of space the font designer suggests
	// to have between lines (between the bottom of the first line's
	// character cell and the top of the second line's character cell).
	// This is a suggestion; it is chosen by the font designer to
	// improve legibility.
	Leading float64

	// TODO figure out what these are
	UnderlinePos       float64
	UnderlineThickness float64
}

FontMetrics holds various measurements about a Font. All metrics are in the same point units used for drawing.

type Form

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

func NewForm

func NewForm() *Form

NewForm creates a new Form.

func (*Form) Append

func (f *Form) Append(label string, child Control, stretchy bool)

Append adds the given control to the end of the Form.

func (*Form) Delete

func (f *Form) Delete(n int)

Delete deletes the nth control of the Form.

func (*Form) Destroy

func (f *Form) Destroy()

Destroy destroys the Form. If the Form has children, Destroy calls Destroy on those Controls as well.

func (*Form) Disable

func (f *Form) Disable()

Disable disables the Form.

func (*Form) Enable

func (f *Form) Enable()

Enable enables the Form.

func (*Form) Handle

func (f *Form) Handle() uintptr

Handle returns the OS-level handle associated with this Form.

func (*Form) Hide

func (f *Form) Hide()

Hide hides the Form.

func (*Form) LibuiControl

func (f *Form) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Form. This is only used by package ui itself and should not be called by programs.

func (*Form) Padded

func (f *Form) Padded() bool

Padded returns whether there is space between each control of the Form.

func (*Form) SetPadded

func (f *Form) SetPadded(padded bool)

SetPadded controls whether there is space between each control of the Form. The size of the padding is determined by the OS and its best practices.

func (*Form) Show

func (f *Form) Show()

Show shows the Form.

type GradientStop

type GradientStop struct {
	Pos float64 // between 0 and 1 inclusive
	R   float64
	G   float64
	B   float64
	A   float64
}

TODO

type Grid

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

Grid is a container Control that arranges controls in rows and columns, with stretchy ("expanding") rows, stretchy ("expanding") columns, cells that span rows and columns, and cells whose content is aligned in either direction rather than just filling.

func NewGrid

func NewGrid() *Grid

NewGrid creates a new Grid.

func (*Grid) Append

func (g *Grid) Append(child Control, left, top, xspan, yspan int, hexpand bool, uialign Align, vexpand bool, valign Align)

Append adds the given control to the end of the Grid.

func (*Grid) Delete

func (g *Grid) Delete(n int)

Delete deletes the nth control of the Grid.

func (*Grid) Destroy

func (g *Grid) Destroy()

Destroy destroys the Grid. If the Grid has children, Destroy calls Destroy on those Controls as well.

func (*Grid) Disable

func (g *Grid) Disable()

Disable disables the Grid.

func (*Grid) Enable

func (g *Grid) Enable()

Enable enables the Grid.

func (*Grid) Handle

func (g *Grid) Handle() uintptr

Handle returns the OS-level handle associated with this Grid.

func (*Grid) Hide

func (g *Grid) Hide()

Hide hides the Grid.

func (*Grid) LibuiControl

func (g *Grid) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Grid. This is only used by package ui itself and should not be called by programs.

func (*Grid) Padded

func (g *Grid) Padded() bool

Padded returns whether there is space between each control of the Grid.

func (*Grid) SetPadded

func (g *Grid) SetPadded(padded bool)

SetPadded controls whether there is space between each control of the Grid. The size of the padding is determined by the OS and its best practices.

func (*Grid) Show

func (g *Grid) Show()

Show shows the Grid.

type Group

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

Group is a Control that holds another Control and wraps it around a labelled box (though some systems make this box invisible). You can use this to group related controls together.

func NewGroup

func NewGroup(title string) *Group

NewGroup creates a new Group.

func (*Group) Destroy

func (g *Group) Destroy()

Destroy destroys the Group. If the Group has a child, Destroy calls Destroy on that as well.

func (*Group) Disable

func (g *Group) Disable()

Disable disables the Group.

func (*Group) Enable

func (g *Group) Enable()

Enable enables the Group.

func (*Group) Handle

func (g *Group) Handle() uintptr

Handle returns the OS-level handle associated with this Group. On Windows this is an HWND of a standard Windows API BUTTON class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkFrame. On OS X this is a pointer to a NSBox.

func (*Group) Hide

func (g *Group) Hide()

Hide hides the Group.

func (*Group) LibuiControl

func (g *Group) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Group. This is only used by package ui itself and should not be called by programs.

func (*Group) Margined

func (g *Group) Margined() bool

Margined returns whether the Group has margins around its child.

func (*Group) SetChild

func (g *Group) SetChild(child Control)

SetChild sets the Group's child to child. If child is nil, the Group will not have a child.

func (*Group) SetMargined

func (g *Group) SetMargined(margined bool)

SetMargined controls whether the Group has margins around its child. The size of the margins are determined by the OS and its best practices.

func (*Group) SetTitle

func (g *Group) SetTitle(title string)

SetTitle sets the Group's title to title.

func (*Group) Show

func (g *Group) Show()

Show shows the Group.

func (*Group) Title

func (g *Group) Title() string

Title returns the Group's title.

type Label

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

Label is a Control that represents a line of text that cannot be interacted with. TODO rest of documentation.

func NewLabel

func NewLabel(text string) *Label

NewLabel creates a new Label with the given text.

func (*Label) Destroy

func (l *Label) Destroy()

Destroy destroys the Label.

func (*Label) Disable

func (l *Label) Disable()

Disable disables the Label.

func (*Label) Enable

func (l *Label) Enable()

Enable enables the Label.

func (*Label) Handle

func (l *Label) Handle() uintptr

Handle returns the OS-level handle associated with this Label. On Windows this is an HWND of a standard Windows API STATIC class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkLabel. On OS X this is a pointer to a NSTextField.

func (*Label) Hide

func (l *Label) Hide()

Hide hides the Label.

func (*Label) LibuiControl

func (l *Label) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*Label) SetText

func (l *Label) SetText(text string)

SetText sets the Label's text to text.

func (*Label) Show

func (l *Label) Show()

Show shows the Label.

func (*Label) Text

func (l *Label) Text() string

Text returns the Label's text.

type LineCap

type LineCap int

TODO

TODO disclaimer TODO rename these to put LineCap at the beginning? or just Cap?

const (
	FlatCap LineCap = iota
	RoundCap
	SquareCap
)

type LineJoin

type LineJoin int

TODO

TODO disclaimer

const (
	MiterJoin LineJoin = iota
	RoundJoin
	BevelJoin
)

type Matrix

type Matrix struct {
	M11 float64
	M12 float64
	M21 float64
	M22 float64
	M31 float64
	M32 float64
}

TODO TODO should the methods of these return self for chaining?

func NewMatrix

func NewMatrix() *Matrix

TODO identity matrix

func (*Matrix) Invert

func (m *Matrix) Invert() bool

TODO

If m is not invertible, false is returned and m is left unchanged.

func (*Matrix) Invertible

func (m *Matrix) Invertible() bool

TODO

func (*Matrix) Multiply

func (m *Matrix) Multiply(m2 *Matrix)

TODO

func (*Matrix) Rotate

func (m *Matrix) Rotate(x float64, y float64, amount float64)

TODO

func (*Matrix) Scale

func (m *Matrix) Scale(xCenter float64, yCenter float64, x float64, y float64)

TODO

func (*Matrix) SetIdentity

func (m *Matrix) SetIdentity()

TODO

func (*Matrix) Skew

func (m *Matrix) Skew(x float64, y float64, xamount float64, yamount float64)

TODO

func (*Matrix) TransformPoint

func (m *Matrix) TransformPoint(x float64, y float64) (xout float64, yout float64)

TODO unimplemented

func (*Matrix) TransformSize

func (m *Matrix) TransformSize(x float64, y float64) (xout float64, yout float64)

TODO unimplemented

func (*Matrix) Translate

func (m *Matrix) Translate(x float64, y float64)

TODO

type Modifiers

type Modifiers uint

TODO document

Note: these must be numerically identical to their libui equivalents.

const (
	Ctrl Modifiers = 1 << iota
	Alt
	Shift
	Super
)

type MultilineEntry

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

MultilineEntry is a Control that represents a space that the user can type multiple lines of text into.

func NewMultilineEntry

func NewMultilineEntry() *MultilineEntry

NewMultilineEntry creates a new MultilineEntry.

func NewMultilineNonWrappingEntry

func NewMultilineNonWrappingEntry() *MultilineEntry

NewMultilineNonWrappingEntry creates a new MultilineEntry.

func (*MultilineEntry) Append

func (e *MultilineEntry) Append(text string)

Append text to the MultilineEntry's text.

func (*MultilineEntry) Destroy

func (e *MultilineEntry) Destroy()

Destroy destroys the MultilineEntry.

func (*MultilineEntry) Disable

func (e *MultilineEntry) Disable()

Disable disables the MultilineEntry.

func (*MultilineEntry) Enable

func (e *MultilineEntry) Enable()

Enable enables the MultilineEntry.

func (*MultilineEntry) Handle

func (e *MultilineEntry) Handle() uintptr

Handle returns the OS-level handle associated with this MultilineEntry.

func (*MultilineEntry) Hide

func (e *MultilineEntry) Hide()

Hide hides the MultilineEntry.

func (*MultilineEntry) LibuiControl

func (e *MultilineEntry) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*MultilineEntry) OnChanged

func (e *MultilineEntry) OnChanged(f func(*MultilineEntry))

OnChanged registers f to be run when the user makes a change to the MultilineEntry. Only one function can be registered at a time.

func (*MultilineEntry) ReadOnly

func (e *MultilineEntry) ReadOnly() bool

ReadOnly returns whether the MultilineEntry can be changed.

func (*MultilineEntry) SetReadOnly

func (e *MultilineEntry) SetReadOnly(ro bool)

SetReadOnly sets whether the MultilineEntry can be changed.

func (*MultilineEntry) SetText

func (e *MultilineEntry) SetText(text string)

SetText sets the MultilineEntry's text to text.

func (*MultilineEntry) Show

func (e *MultilineEntry) Show()

Show shows the MultilineEntry.

func (*MultilineEntry) Text

func (e *MultilineEntry) Text() string

Text returns the MultilineEntry's text.

type Path

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

Path represents a geometric path in a drawing context. This is the basic unit of drawing: all drawing operations consist of forming a path, then stroking, filling, or clipping to that path. A path is an OS resource; you must explicitly free it when finished. Paths consist of multiple figures. Once you have added all the figures to a path, you must "end" the path to make it ready to draw with. TODO rewrite all that

Or more visually, the lifecycle of a Path is

p := NewPath()
for every figure {
	p.NewFigure(...) // or NewFigureWithArc
	p.LineTo(...)    // any number of these in any order
	p.ArcTo(...)
	p.BezierTo(...)
	if figure should be closed {
		p.CloseFigure()
	}
}
p.End()
// ...
dp.Context.Stroke(p, ...) // any number of these in any order
dp.Context.Fill(p, ...)
dp.Context.Clip(p)
// ...
p.Free() // when done with the path

A Path also defines its fill mode. (This should ideally be a fill parameter, but some implementations prevent it.) TODO talk about fill modes

func NewPath

func NewPath(fillMode FillMode) *Path

NewPath creates a new Path with the given fill mode.

func (*Path) AddRectangle

func (p *Path) AddRectangle(x float64, y float64, width float64, height float64)

AddRectangle creates a new figure in the Path that consists entirely of a rectangle whose top-left corner is at the given point and whose size is the given size. The rectangle is a closed figure; you must either start a new figure or end the Path after calling this method.

func (*Path) ArcTo

func (p *Path) ArcTo(xCenter float64, yCenter float64, radius float64, startAngle float64, sweep float64, isNegative bool)

ArcTo adds a circular arc to the current figure of the Path. You pass it the center of the arc, its radius in radians, the starting angle (couterclockwise) in radians, and the number of radians the arc should sweep (counterclockwise). A line segment is drawn from the current point to the start of the arc. The current point is set to the end of the arc.

func (*Path) BezierTo

func (p *Path) BezierTo(c1x float64, c1y float64, c2x float64, c2y float64, endX float64, endY float64)

BezierTo adds a cubic Bezier curve to the current figure of the Path. Its start point is the current point. c1x and c1y are the first control point. c2x and c2y are the second control point. endX and endY are the end point. The current point is set to the end point.

func (*Path) CloseFigure

func (p *Path) CloseFigure()

CloseFigure draws a line segment from the current point of the current figure of the Path back to its initial point. After calling this, the current figure is over and you must either start a new figure or end the Path. If this is not called and you start a new figure or end the Path, then the current figure will not have this closing line segment added to it (but the figure will still be over).

func (*Path) End

func (p *Path) End()

End ends the current Path. You cannot add figures to a Path that has been ended. You cannot draw with a Path that has not been ended.

func (*Path) Free

func (p *Path) Free()

Free destroys a Path. After calling Free the Path cannot be used.

func (*Path) LineTo

func (p *Path) LineTo(x float64, y float64)

LineTo adds a line to the current figure of the Path starting from the current point and ending at the given point. The current point is set to the ending point.

func (*Path) NewFigure

func (p *Path) NewFigure(x float64, y float64)

NewFigure starts a new figure in the Path. The current point is set to the given point.

func (*Path) NewFigureWithArc

func (p *Path) NewFigureWithArc(xCenter float64, yCenter float64, radius float64, startAngle float64, sweep float64, isNegative bool)

NewFigureWithArc starts a new figure in the Path and adds an arc as the first element of the figure. Unlike ArcTo, NewFigureWithArc does not draw an initial line segment. Otherwise, see ArcTo.

type ProgressBar

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

ProgressBar is a Control that represents a horizontal bar that is filled in progressively over time as a process completes.

func NewProgressBar

func NewProgressBar() *ProgressBar

NewProgressBar creates a new ProgressBar.

func (*ProgressBar) Destroy

func (p *ProgressBar) Destroy()

Destroy destroys the ProgressBar.

func (*ProgressBar) Disable

func (p *ProgressBar) Disable()

Disable disables the ProgressBar.

func (*ProgressBar) Enable

func (p *ProgressBar) Enable()

Enable enables the ProgressBar.

func (*ProgressBar) Handle

func (p *ProgressBar) Handle() uintptr

Handle returns the OS-level handle associated with this ProgressBar. On Windows this is an HWND of a standard Windows API PROGRESS_CLASS class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkProgressBar. On OS X this is a pointer to a NSProgressIndicator.

func (*ProgressBar) Hide

func (p *ProgressBar) Hide()

Hide hides the ProgressBar.

func (*ProgressBar) LibuiControl

func (p *ProgressBar) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*ProgressBar) SetValue

func (p *ProgressBar) SetValue(value int)

SetValue sets the ProgressBar's currently displayed percentage to value. value must be between 0 and 100 inclusive.

func (*ProgressBar) Show

func (p *ProgressBar) Show()

Show shows the ProgressBar.

type RadioButtons

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

RadioButtons is a Control that represents a set of checkable buttons from which exactly one may be chosen by the user.

func NewRadioButtons

func NewRadioButtons() *RadioButtons

NewRadioButtons creates a new RadioButtons.

func (*RadioButtons) Append

func (r *RadioButtons) Append(text string)

Append adds the named button to the end of the RadioButtons. If this button is the first button, it is automatically selected.

func (*RadioButtons) Destroy

func (r *RadioButtons) Destroy()

Destroy destroys the RadioButtons.

func (*RadioButtons) Disable

func (r *RadioButtons) Disable()

Disable disables the RadioButtons.

func (*RadioButtons) Enable

func (r *RadioButtons) Enable()

Enable enables the RadioButtons.

func (*RadioButtons) Handle

func (r *RadioButtons) Handle() uintptr

Handle returns the OS-level handle associated with this RadioButtons. On Windows this is an HWND of a libui-internal class; its child windows are instances of the standard Windows API BUTTON class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkBox containing GtkRadioButtons. On OS X this is a pointer to a NSView with each radio button as a NSButton subview.

func (*RadioButtons) Hide

func (r *RadioButtons) Hide()

Hide hides the RadioButtons.

func (*RadioButtons) LibuiControl

func (r *RadioButtons) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*RadioButtons) OnSelected

func (r *RadioButtons) OnSelected(f func(*RadioButtons))

OnSelected registers f to be run when the user selects an item in the RadioButtons. Only one function can be registered at a time.

func (*RadioButtons) Selected

func (r *RadioButtons) Selected() int

Selected returns the index of the currently selected item in the RadioButtons.

func (*RadioButtons) SetSelected

func (r *RadioButtons) SetSelected(index int)

SetSelected sets the currently select item in the RadioButtons to index.

func (*RadioButtons) Show

func (r *RadioButtons) Show()

Show shows the RadioButtons.

type Separator

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

Separator is a Control that represents a horizontal line that visually separates controls.

func NewHorizontalSeparator

func NewHorizontalSeparator() *Separator

NewSeparator creates a new horizontal Separator.

func (*Separator) Destroy

func (s *Separator) Destroy()

Destroy destroys the Separator.

func (*Separator) Disable

func (s *Separator) Disable()

Disable disables the Separator.

func (*Separator) Enable

func (s *Separator) Enable()

Enable enables the Separator.

func (*Separator) Handle

func (s *Separator) Handle() uintptr

Handle returns the OS-level handle associated with this Separator. On Windows this is an HWND of a standard Windows API STATIC class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkSeparator. On OS X this is a pointer to a NSBox.

func (*Separator) Hide

func (s *Separator) Hide()

Hide hides the Separator.

func (*Separator) LibuiControl

func (s *Separator) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*Separator) Show

func (s *Separator) Show()

Show shows the Separator.

type Slider

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

Slider is a Control that represents a horizontal bar that represents a range of integers. The user can drag a pointer on the bar to select an integer.

func NewSlider

func NewSlider(min int, max int) *Slider

NewSlider creates a new Slider. If min >= max, they are swapped.

func (*Slider) Destroy

func (s *Slider) Destroy()

Destroy destroys the Slider.

func (*Slider) Disable

func (s *Slider) Disable()

Disable disables the Slider.

func (*Slider) Enable

func (s *Slider) Enable()

Enable enables the Slider.

func (*Slider) Handle

func (s *Slider) Handle() uintptr

Handle returns the OS-level handle associated with this Slider. On Windows this is an HWND of a standard Windows API TRACKBAR_CLASS class (as provided by Common Controls version 6). On GTK+ this is a pointer to a GtkScale. On OS X this is a pointer to a NSSlider.

func (*Slider) Hide

func (s *Slider) Hide()

Hide hides the Slider.

func (*Slider) LibuiControl

func (s *Slider) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*Slider) OnChanged

func (s *Slider) OnChanged(f func(*Slider))

OnChanged registers f to be run when the user changes the value of the Slider. Only one function can be registered at a time.

func (*Slider) SetValue

func (s *Slider) SetValue(value int)

SetText sets the Slider's current value to value.

func (*Slider) Show

func (s *Slider) Show()

Show shows the Slider.

func (*Slider) Value

func (s *Slider) Value() int

Value returns the Slider's current value.

type Spinbox

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

Spinbox is a Control that represents a space where the user can enter integers. The space also comes with buttons to add or subtract 1 from the integer.

func NewSpinbox

func NewSpinbox(min int, max int) *Spinbox

NewSpinbox creates a new Spinbox. If min >= max, they are swapped.

func (*Spinbox) Destroy

func (s *Spinbox) Destroy()

Destroy destroys the Spinbox.

func (*Spinbox) Disable

func (s *Spinbox) Disable()

Disable disables the Spinbox.

func (*Spinbox) Enable

func (s *Spinbox) Enable()

Enable enables the Spinbox.

func (*Spinbox) Handle

func (s *Spinbox) Handle() uintptr

Handle returns the OS-level handle associated with this Spinbox. On Windows this is an HWND of a standard Windows API EDIT class (as provided by Common Controls version 6). Due to various limitations which affect the lifetime of the associated Common Controls version 6 UPDOWN_CLASS window that provides the buttons, there is no way to access it. On GTK+ this is a pointer to a GtkSpinButton. On OS X this is a pointer to a NSView that contains a NSTextField and a NSStepper as subviews.

func (*Spinbox) Hide

func (s *Spinbox) Hide()

Hide hides the Spinbox.

func (*Spinbox) LibuiControl

func (s *Spinbox) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*Spinbox) OnChanged

func (s *Spinbox) OnChanged(f func(*Spinbox))

OnChanged registers f to be run when the user changes the value of the Spinbox. Only one function can be registered at a time.

func (*Spinbox) SetValue

func (s *Spinbox) SetValue(value int)

SetText sets the Spinbox's current value to value.

func (*Spinbox) Show

func (s *Spinbox) Show()

Show shows the Spinbox.

func (*Spinbox) Value

func (s *Spinbox) Value() int

Value returns the Spinbox's current value.

type StrokeParams

type StrokeParams struct {
	Cap        LineCap
	Join       LineJoin
	Thickness  float64
	MiterLimit float64
	Dashes     []float64
	DashPhase  float64
}

TODO

type Tab

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

Tab is a Control that holds tabbed pages of Controls. Each tab has a label. The user can click on the tabs themselves to switch pages. Individual pages can also have margins.

func NewTab

func NewTab() *Tab

NewTab creates a new Tab.

func (*Tab) Append

func (t *Tab) Append(name string, child Control)

Append adds the given page to the end of the Tab.

func (*Tab) Delete

func (t *Tab) Delete(n int)

Delete deletes the nth page of the Tab.

func (*Tab) Destroy

func (t *Tab) Destroy()

Destroy destroys the Tab. If the Tab has pages, Destroy calls Destroy on the pages's Controls as well.

func (*Tab) Disable

func (t *Tab) Disable()

Disable disables the Tab.

func (*Tab) Enable

func (t *Tab) Enable()

Enable enables the Tab.

func (*Tab) Handle

func (t *Tab) Handle() uintptr

Handle returns the OS-level handle associated with this Tab. On Windows this is an HWND of a standard Windows API WC_TABCONTROL class (as provided by Common Controls version 6). The pages are not children of this window and there currently is no way to directly access them. On GTK+ this is a pointer to a GtkNotebook. On OS X this is a pointer to a NSTabView.

func (*Tab) Hide

func (t *Tab) Hide()

Hide hides the Tab.

func (*Tab) InsertAt

func (t *Tab) InsertAt(name string, n int, child Control)

InsertAt adds the given page to the Tab such that it is the nth page of the Tab (starting at 0).

func (*Tab) LibuiControl

func (t *Tab) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Tab. This is only used by package ui itself and should not be called by programs.

func (*Tab) Margined

func (t *Tab) Margined(n int) bool

Margined returns whether page n (starting at 0) of the Tab has margins around its child.

func (*Tab) NumPages

func (t *Tab) NumPages() int

NumPages returns the number of pages in the Tab.

func (*Tab) SetMargined

func (t *Tab) SetMargined(n int, margined bool)

SetMargined controls whether page n (starting at 0) of the Tab has margins around its child. The size of the margins are determined by the OS and its best practices.

func (*Tab) Show

func (t *Tab) Show()

Show shows the Tab.

type TextItalic

type TextItalic int

TextItalic defines the various text italic modes.

TODO disclaimer

const (
	TextItalicNormal  TextItalic = iota
	TextItalicOblique            // merely slanted text
	TextItalicItalic             // true italics
)

type TextLayout

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

TextLayout is the entry point for formatting a block of text to be drawn onto a DrawContext.

The block of text to lay out and the default font that is used if no font attributes are applied to a given character are provided at TextLayout creation time and cannot be changed later. However, you may add attributes to various points of the text at any time, even after drawing the text once (unlike a DrawPath). Some of these attributes also have initial values; refer to each method to see what they are.

The block of text can either be a single line or multiple word-wrapped lines, each with a given maximum width.

func NewTextLayout

func NewTextLayout(text string, defaultFont *Font, width float64) *TextLayout

NewTextLayout creates a new TextLayout. For details on the width parameter, see SetWidth.

func (*TextLayout) Extents

func (l *TextLayout) Extents() (width float64, height float64)

Extents returns the width and height that the TextLayout will actually take up when drawn. This measures full line allocations, even if no glyph reaches to the top of its ascent or bottom of its descent; it does not return a "best fit" rectnagle for the points that are actually drawn.

For a single-line TextLayout (where the width is negative), if there are no font changes throughout the TextLayout, then the height returned by TextLayout is equivalent to the sum of the ascent and descent of its default font's metrics. Or in other words, after

f := ui.LoadClosestFont(...)
l := ui.NewTextLayout("text", f, -1)
metrics := f.Metrics()
_, height := l.Extents()

metrics.Ascent+metrics.Descent and height are equivalent.

func (*TextLayout) Free

func (l *TextLayout) Free()

Free destroys a TextLayout. After calling Free the TextLayout cannot be used.

func (*TextLayout) SetWidth

func (l *TextLayout) SetWidth(width float64)

SetWidth sets the maximum width of the lines of text in a TextLayout. If the given width is negative, then the TextLayout will draw as a single line of text instead.

type TextStretch

type TextStretch int

TextStretch defines the various text stretches, in order of increasing wideness.

Note that if you leave this field unset, it will default to TextStretchUltraCondensed. If you want the normal font stretch, explicitly use the constant TextStretchNormal instead. TODO realign these?

TODO disclaimer

const (
	TextStretchUltraCondensed TextStretch = iota
	TextStretchExtraCondensed
	TextStretchCondensed
	TextStretchSemiCondensed
	TextStretchNormal
	TextStretchSemiExpanded
	TextStretchExpanded
	TextStretchExtraExpanded
	TextStretchUltraExpanded
)

type TextWeight

type TextWeight int

TextWeight defines the various text weights, in order of increasing weight.

Note that if you leave this field unset, it will default to TextWeightThin. If you want the normal font weight, explicitly use the constant TextWeightNormal instead. TODO realign these?

TODO disclaimer

const (
	TextWeightThin TextWeight = iota
	TextWeightUltraLight
	TextWeightLight
	TextWeightBook
	TextWeightNormal
	TextWeightMedium
	TextWeightSemiBold
	TextWeightBold
	TextWeightUtraBold
	TextWeightHeavy
	TextWeightUltraHeavy
)

type Window

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

Window is a Control that represents a top-level window. A Window contains one child Control that occupies the entirety of the window. Though a Window is a Control, a Window cannot be the child of another Control.

func NewWindow

func NewWindow(title string, width int, height int, hasMenubar bool) *Window

NewWindow creates a new Window.

func (*Window) Center

func (w *Window) Center()

Center centers the Window.

func (*Window) Destroy

func (w *Window) Destroy()

Destroy destroys the Window. If the Window has a child, Destroy calls Destroy on that as well.

func (*Window) Disable

func (w *Window) Disable()

Disable disables the Window.

func (*Window) Enable

func (w *Window) Enable()

Enable enables the Window.

func (*Window) GetContentSize

func (w *Window) GetContentSize() (width, height int)

GetContentSize change the window content size.

func (*Window) Handle

func (w *Window) Handle() uintptr

Handle returns the OS-level handle associated with this Window. On Windows this is an HWND of a libui-internal class. On GTK+ this is a pointer to a GtkWindow. On OS X this is a pointer to a NSWindow.

func (*Window) Hide

func (w *Window) Hide()

Hide hides the Window.

func (*Window) LibuiControl

func (w *Window) LibuiControl() uintptr

LibuiControl returns the libui uiControl pointer that backs the Window. This is only used by package ui itself and should not be called by programs.

func (*Window) Margined

func (w *Window) Margined() bool

Margined returns whether the Window has margins around its child.

func (*Window) OnClosing

func (w *Window) OnClosing(f func(*Window) bool)

OnClosing registers f to be run when the user clicks the Window's close button. Only one function can be registered at a time. If f returns true, the window is destroyed with the Destroy method. If f returns false, or if OnClosing is never called, the window is not destroyed and is kept visible.

func (*Window) SetChild

func (w *Window) SetChild(child Control)

SetChild sets the Window's child to child. If child is nil, the Window will not have a child.

func (*Window) SetContentSize

func (w *Window) SetContentSize(width, height int)

SetContentSize change the window content size.

func (*Window) SetMargined

func (w *Window) SetMargined(margined bool)

SetMargined controls whether the Window has margins around its child. The size of the margins are determined by the OS and its best practices.

func (*Window) SetPosition

func (w *Window) SetPosition(x, y int)

SetPosition changes the position of the Window.

func (*Window) SetTitle

func (w *Window) SetTitle(title string)

SetTitle sets the Window's title to title.

func (*Window) Show

func (w *Window) Show()

Show shows the Window. It uses the OS conception of "presenting" the Window, whatever that may be on a given OS.

func (*Window) Title

func (w *Window) Title() string

Title returns the Window's title.

Notes

Bugs

  • Ideally, all the drawing APIs should be in another package ui/draw (they all have the "uiDraw" prefix in C to achieve a similar goal of avoiding confusing programmers via namespace pollution); managing the linkage of the libui shared library itself across multiple packages is likely going to be a pain, though. (Custom controls implemented using libui won't have this issue, as they *should* only need libui present when linking the shared object, not when linking the Go wrapper. I'm not sure; I'd have to find out first.)

Jump to

Keyboard shortcuts

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