ux

package module
v0.0.0-...-955f326 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2020 License: MPL-2.0 Imports: 27 Imported by: 0

README

ux

Go user experience framework for macOS (and at some point in the future, Windows and Linux).

An example application can be found in the example directory.

Notes
  • Windows and Linux platform support is not currently functional. Windows can be created but drawing is largely broken or non-existent.
  • All target platforms can be built from macOS. Unfortunately, due to the need for cgo on macOS, the macOS target platform cannot be built on other platforms.

Documentation

Index

Constants

View Source
const (
	ButtonLeft  = 0
	ButtonRight = 1
)

Constants for mouse buttons.

View Source
const (
	TitledWindowMask StyleMask = 1 << iota
	ClosableWindowMask
	MinimizableWindowMask
	ResizableWindowMask
	NoInternalMenuWindowMask = 1 << 30 // Has no effect on macOS
	BorderlessWindowMask     = 0
	StdWindowMask            = TitledWindowMask | ClosableWindowMask | MinimizableWindowMask | ResizableWindowMask
)

Possible values for the StyleMask.

Variables

View Source
var (
	// WillFinishStartupCallback is called right before application startup
	// has completed. This is a good point to create any windows your app
	// wants to display.
	WillFinishStartupCallback func()

	// DidFinishStartupCallback is called once application startup has
	// completed and it is about to start servicing the event loop.
	DidFinishStartupCallback func()

	// WillActivateCallback is called right before the application is
	// activated.
	WillActivateCallback func()

	// DidActivateCallback is called once the application is activated.
	DidActivateCallback func()

	// WillDeactivateCallback is called right before the application is
	// deactivated.
	WillDeactivateCallback func()

	// DidDeactivateCallback is called once the application is deactivated.
	DidDeactivateCallback func()

	// OpenURLsCallback is called when the application is asked to open one or
	// more URLs by the OS or external application.
	OpenURLsCallback func(urls []string)

	// OSThemeChangedCallback is called when the OS theme is changed.
	OSThemeChangedCallback func()

	// QuitAfterLastWindowClosedCallback is called when the last window is
	// closed to determine if the application should quit as a result.
	QuitAfterLastWindowClosedCallback func() bool

	// CheckQuitCallback is called when termination has been requested.
	CheckQuitCallback func() QuitResponse

	// QuittingCallback is called when the app will in fact terminate.
	QuittingCallback func()
)
View Source
var (
	// TooltipDelay holds the delay before a tooltip will be shown.
	TooltipDelay = 1500 * time.Millisecond
	// TooltipDismissal holds the delay before a tooltip will be dismissed.
	TooltipDismissal = 3 * time.Second
)

Functions

func AppWindowsToFront

func AppWindowsToFront()

AppWindowsToFront attempts to bring all of the application's windows to the foreground.

func AttemptQuit

func AttemptQuit()

AttemptQuit initiates the termination sequence.

func HideApp

func HideApp()

HideApp will hide the application on platforms where that is supported.

func HideOtherApps

func HideOtherApps()

HideOtherApps will hide all other applications on platforms where that is supported.

func Invoke

func Invoke(taskFunction func())

Invoke a task on the UI thread. The task is put into the system event queue and will be run at the next opportunity.

func InvokeAfter

func InvokeAfter(taskFunction func(), after time.Duration)

InvokeAfter schedules a task to be run on the UI thread after waiting for the specified duration.

func MayQuitNow

func MayQuitNow(quit bool)

MayQuitNow resumes the termination sequence that was delayed when Later is returned from the CheckQuitCallback. Passing in false for the quit parameter will cancel the termination sequence while true will allow it to proceed.

func SetInvokeRecoverCallback

func SetInvokeRecoverCallback(recoveryHandler errs.RecoveryHandler)

SetInvokeRecoverCallback sets a callback that will be called should an invoked task panic. If no recover callback is set, the panic will be silently swallowed.

func ShowAllApps

func ShowAllApps()

ShowAllApps will unhide any hidden applications on platforms where that is supported.

func Start

func Start()

Start the application. This function does NOT return. No calls to anything in the ux package tree should be made before this call, although setting the various callbacks above can and should be done before this call.

