sparta

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

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

Go to latest
Published: Jun 13, 2014 License: BSD-2-Clause Imports: 2 Imported by: 1

README

Sparta

Sparta is a generic (and spartan) widget toolkit for window based guis. Current implementation has been tested in linux (32 and 64 bits) as well as in windows (32 bits).

It is a "classic" toolkit in the sense that uses the traditional system of creating widget and answering events through an event function.

Setup

go get github.com/js-arias/sparta

In the main package initialize the init package that will authomatically setup the corresponding backend.

After all widgets are defined, the main loop of the program is executed using the Run() function.

The package defines a basic widget interface, some simple widgets are included in the widget package that can be used for applications, or can be used as an example of how the widgets can be implemented.

Properties

To kept the API small, instead of a lot of function calls, each widget has a set of properties, some are common to all or most all widgets, and others just limited to particular widgets. The properties can be set using SetProperty and Property functions.

Events

It is possible to define a function based on an event. The basic events are produced from the Mouse, the Keyboard, Exposition and Configuration of the widget, as well as from other widgets or the main process.

Examples

The directory example provide a collection of diferent examples that shows the usage of the library.

Authorship and license

Copyright (c) 2014, J. Salvador Arias jsalarias@gmail.com All rights reserved. Distributed under BSD2 license that can be found in the LICENSE file.

Documentation

Overview

Package sparta provides a generic (and spartan) widget toolkit for window-based guis.

Index

Constants

View Source
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.

View Source
const (
	MouseLeft  MouseButton = 1
	MouseRight             = 2
	MouseWheel             = 3
	Mouse2                 = 4
)

Mouse button values.

View Source
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.

View Source
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.

View Source
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

View Source
var (
	WidthUnit  int
	HeightUnit int
)

Sparta generic units

View Source
var Close = func() {
	panic("undefined Close in the backend")
}

Close closes the application.

View Source
var NewWindow = func(w Widget) {
	panic("undefined NewWindow in the backend")
}

NewWindow assigns a new window to a widget.

View Source
var Run = func() {
	panic("undefined Run in the backend")
}

Run executes the program event loop.

View Source
var SendEvent = func(dest Widget, comm CommandEvent) {
	panic("undefined Close in the backend")
}

SendEvent sends a command event to an specified window.

Functions

func Block

func Block(b Widget)

Block block the application from input.

func IsBlock

func IsBlock() bool

IsBlock returns true if the application is blocked from input.

func IsBlocker

func IsBlocker(w Widget) bool

IsBlocker returns true if the widget (or its parent) is blocking the input.

func Unblock

func Unblock(req Widget)

Unblock opens the application for user input. The widget requesting the unblocking must be the same or a child of the widget that request the blocking.

Types

type CloseEvent

type CloseEvent struct{}

A CloseEvent is sent when the window is closed.

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

type ConfigureEvent struct {
	Rect image.Rectangle
}

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 EventType

type EventType string

A EventType is a type of event.

type ExposeEvent

type ExposeEvent struct {
	Rect image.Rectangle
}

An ExposeEvent is sent when the window has exposed.

type Key

type Key int

Key is a keyboard key.

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 MouseButton

type MouseButton int

MouseButton is a mouse button.

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 Property

type Property string

Property is a windget property.

type StateKey

type StateKey int

StateKey is an state key.

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.

Jump to

Keyboard shortcuts

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