ui

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

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

Go to latest
Published: Nov 24, 2019 License: MPL-2.0 Imports: 10 Imported by: 0

README

Deprecated. Future work moved to github.com/richardwilkes/ux

A user interface for Go.

C Dependencies:

On macOS:
brew install cairo pango
On Linux:
sudo apt install pkg-config libcairo2-dev libpango1.0-dev libx11-dev libxcursor-dev
On Windows:

Install MSYS2 then install pkg-config and gtk3

pacman -S mingw64/mingw-w64-x86_64-pkg-config mingw64/mingw-w64-x86_64-gtk3

Go Dependencies:

go get -u github.com/richardwilkes/toolbox

This is very much a work in progress. My intent is to make this work for Mac, Linux & Windows. At the moment, the Mac and Linux implementations are functional, if not complete.

Widgets that have been implemented:

  • Button
  • CheckBox
  • ImageButton
  • Label
  • List
  • Menus
  • PopupMenu
  • ProgressBar
  • RadioButton
  • ScrollArea
  • ScrollBar
  • Slider
  • Separator
  • SplitPanel
  • Table
  • TabPanel
  • TextArea
  • TextField
  • ToolBar
  • Tree
  • Web View (only macOS implemented at the moment)

Top-level windows and dialogs:

  • Dialog
  • FileDialog
  • Window

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sizes

func Sizes(widget Widget, hint geom.Size) (min, pref, max geom.Size)

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

Types

type Widget

type Widget interface {
	event.Target

	// Sizer returns the Sizer for this widget, if any.
	Sizer() layout.Sizer
	// SetSizer sets the Sizer for this widget. May be nil.
	SetSizer(sizer layout.Sizer)

	// Layout returns the Layout for this widget, if any.
	Layout() layout.Layout
	// SetLayout sets the Layout for this widget. May be nil.
	SetLayout(layout layout.Layout)
	// NeedLayout returns true if this widget needs to have its children laid
	// out.
	NeedLayout() bool
	// SetNeedLayout sets the whether this widget needs to have its children
	// lait out.
	SetNeedLayout(needLayout bool)
	// LayoutData returns the layout data, if any, associated with this widget.
	LayoutData() interface{}
	// SetLayoutData sets layout data on this widget. May be nil.
	SetLayoutData(data interface{})
	// ValidateLayout triggers any layout that needs to be run by this widget or
	// its children.
	ValidateLayout()

	// Border returns the Border for this widget, if any.
	Border() border.Border
	// SetBorder sets the Border for this widget. May be nil.
	SetBorder(border border.Border)

	// Repaint marks this widget for painting at the next update.
	Repaint()
	// RepaintBounds marks the area 'bounds' in local coordinates within the
	// widget for painting at the next update.
	RepaintBounds(bounds geom.Rect)
	// Paint is called by its owning window when a widget needs to be drawn. 'g'
	// is the graphics context to use. It has already had its clip set to the
	// 'dirty' rectangle. 'dirty' is the area that needs to be drawn.
	Paint(g *draw.Graphics, dirty geom.Rect)

	// Enabled returns true if this widget is currently enabled and can receive
	// events.
	Enabled() bool
	// SetEnabled sets this widget's enabled state.
	SetEnabled(enabled bool)
	// Focusable returns true if this widget can have the keyboard focus.
	Focusable() bool
	// SetFocusable sets whether this widget can have the keyboard focus.
	SetFocusable(focusable bool)
	// Focused returns true if this widget has the keyboard focus.
	Focused() bool
	// GrabFocusWhenClickedOn returns true if this widget wants to have the
	// keyboard focus when it is clicked on.
	GrabFocusWhenClickedOn() bool
	// SetGrabFocusWhenClickedOn sets whether this widget wants to have the
	// keyboard focus when it is clicked on.
	SetGrabFocusWhenClickedOn(grabsFocus bool)

	// Children returns the direct descendents of this widget.
	Children() []Widget
	// IndexOfChild returns the index of the specified child, or -1 if the
	// passed in widget is not a child of this widget.
	IndexOfChild(child Widget) int
	// AddChild adds 'child' as a child of this widget, removing it from any
	// previous parent it may have had.
	AddChild(child Widget)
	// AddChildAtIndex adds 'child' as a child of this widget 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.
	AddChildAtIndex(child Widget, index int)
	// RemoveChild removes 'child' from this widget. If 'child' is not a direct
	// descendent of this widget, nothing happens.
	RemoveChild(child Widget)
	// RemoveChildAtIndex removes the child widget at 'index' from this widget.
	// If 'index' is out of range, nothing happens.
	RemoveChildAtIndex(index int)
	// RemoveFromParent removes this widget from its parent, if any.
	RemoveFromParent()
	// Parent returns the parent widget, if any.
	Parent() Widget
	// SetParent sets `parent` to be the parent of this widget. It does not add
	// this widget to the parent as a child. Call AddChild or AddChildAtIndex
	// for that.
	SetParent(parent Widget)
	// Window returns the containing window, if any.
	Window() Window
	// RootOfWindow returns true if this widget is the root widget of a window.
	RootOfWindow() bool

	// Bounds returns the location and size of the widget in its parent's
	// coordinate system.
	Bounds() geom.Rect
	// LocalBounds returns the location and size of the widget in local
	// coordinates.
	LocalBounds() geom.Rect
	// LocalInsetBounds returns the location and size of the widget in local
	// coordinates after adjusting for any Border it may have.
	LocalInsetBounds() geom.Rect
	// SetBounds sets the location and size of the widget in its parent's
	// coordinate system.
	SetBounds(bounds geom.Rect)
	// Location returns the location of this widget in its parent's coordinate
	// system.
	Location() geom.Point
	// SetLocation sets the location of this widget in its parent's coordinate
	// system.
	SetLocation(pt geom.Point)
	// Size returns the size of this widget.
	Size() geom.Size
	// SetSize sets the size of this widget.
	SetSize(size geom.Size)

	// WidgetAt returns the leaf-most child widget containing 'pt', or this
	// widget if no child is found.
	WidgetAt(pt geom.Point) Widget

	// ToWindow converts widget-local coordinates into window coordinates.
	ToWindow(pt geom.Point) geom.Point
	// FromWindow converts window coordinates into widget-local coordinates.
	FromWindow(pt geom.Point) geom.Point

	// Background returns the background color of this widget.
	Background() color.Color
	// SetBackground sets the background color of this widget.
	SetBackground(color color.Color)
}