func WindowContentRectForFrameRect

func WindowContentRectForFrameRect(frame geom.Rect, style StyleMask) geom.Rect

WindowContentRectForFrameRect determines the content rect for a window based on the given frame rect and window style.

func WindowCount

func WindowCount() int

WindowCount returns the number of windows that are open.

func WindowFrameRectForContentRect

func WindowFrameRectForContentRect(content geom.Rect, style StyleMask) geom.Rect

WindowFrameRectForContentRect determines the frame rect for a window based on the given content rect and window style.

Types

type DragInfo

type DragInfo struct {
	Sequence            int
	SourceOperationMask DragOperation
	DragX               float64
	DragY               float64
	DragImageX          float64
	DragImageY          float64
	ValidItemsForDrop   int
	ItemTypes           []datatypes.DataType
	DataForType         func(dataType datatypes.DataType) [][]byte
}

DragInfo holds information about the current drag.

func (*DragInfo) ApplyOffset

func (di *DragInfo) ApplyOffset(dx, dy float64)

ApplyOffset applies the delta to the drag and drag image positions.

func (*DragInfo) FirstTypePresent

func (di *DragInfo) FirstTypePresent(dataType ...datatypes.DataType) datatypes.DataType

FirstTypePresent returns the first data type that matches the available data types, or returns datatypes.None.

func (*DragInfo) HasType

func (di *DragInfo) HasType(dataType datatypes.DataType) bool

HasType returns true if the specified data type is present.

type DragOperation

type DragOperation = uint32

DragOperation holds the type of drag operation.

const (
	DragOperationCopy DragOperation = 1 << iota
	DragOperationLink
	DragOperationGeneric
	DragOperationPrivate
	DragOperationMove
	DragOperationDelete
	DragOperationNone  DragOperation = 0
	DragOperationEvery DragOperation = math.MaxUint32
)

Possible DragOperation values.

type OSWindow

type OSWindow = *xwindow.Window

type Panel

type Panel struct {
	Tooltip *Panel

	DrawCallback                        func(gc draw.Context, dirty geom.Rect, inLiveResize bool)
	DrawOverCallback                    func(gc draw.Context, dirty geom.Rect, inLiveResize bool)
	GainedFocusCallback                 func()
	LostFocusCallback                   func()
	MouseDownCallback                   func(where geom.Point, button, clickCount int, mod keys.Modifiers) bool
	MouseDragCallback                   func(where geom.Point, button int, mod keys.Modifiers)
	MouseUpCallback                     func(where geom.Point, button int, mod keys.Modifiers)
	MouseEnterCallback                  func(where geom.Point, mod keys.Modifiers)
	MouseMoveCallback                   func(where geom.Point, mod keys.Modifiers)
	MouseExitCallback                   func()
	MouseWheelCallback                  func(where, delta geom.Point, mod keys.Modifiers) bool
	KeyDownCallback                     func(keyCode int, ch rune, mod keys.Modifiers, repeat bool) bool
	KeyUpCallback                       func(keyCode int, mod keys.Modifiers) bool
	UpdateCursorCallback                func(where geom.Point) *draw.Cursor
	UpdateTooltipCallback               func(where geom.Point, suggestedAvoid geom.Rect) geom.Rect
	DragEnteredCallback                 func(dragInfo *DragInfo) DragOperation
	DragUpdatedCallback                 func(dragInfo *DragInfo) DragOperation
	DragExitedCallback                  func()
	DragEndedCallback                   func()
	DropIsAcceptableCallback            func(dragInfo *DragInfo) bool
	DropCallback                        func(dragInfo *DragInfo) bool
	DropFinishedCallback                func(dragInfo *DragInfo)
	CanPerformCmdCallback               func(source interface{}, id int) bool
	PerformCmdCallback                  func(source interface{}, id int)
	FrameChangeCallback                 func()
	FrameChangeInChildHierarchyCallback func(panel *Panel)
	ScrollRectIntoViewCallback          func(rect geom.Rect) bool
	ParentChangedCallback               func()
	NeedsLayout                         bool
	// contains filtered or unexported fields
}

Panel is the basic user interface element that interacts with the user.

func NewPanel

