Documentation
¶
Overview ¶
Package sparta provides a generic (and spartan) widget toolkit for window-based guis.
Index ¶
- Constants
- Variables
- func Block(b Widget)
- func IsBlock() bool
- func IsBlocker(w Widget) bool
- func Unblock(req Widget)
- type CloseEvent
- type CommandEvent
- type ConfigureEvent
- type Drawable
- type EventType
- type ExposeEvent
- type Key
- type KeyEvent
- type MouseButton
- type MouseEvent
- type Property
- type StateKey
- type Widget
- type Window
Constants ¶
const ( CloseEv EventType = "close" // close event Command = "command" // command event Configure = "configure" // configure event Expose = "expose" // expose event KeyEv = "key" // key events Mouse = "mouse" // mouse events )
Event types that a window can receive. They are used to define the callbacks.
const ( MouseLeft MouseButton = 1 MouseRight = 2 MouseWheel = 3 Mouse2 = 4 )
Mouse button values.
const ( StateShift StateKey = 1 StateLock = 2 StateCtrl = 4 StateAltGr = 128 StateButtonL = 256 StateButton2 = 512 StateButtonR = 1024 StateAny = 7 | StateAltGr | StateButtonL | StateButton2 | StateButtonR )
State key values.
const ( // flag used to recognize non-char keys KeyNoChar Key = 0x8000 // General keyboard keys KeyBackSpace Key = 0xff08 KeyTab = 0xff09 KeyClear = 0xff0b KeyReturn = 0xff0d KeyPause = 0xff13 KeyScrollLock = 0xff14 KeySysReq = 0xff15 KeyEscape = 0xff1b KeyHome = 0xff50 KeyLeft = 0xff51 KeyUp = 0xff52 KeyRight = 0xff53 KeyDown = 0xff54 KeyPageUp = 0xff55 KeyPageDown = 0xff56 KeyEnd = 0xff57 KeySelect = 0xff60 KeyPrint = 0xff61 KeyExecute = 0xff62 KeyInsert = 0xff63 KeyMenu = 0xff67 KeyHelp = 0xff6a KeyNumLock = 0xff7f KeyShift = 0xffe1 // either one KeyControl = 0xffe3 // either one KeyCapsLock = 0xffe5 KeyAlt = 0xffe9 KeyAltGr = 0xffea KeySuperL = 0xffeb KeySuperR = 0xffec KeyDelete = 0xffff // KeyPad values KeyPadSpace Key = 0xff80 KeyPadTab = 0xff89 KeyPadEnter = 0xff8d KeyPadF1 = 0xff91 KeyPadF2 = 0xff92 KeyPadF3 = 0xff93 KeyPadF4 = 0xff94 KeyPadHome = 0xff95 KeyPadLeft = 0xff96 KeyPadUp = 0xff97 KeyPadRight = 0xff98 KeyPadDown = 0xff99 KeyPadPrior = 0xff9a KeyPadPage_Up = 0xff9a KeyPadNext = 0xff9b KeyPadPage_Down = 0xff9b KeyPadEnd = 0xff9c KeyPadBegin = 0xff9d KeyPadInsert = 0xff9e KeyPadDelete = 0xff9f KeyPadEqual = 0xffbd KeyPadMultiply = 0xffaa KeyPadAdd = 0xffab KeyPadSeparator = 0xffac KeyPadSubtract = 0xffad KeyPadDecimal = 0xffae KeyPadDivide = 0xffaf KeyPad0 = 0xffb0 KeyPad1 = 0xffb1 KeyPad2 = 0xffb2 KeyPad3 = 0xffb3 KeyPad4 = 0xffb4 KeyPad5 = 0xffb5 KeyPad6 = 0xffb6 KeyPad7 = 0xffb7 KeyPad8 = 0xffb8 KeyPad9 = 0xffb9 // Function keys KeyF1 Key = 0xffbe KeyF2 = 0xffbf KeyF3 = 0xffc0 KeyF4 = 0xffc1 KeyF5 = 0xffc2 KeyF6 = 0xffc3 KeyF7 = 0xffc4 KeyF8 = 0xffc5 KeyF9 = 0xffc6 KeyF10 = 0xffc7 KeyF11 = 0xffc8 KeyF12 = 0xffc9 KeyF13 = 0xffca KeyF14 = 0xffcb KeyF15 = 0xffcc KeyF16 = 0xffcd KeyF17 = 0xffce KeyF18 = 0xffcf KeyF19 = 0xffd0 KeyF20 = 0xffd1 KeyF21 = 0xffd2 KeyF22 = 0xffd3 KeyF23 = 0xffd4 KeyF24 = 0xffd5 )
Key values.
const ( // widget title/caption (string) Caption Property = "caption" // children of the window([]Widget) Childs = "childs" // data is the particular data associated with the window Data = "data" // widget geometry (image.Rectangle) Geometry = "geometry" // parent widget (Widget) Parent = "parent" // widget id-name (string) Name = "name" // Background of the window (color.RGBA). This value will be take // efect in the next expose event of the widget. Background = "background" // Foreground of the window (color.RGBA) This value will be take // efect in the next expose event of the widget. Foreground = "foreground" // Border sets a border line around a widget (bool). If true the // widget perimeter will be enmarked. This value will be take // efect in the next expose event of the widget. Border = "border" // Target widget (Widget), used in widgets that sends events to // another widget (such a button). If the target is set to nil, then // the widget will send the events to its parent. Target = "target" )
Properties of a Widget-Window. The type associated with the property is indicated in parentesis.
Variables ¶
var ( WidthUnit int HeightUnit int )
Sparta generic units
var Close = func() { panic("undefined Close in the backend") }
Close closes the application.
var NewWindow = func(w Widget) { panic("undefined NewWindow in the backend") }
NewWindow assigns a new window to a widget.
var Run = func() { panic("undefined Run in the backend") }
Run executes the program event loop.
var SendEvent = func(dest Widget, comm CommandEvent) { panic("undefined Close in the backend") }
SendEvent sends a command event to an specified window.
Functions ¶
Types ¶
type CommandEvent ¶
type CommandEvent struct { Source Widget // widget that issue the command Value int // value identifier of the event }
A CommandEvent is an event sent from goroutines to particular windows.
type ConfigureEvent ¶
A ConfigureEvent is sent when the window change its size.
type Drawable ¶
type Drawable interface { // Draw sets a drawable in a ready to draw mode (true) or ends the // drawing mode (false). Draw(bool) // SetColor sets a temporal drawing color of the drawable. This // values will be valid until a new Expose event will be produced. // If you want to change the values of the window, use "SetProperty". SetColor(Property, color.RGBA) // Text draws a string in the indicated point of the drawable. Text(image.Point, string) // Rectangle draws a rectangle in the drawable. Rectangle(image.Rectangle, bool) // Lines draws one or more lines in the drawable. Lines([]image.Point) // Arc draws an arc in the drawable. Arc(image.Rectangle, float64, float64, bool) // Polygon draws a polygon in the drawable. Polygon([]image.Point, bool) // Pixel draws a pixel in the drawable. Pixel(image.Point) }
Drawable is a screen space to be draw by the backend.
type ExposeEvent ¶
An ExposeEvent is sent when the window has exposed.
type KeyEvent ¶
type KeyEvent struct { // The value k represent key k being pressed. // The value -k represents key k being released. Key Key // State represents the keyboard, button state State StateKey // Loc is the location of the mouse pointer Loc image.Point }
A KeyEvent is sent for a key press or release.
type MouseEvent ¶
type MouseEvent struct { // Button represents the button being pressed or released (negative). Button MouseButton // State represents the keyboard, button state State StateKey // Loc is the location of the mouse pointer. Loc image.Point }
A MouseEvent is sent for a button press or release or for a mouse movement.
type Widget ¶
type Widget interface { // SetWindow is used to set the backend window. SetWindow(Window) // Window returns the backend window. Window() Window // RemoveWindow removes the backend window. RemoveWindow() // Property returns the indicated property of the windget. Property(Property) interface{} // SetProperty sets a property of the winget. SetProperty(Property, interface{}) // Capture sets an event function of the widget. The function // receive a Widget and an interface that represents the event, // this function returns false if the default operation should // be performed. Capture(EventType, func(Widget, interface{}) bool) // OnEvent is used to send a particular event to the widget. OnEvent(interface{}) // Update updates the widget. Update() // Focus set the focus on the widget. Focus() }
Widget is an specific purpouse window.
type Window ¶
type Window interface { Drawable // Close closes the window. Close() // SetProperty sets a window property. SetProperty(Property, interface{}) // Update updates the window content. Update() // Focus set the focus on the window. Focus() }
Window is a backend window that receives events. Most code should use Widget type.
Directories
¶
Path | Synopsis |
---|---|
Package init initializes sparta backend.
|
Package init initializes sparta backend. |
Package widget provides a concrete widgets using the sparta package.
|
Package widget provides a concrete widgets using the sparta package. |
Package win32 defines the windows backend for sparta.
|
Package win32 defines the windows backend for sparta. |
Package x11 defines the x-window backend for sparta.
|
Package x11 defines the x-window backend for sparta. |