A Widget is the basic user interface block that interacts with the user.

type Window

type Window interface {
	event.Target
	// MayClose returns true if the window is permitted to close.
	MayClose() bool
	// AttemptClose closes the window if a Closing event permits it.
	AttemptClose()
	// Close the window.
	Close()
	// Valid returns true if the window is still valid (i.e. has not been
	// closed).
	Valid() bool
	// Title returns the title of this window.
	Title() string
	// SetTitle sets the title of this window.
	SetTitle(title string)
	// Frame 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).
	Frame() geom.Rect
	// SetFrame sets the boundaries of the frame of this window.
	SetFrame(bounds geom.Rect)
	// ContentFrame returns the boundaries of the root widget of this window.
	ContentFrame() geom.Rect
	// SetContentFrame sets the boundaries of the root widget of this window.
	SetContentFrame(bounds geom.Rect)
	// ContentLocalFrame returns the local boundaries of the root widget of
	// this window.
	ContentLocalFrame() geom.Rect
	// Pack sets the window's content size to match the preferred size of the
	// root widget.
	Pack()
	// MenuBar returns the menu bar for the window. On some platforms, the menu
	// bar is a global entity and the same value will be returned for all
	// windows.
	MenuBar() menu.Bar
	// Content returns the content widget of the window. This is not the root
	// widget of the window, which contains both the content widget and the menu
	// bar, for platforms that hold the menu bar within the window.
	Content() Widget
	// SetCursor sets the window's current cursor.
	SetCursor(cur *cursor.Cursor)
	// Focus returns the widget with the keyboard focus in this window.
	Focus() Widget
	// SetFocus sets the keyboard focus to the specified target.
	SetFocus(target Widget)
	// FocusNext moves the keyboard focus to the next focusable widget.
	FocusNext()
	// FocusPrevious moves the keyboard focus to the previous focusable widget.
	FocusPrevious()
	// Focused returns true when this window has the keyboard focus.
	Focused() bool
	// ToFront attempts to bring the window to the foreground and give it the
	// keyboard focus.
	ToFront()
	// Repaint marks this window for painting at the next update.
	Repaint()
	// RepaintBounds marks the specified bounds within the window for painting
	// at the next update.
	RepaintBounds(bounds geom.Rect)
	// FlushPainting causes any areas marked for repainting to be painted.
	FlushPainting()
	// Minimize performs the platform's minimize function on the window.
	Minimize()
	// Zoom performs the platform's zoom funcion on the window.
	Zoom()
	// PlatformPtr returns a pointer to the underlying platform-specific data.
	PlatformPtr() unsafe.Pointer
	// Closable returns true if the window was created with the
	// ClosableWindowMask.
	Closable() bool
	// Minimizable returns true if the window was created with the
	// MiniaturizableWindowMask.
	Minimizable() bool
	// Resizable returns true if the window was created with the
	// ResizableWindowMask.
	Resizable() bool
	// Invoke a task on the UI thread. The task is put into the system event
	// queue and will be run at the next opportunity.
	Invoke(task func())
	// InvokeAfter schedules a task to be run on the UI thread after waiting for
	// the specified duration.
	InvokeAfter(task func(), after time.Duration)
}

Window defines the methods that all Windows must have.

Jump to

Keyboard shortcuts

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