func NewPanel() *Panel

NewPanel creates a new panel.

func (*Panel) AddChild

func (p *Panel) AddChild(child *Panel)

AddChild adds child to this panel, removing it from any previous parent it may have had.

func (*Panel) AddChildAtIndex

func (p *Panel) AddChildAtIndex(child *Panel, index int)

AddChildAtIndex adds child to this panel at the index, removing it from any previous parent it may have had. Passing in a negative value for the index will add it to the end.

func (*Panel) AsPanel

func (p *Panel) AsPanel() *Panel

AsPanel returns this object as a panel.

func (*Panel) Border

func (p *Panel) Border() border.Border

Border returns the border for this panel, if any.

func (*Panel) Children

func (p *Panel) Children() []*Panel

Children returns the direct descendents of this panel.

func (*Panel) ChildrenForLayout

func (p *Panel) ChildrenForLayout() []layout.Layoutable

ChildrenForLayout is the same as calling Children(), but returns them as layout.Layoutable objects instead.

func (*Panel) ClientData

func (p *Panel) ClientData() map[string]interface{}

ClientData returns a map of client data for this panel.

func (*Panel) ContentRect

func (p *Panel) ContentRect(includeBorder bool) geom.Rect

ContentRect returns the location and size of the panel in local coordinates.

func (*Panel) Draw

func (p *Panel) Draw(gc draw.Context, dirty geom.Rect, inLiveResize bool)

Draw is called by its owning window when a panel needs to be drawn. The gc has already had its clip set to the dirty rectangle.

func (*Panel) Enabled

func (p *Panel) Enabled() bool

Enabled returns true if this panel is currently enabled and can receive events.

func (*Panel) FlushDrawing

func (p *Panel) FlushDrawing()

FlushDrawing is a convenience for calling the parent window's (if any) FlushDrawing() method.

func (*Panel) Focusable

func (p *Panel) Focusable() bool

Focusable returns true if this panel can have the keyboard focus.

func (*Panel) Focused

func (p *Panel) Focused() bool

Focused returns true if this panel has the keyboard focus.

func (*Panel) FrameRect

func (p *Panel) FrameRect() geom.Rect

FrameRect returns the location and size of the panel in its parent's coordinate system.

func (*Panel) ID

func (p *Panel) ID() uint64

ID returns the unique ID for the panel.

func (*Panel) IndexOfChild

func (p *Panel) IndexOfChild(child *Panel) int

IndexOfChild returns the index of the specified child, or -1 if the passed in panel is not a child of this panel.

func (*Panel) InitTypeAndID

func (p *Panel) InitTypeAndID(self interface{})

InitTypeAndID initializes the panel with the appropriate self-identification information.

func (*Panel) Is

func (p *Panel) Is(other *Panel) bool

Is returns true if this panel is the other panel.

func (*Panel) Layout

func (p *Panel) Layout() layout.Layout

Layout returns the Layout for this panel, if any.

func (*Panel) LayoutData

func (p *Panel) LayoutData() interface{}

LayoutData returns the layout data, if any, associated with this panel.

func (*Panel) MarkForLayoutAndRedraw

func (p *Panel) MarkForLayoutAndRedraw()

MarkForLayoutAndRedraw marks this panel as needing to be laid out as well as redrawn at the next update.

func (*Panel) MarkForRedraw

func (p *Panel) MarkForRedraw()

MarkForRedraw marks this panel for drawing at the next update.

func (*Panel) MarkRectForRedraw

func (p *Panel) MarkRectForRedraw(rect geom.Rect)

MarkRectForRedraw marks the rect in local coordinates within the panel for drawing at the next update.

func (*Panel) PanelAt

func (p *Panel) PanelAt(pt geom.Point) *Panel

PanelAt returns the leaf-most child panel containing the point, or this panel if no child is found.

func (*Panel) Parent

func (p *Panel) Parent() *Panel

Parent returns the parent panel, if any.

func (*Panel) PointFromRoot

func (p *Panel) PointFromRoot(pt geom.Point) geom.Point

PointFromRoot converts root coordinates (i.e. window-local, when rooted within a window) into panel-local coordinates.

func (*Panel) PointToRoot

func (p *Panel) PointToRoot(pt geom.Point) geom.Point

PointToRoot converts panel-local coordinates into root coordinates, which when rooted within a window, will be window-local coordinates.

func (*Panel) RectFromRoot

func (p *Panel) RectFromRoot(rect geom.Rect) geom.Rect

RectFromRoot converts root coordinates (i.e. window-local, when rooted within a window) into panel-local coordinates.

func (*Panel) RectToRoot

func (p *Panel) RectToRoot(rect geom.Rect) geom.Rect

RectToRoot converts panel-local coordinates into root coordinates, which when rooted within a window, will be window-local coordinates.

func (*Panel) RemoveAllChildren

func (p *Panel) RemoveAllChildren()

RemoveAllChildren removes all child panels from this panel.

func (*Panel) RemoveChild

func (p *Panel) RemoveChild(child *Panel)

RemoveChild removes 'child' from this panel. If 'child' is not a direct descendent of this panel, nothing happens.

func (*Panel) RemoveChildAtIndex

func (p *Panel) RemoveChildAtIndex(index int)

RemoveChildAtIndex removes the child panel at 'index' from this panel. If 'index' is out of range, nothing happens.

func (*Panel) RemoveFromParent

func (p *Panel) RemoveFromParent()

RemoveFromParent removes this panel from its parent, if any.

func (*Panel) RequestFocus

func (p *Panel) RequestFocus()

RequestFocus attempts to make this panel the keyboard focus.

func (*Panel) ScrollIntoView

func (p *Panel) ScrollIntoView()

ScrollIntoView attempts to scroll this panel into the current view if it is not already there, using ScrollAreas in this panel's hierarchy.

func (*Panel) ScrollRectIntoView

func (p *Panel) ScrollRectIntoView(rect geom.Rect)

ScrollRectIntoView attempts to scroll the rect (in coordinates local to this panel) into the current view if it is not already there, using ScrollAreas in this panel's hierarchy.

func (*Panel) Self

func (p *Panel) Self() interface{}

Self returns the actual panel.

func (*Panel) SetBorder

func (p *Panel) SetBorder(b border.Border) *Panel

SetBorder sets the border for this panel. May be nil.

func (*Panel) SetEnabled

func (p *Panel) SetEnabled(enabled bool) *Panel

SetEnabled sets this panel's enabled state.

func (*Panel) SetFocusable

func (p *Panel) SetFocusable(focusable bool) *Panel

SetFocusable sets whether this panel can have the keyboard focus.

func (*Panel) SetFrameRect

func (p *Panel) SetFrameRect(rect geom.Rect)

SetFrameRect sets the location and size of the panel in its parent's coordinate system.

func (*Panel) SetLayout

func (p *Panel) SetLayout(lay layout.Layout)

SetLayout sets the Layout for this panel. May be nil.

func (*Panel) SetLayoutData

func (p *Panel) SetLayoutData(data interface{})

SetLayoutData sets layout data on this panel. May be nil.

func (*Panel) SetSizer

func (p *Panel) SetSizer(sizer layout.Sizer)

SetSizer sets the sizer for this panel. May be nil.

func (*Panel) Sizer

func (p *Panel) Sizer() layout.Sizer

Sizer returns the sizer for this panel, if any.

func (*Panel) Sizes

func (p *Panel) Sizes(hint geom.Size) (min, pref, max geom.Size)

Sizes returns the minimum, preferred, and maximum sizes the panel wishes to be. It does this by first asking the panel's layout. If no layout is present, then the panel's sizer is asked. If no sizer is present, then it finally uses a default set of sizes that are used for all panels.

func (*Panel) String

func (p *Panel) String() string

func (*Panel) ValidateLayout

func (p *Panel) ValidateLayout()

ValidateLayout performs any layout that needs to be run by this panel or its children.

func (*Panel) Window

func (p *Panel) Window() *Window

Window returns the containing window, if any.

type QuitResponse

type QuitResponse int

QuitResponse is used to respond to requests for app termination.

const (
	Cancel QuitResponse = iota
	Now
	Later // Must make a call to MayQuitNow() at some point in the future.
)

Possible termination responses

type StyleMask

type StyleMask int

StyleMask controls the look and capabilities of a window.

type Window

type Window struct {

	// MayCloseCallback is called when the user has requested that the window
	// be closed. Return true to permit it, false to cancel the operation.
	// Defaults to always returning true.
	MayCloseCallback func() bool
	// WillCloseCallback is called just prior to the window closing.
	WillCloseCallback func()
	// GainedFocusCallback is called when the keyboard focus is gained on this
	// window.
	GainedFocusCallback func()
	// LostFocusCallback is called when the keyboard focus is lost from this
	// window.
	LostFocusCallback func()
	// MouseDownCallback is called when the mouse is pressed within this
	// window.
	MouseDownCallback func(where geom.Point, button, clickCount int, mod keys.Modifiers)
	// MouseDragCallback is called when the mouse is dragged after being
	// pressed within this window.
	MouseDragCallback func(where geom.Point, button int, mod keys.Modifiers)
	// MouseUpCallback is called when the mouse is released after being
	// pressed within this window.
	MouseUpCallback func(where geom.Point, button int, mod keys.Modifiers)
	// MouseEnterCallback is called when the mouse enters this window.
	MouseEnterCallback func(where geom.Point, mod keys.Modifiers)
	// MouseMoveCallback is called when the mouse moves within this window.
	MouseMoveCallback func(where geom.Point, mod keys.Modifiers)
	// MouseExitCallback is called when the mouse exits this window.
	MouseExitCallback func()
	// MouseWheelCallback is called when the mouse wheel is rotated over this
	// window.
	MouseWheelCallback func(where, delta geom.Point, mod keys.Modifiers)
	// KeyDownCallback is called when a key is pressed in this window.
	KeyDownCallback func(keyCode int, ch rune, mod keys.Modifiers, repeat bool)
	// KeyDownCallback is called when a key is released in this window.
	KeyUpCallback func(keyCode int, mod keys.Modifiers)
	// DragEnteredCallback is called when a drag enters this window.
	DragEnteredCallback func(di *DragInfo) DragOperation
	// DragUpdatedCallback is called when a drag moves within this window or
	// the drag operation changes.
	DragUpdatedCallback func(di *DragInfo) DragOperation
	// DragExitedCallback is called when a drag exits the window.
	DragExitedCallback func()
	// DragEndedCallback is called when a drag ends.
	DragEndedCallback func()
	// DropIsAcceptableCallback is called when the drag is dropped to
	// determine if it is still valid to drop here.
	DropIsAcceptableCallback func(di *DragInfo) bool
	// DropCallback is called to perform the actual drop. Returns true on
	// success.
	DropCallback func(di *DragInfo) bool
	// DropFinishedCallback is called when the drop concludes.
	DropFinishedCallback func(di *DragInfo)
	// contains filtered or unexported fields
}

Window holds window information.

func NewWindow

func NewWindow(title string, frame geom.Rect, style StyleMask) (*Window, error)

NewWindow creates a new window.

func WindowWithFocus

func WindowWithFocus() *Window

WindowWithFocus returns the window that currently has the keyboard focus, or nil if none of your application's windows has the keyboard focus.

func Windows

func Windows() []*Window

Windows returns a slice containing the current set of open windows.

func (*Window) AttemptClose

func (w *Window) AttemptClose()

AttemptClose closes the window if permitted.

func (*Window) Background

func (w *Window) Background() draw.Ink

Background returns the background of this window.

func (*Window) ClearTooltip

func (w *Window) ClearTooltip()

ClearTooltip clears any existing tooltip and resets the timer.

func (*Window) ClientData

func (w *Window) ClientData() map[string]interface{}

ClientData returns a map of client data for this window.

func (*Window) Closable

func (w *Window) Closable() bool

Closable returns true if the window was created with the ClosableWindowMask.

func (*Window) Content

func (w *Window) Content() *Panel

Content returns the content panel for the window.

func (*Window) ContentRect

func (w *Window) ContentRect() geom.Rect

ContentRect returns the boundaries in display coordinates of the window's content area.

func (*Window) Dispose

func (w *Window) Dispose()

Dispose of the window.

func (*Window) Draw

func (w *Window) Draw(gc draw.Context, dirtyRect geom.Rect, inLiveResize bool)

Draw the window contents.

func (*Window) FlushDrawing

func (w *Window) FlushDrawing()

FlushDrawing causes any areas marked for drawing to be drawn now.

func (*Window) Focus

func (w *Window) Focus() *Panel

Focus returns the panel with the keyboard focus in this window.

func (*Window) FocusNext

func (w *Window) FocusNext()

FocusNext moves the keyboard focus to the next focusable panel.

func (*Window) FocusPrevious

func (w *Window) FocusPrevious()

FocusPrevious moves the keyboard focus to the previous focusable panel.

func (*Window) Focused

func (w *Window) Focused() bool

Focused returns true if the window has the current keyboard focus.

func (*Window) FrameRect

func (w *Window) FrameRect() geom.Rect

FrameRect returns the boundaries in display coordinates of the frame of this window (i.e. the area that includes both the content and its border and window controls).

func (*Window) ID

func (w *Window) ID() uint64

ID returns the unique ID for the window.

func (*Window) IsValid

func (w *Window) IsValid() bool

IsValid returns true if the window is still valid (i.e. hasn't been disposed).

func (*Window) MarkForRedraw

func (w *Window) MarkForRedraw()

MarkForRedraw marks this window for drawing at the next update.

func (*Window) MarkRectForRedraw

func (w *Window) MarkRectForRedraw(rect geom.Rect)

MarkRectForRedraw marks the rect in local coordinates within the window for drawing at the next update.

func (*Window) Minimizable

func (w *Window) Minimizable() bool

Minimizable returns true if the window was created with the MinimizableWindowMask.

func (*Window) Minimize

func (w *Window) Minimize()

Minimize performs the minimize function on the window.

func (*Window) MouseLocation

func (w *Window) MouseLocation() geom.Point

MouseLocation returns the current mouse location relative to this window.

func (*Window) OSWindow

func (w *Window) OSWindow() OSWindow

OSWindow returns the underlying OS window object.

func (*Window) Pack

func (w *Window) Pack()

Pack sets the window's content size to match the preferred size of the root panel.

func (*Window) RegisterDragTypes

func (w *Window) RegisterDragTypes(dt ...datatypes.DataType)

RegisterDragTypes registers the data types the window will accept in a drag & drop operation.

func (*Window) Resizable

func (w *Window) Resizable() bool

Resizable returns true if the window was created with the ResizableWindowMask.

func (*Window) RunModal

func (w *Window) RunModal() int

RunModal displays and brings this window to the front, the runs a modal event loop until StopModal is called.

func (*Window) SetBackground

func (w *Window) SetBackground(ink draw.Ink)

SetBackground sets the background of this window.

func (*Window) SetContent

func (w *Window) SetContent(panel *Panel)

SetContent sets the content panel for the window.

func (*Window) SetContentRect

func (w *Window) SetContentRect(rect geom.Rect)

SetContentRect sets the boundaries of the frame of this window by converting the content rect into a suitable frame rect and then applying it to the window.

func (*Window) SetFocus

func (w *Window) SetFocus(target *Panel)

SetFocus sets the keyboard focus to the specified target.

func (*Window) SetFrameRect

func (w *Window) SetFrameRect(rect geom.Rect)

SetFrameRect sets the boundaries of the frame of this window.

func (*Window) SetTitle

func (w *Window) SetTitle(title string)

SetTitle sets the title of this window.

func (*Window) StopModal

func (w *Window) StopModal(code int)

StopModal stops the current modal event loop, closes the window, and propagates the provided code as the result to RunModal().

func (*Window) String

func (w *Window) String() string

func (*Window) Title

func (w *Window) Title() string

Title returns the title of this window.

func (*Window) ToFront

func (w *Window) ToFront()

ToFront attempts to bring the window to the foreground and give it the keyboard focus.

func (*Window) ValidateLayout

func (w *Window) ValidateLayout()

ValidateLayout performs any layout that needs to be run by this window or its children.

func (*Window) Zoom

func (w *Window) Zoom()

Zoom performs the zoom function on the window.

Jump to

Keyboard shortcuts

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