base

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

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

Go to latest
Published: May 20, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

GoVision

Text User Interface inspired by TurboVision and Windows writing in pure GO build on top of great TCell library.

GoVision works by message.

Why another library ?

Mmm... good question. When I was young, I'm fan of Borland TurboPascal and TurboVision and Visual Basic 1.0 for MS-DOS.

I'm also love how Windows works for GUI, by using message.

Installation

go get -u github.com/emeric-martineau/govision

Documentation

Standard component library

Screenshots

License

Apache License 2.0

Other same library

Documentation

Overview

Package base is base package of GoVision.

This package contain TComponent/Component that is root of all GoVision components. Contains also TView/View that is base component of all display component. Application is the main struct to use GoVision.

Index

Constants

View Source
const WaActive uint = 1

WaActive Activated.

View Source
const WaInactive uint = 0

WaInactive Deactivated.

View Source
const WmActivate uint = 16

WmActivate Sent to both the window being activated and the window being deactivated. Value can be WaActive or WaInactive.

View Source
const WmChangeBounds uint = 7

WmChangeBounds send to component to change size, or move.

View Source
const WmCreate uint = 9

WmCreate sent when you have create windows and want add in list.

View Source
const WmDestroy uint = 10

WmDestroy sent when you want remove windows from list and let GC remove it.

View Source
const WmDraw uint = 4

WmDraw draw component. Becarefull! If you send to one component, only this component and his child draw.

View Source
const WmEnable uint = 1

WmEnable send to enable or disable a component.

View Source
const WmKey uint = 2

WmKey when a key is pressed.

View Source
const WmLButtonDown uint = 12

WmLButtonDown send when left button pressed on window beneath cursor.

View Source
const WmLButtonUp uint = 13

WmLButtonUp send when left button released on window beneath cursor.

View Source
const WmMouse uint = 11

WmMouse send when mouse occure. Generally manage by Application struct. If nothing can be done with, send to Window struct.

View Source
const WmMouseEnter uint = 17

WmMouseEnter sent when mouse enter to TView.

View Source
const WmMouseLeave uint = 18

WmMouseLeave sent when mouse leave to TView.

View Source
const WmNull uint = 0

WmNull is empty message, ignore it (internal use only). This is never use by GoVision.

View Source
const WmQuit uint = 6

WmQuit force application to shutdown.

View Source
const WmRButtonDown uint = 14

WmRButtonDown send when right button pressed on window beneath cursor.

View Source
const WmRButtonUp uint = 15

WmRButtonUp send when right button released on window beneath cursor.

View Source
const WmScreenResize uint = 3

WmScreenResize when a screen size change.

View Source
const WmTimer uint = 8

WmTimer send to Timer parent component if OnTimer is nil.

View Source
const WmUser uint = ^uint(0) / 2

WmUser allow user to have own message.

View Source
const WmZorderChange uint = 5

WmZorderChange send to parent when you change Zorder of children.

Variables

This section is empty.

Functions

func ApplicationHandler

func ApplicationHandler() uuid.UUID

ApplicationHandler is use to send message to application only.

func BroadcastHandler

func BroadcastHandler() uuid.UUID

BroadcastHandler return value for broadcast all component.

func InHorizontal

func InHorizontal(x int, r Rect) bool

InHorizontal return true if x in rect.

func InVertical

func InVertical(y int, r Rect) bool

InVertical return true if y in rect.

func MaxInt

func MaxInt(a int, b int) int

MaxInt return greater integer.

func MinInt

func MinInt(a int, b int) int

MinInt return less integer.

func PrintStringOnScreen

func PrintStringOnScreen(screen tcell.Screen, bc tcell.Color, fc tcell.Color, x int, y int, msg string)

PrintStringOnScreen helper to print string. For Debug only.

Types

type Application

type Application struct {

	// Quit application on Ctrl+C.
	ExitOnCtrlC bool
	// Show text mouse cursor.
	ShowMouseCursor bool
	// contains filtered or unexported fields
}

Application is base struct for create text UI.

func NewApplication

func NewApplication(config ApplicationConfig) Application

NewApplication create a text application.

func (*Application) AddWindow

func (a *Application) AddWindow(w TView)

AddWindow add window to list. If first window, she become the main window.

func (*Application) Canvas

func (a *Application) Canvas() TCanvas

Canvas return application confguration.

func (*Application) Init

func (a *Application) Init() error

Init initialize screen (color, style...).

func (*Application) MainWindow

func (a *Application) MainWindow() TView

MainWindow return main windows.

func (*Application) Run

func (a *Application) Run()

Run application and wait event.

func (*Application) SetEncodingFallback

func (a *Application) SetEncodingFallback(fb tcell.EncodingFallback)

SetEncodingFallback changes the behavior of GetEncoding when a suitable encoding is not found. The default is EncodingFallbackFail, which causes GetEncoding to simply return nil.

func (*Application) WindowsList

func (a *Application) WindowsList() []TView

WindowsList return the current windows list. Becarefull, each call create a new array to return.

type ApplicationConfig

type ApplicationConfig struct {
	// Default style screen application.
	ScreenStyle ApplicationStyle
	// Screen of application.
	Screen tcell.Screen
	// Message bus.
	Message Bus
}

ApplicationConfig is configuration of application.

func CreateDefaultApplicationConfig

func CreateDefaultApplicationConfig() ApplicationConfig

CreateDefaultApplicationConfig create application config for almost case.

type ApplicationStyle

type ApplicationStyle struct {
	// Default screen style.
	Style tcell.Style
	// Default screen text color.
	ForegroundColor tcell.Color
	// Default screen background color.
	BackgroundColor tcell.Color
}

ApplicationStyle is style of screen for application.

type Bus

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

Bus bus message.

func NewBus

func NewBus() Bus

NewBus create a new bus.

func (Bus) Channel

func (b Bus) Channel() *chan Message

Channel a event in bus.

func (Bus) Send

func (b Bus) Send(e Message)

Send a event in bus.

type ByZorder

type ByZorder []TComponent

ByZorder implements sort.Interface based on the zorder field.

func (ByZorder) Len

func (a ByZorder) Len() int

func (ByZorder) Less

func (a ByZorder) Less(i, j int) bool

func (ByZorder) Swap

func (a ByZorder) Swap(i, j int)

type Canvas

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

Canvas is virtal screen to draw components.

func (*Canvas) CreateCanvasFrom

func (c *Canvas) CreateCanvasFrom(r Rect) TCanvas

CreateCanvasFrom create a sub-canvas for `r` parameter.

func (*Canvas) Fill

func (c *Canvas) Fill(bounds Rect)

Fill zone of canvas.

func (*Canvas) PrintChar

func (c *Canvas) PrintChar(x int, y int, char rune)

PrintChar print a charactere.

func (*Canvas) PrintCharWithBrush

func (c *Canvas) PrintCharWithBrush(x int, y int, char rune, brush tcell.Style)

PrintCharWithBrush print a charactere with brush.

func (*Canvas) SetBrush

func (c *Canvas) SetBrush(b tcell.Style)

SetBrush set the brush to draw.

func (*Canvas) UpdateBounds

func (c *Canvas) UpdateBounds(r Rect)

UpdateBounds call when component move or resize.

type Component

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

Component is the base object of all widget.

func NewComponent

func NewComponent(name string, message Bus) Component

NewComponent create new component.

func (*Component) AddChild

func (c *Component) AddChild(child TComponent)

AddChild add a child component.

func (*Component) Children

func (c *Component) Children() []TComponent

Children return children list.

func (*Component) GetEnabled

func (c *Component) GetEnabled() bool

GetEnabled return if component is enable.

func (*Component) GetMessageBus

func (c *Component) GetMessageBus() Bus

GetMessageBus return application bus.

func (*Component) GetOnEnabled

func (c *Component) GetOnEnabled() OnEnabled

GetOnEnabled return function to be execute when receive enable message.

func (*Component) GetOnReceiveMessage

func (c *Component) GetOnReceiveMessage() OnReceiveMessage

GetOnReceiveMessage return function to be execute when receive message.

func (*Component) GetParent

func (c *Component) GetParent() TComponent

GetParent return parent of component. Nil -> no parent, maybe root component.

func (*Component) GetZorder

func (c *Component) GetZorder() int

GetZorder order of message.

func (*Component) HandleMessage

func (c *Component) HandleMessage(msg Message) bool

HandleMessage is use to manage message and give message to children.

func (*Component) Handler

func (c *Component) Handler() uuid.UUID

Handler return handler value to send message to this component.

func (*Component) Name

func (c *Component) Name() string

Name return the name of component.

func (*Component) RemoveChild

func (c *Component) RemoveChild(child TComponent)

RemoveChild remove the child.

func (*Component) SetEnabled

func (c *Component) SetEnabled(status bool)

SetEnabled active or disable component.

func (*Component) SetOnEnabled

func (c *Component) SetOnEnabled(f OnEnabled)

SetOnEnabled set function when set enable.

func (*Component) SetOnReceiveMessage

func (c *Component) SetOnReceiveMessage(f OnReceiveMessage)

SetOnReceiveMessage set function when receive message.

func (*Component) SetParent

func (c *Component) SetParent(p TComponent)

SetParent set parent of component. Nil -> no parent, maybe root component.

func (*Component) SetZorder

func (c *Component) SetZorder(i int)

SetZorder order of message. Remember you must send WmZorderChange message to his parent.

type Message

type Message struct {
	Handler uuid.UUID
	Type    uint
	Value   interface{}
}

Message is data structure for any message.

func BuildActivateMessage

func BuildActivateMessage(handler uuid.UUID) Message

BuildActivateMessage send message to windows gains focus.

func BuildChangeBoundsMessage

func BuildChangeBoundsMessage(handler uuid.UUID, bounds Rect) Message

BuildChangeBoundsMessage return a message to change bounds of component.

func BuildClickMouseMessage

func BuildClickMouseMessage(handler uuid.UUID, ev *tcell.EventMouse, side uint) Message

BuildClickMouseMessage send message to windows gains focus.

func BuildDesactivateMessage

func BuildDesactivateMessage(handler uuid.UUID) Message

BuildDesactivateMessage send message to windows gains focus.

func BuildDrawMessage

func BuildDrawMessage(handler uuid.UUID) Message

BuildDrawMessage return a message to force a component to redraw.

func BuildEmptyMessage

func BuildEmptyMessage() Message

BuildEmptyMessage build empty message.

func BuildKeyMessage

func BuildKeyMessage(event *tcell.EventKey) Message

BuildKeyMessage build a message for keyboard event.

func BuildMouseEnterMessage

func BuildMouseEnterMessage(handler uuid.UUID, x, y int) Message

BuildMouseEnterMessage send message to windows when mouse enter.

func BuildMouseLeaveMessage

func BuildMouseLeaveMessage(handler uuid.UUID) Message

BuildMouseLeaveMessage send message to windows when mouse enter.

func BuildScreenResizeMessage

func BuildScreenResizeMessage(screen tcell.Screen) Message

BuildScreenResizeMessage build a resize message broadcast.

func BuildZorderMessage

func BuildZorderMessage(handler uuid.UUID) Message

BuildZorderMessage return a message to change Zorder.

type OnActivate

type OnActivate func(bool)

OnActivate is call when set or leave focus

type OnChangeBounds

type OnChangeBounds func(Rect)

OnChangeBounds is call when change bounds message receive.

type OnDraw

type OnDraw func(TView)

OnDraw is call when change enable.

type OnEnabled

type OnEnabled func(TComponent, bool) bool

OnEnabled is call when change enable.

type OnReceiveMessage

type OnReceiveMessage func(TComponent, Message) bool

OnReceiveMessage is call when component receive message and you want overide behavior. Return true to stop message propagation.

type Rect

type Rect struct {
	X      int
	Y      int
	Width  int
	Height int
}

Rect is the base object for placement or size of widget.

func Intersect

func Intersect(r1 Rect, r2 Rect) Rect

Intersect return interesection of rectangle. If no intersection, return Rect{X:0, Y:0, Width:0, Height: 0}.

type TCanvas

type TCanvas interface {
	// Set brush property.
	SetBrush(b tcell.Style)
	// Create a canvas.
	CreateCanvasFrom(r Rect) TCanvas
	// Print char with current brush property.
	PrintChar(x int, y int, char rune)
	// Print char with brush.
	PrintCharWithBrush(x int, y int, char rune, brush tcell.Style)
	// Update position.
	UpdateBounds(r Rect)
	// Fill zone of canvas.
	Fill(bounds Rect)
}

TCanvas is virtal screen to draw components.

func NewCanvas

func NewCanvas(parent TCanvas, r Rect) TCanvas

NewCanvas create a sub canvas.

type TComponent

type TComponent interface {
	// Call when receive a message.
	// Return true if stop loop because message are manage by client.
	HandleMessage(Message) bool
	// Name of component.
	Name() string
	// Handler of component (UUID).
	Handler() uuid.UUID
	// Enable component.
	SetEnabled(bool)
	GetEnabled() bool
	// Parent component.
	SetParent(TComponent)
	GetParent() TComponent
	// Children component.
	AddChild(TComponent)
	RemoveChild(TComponent)
	Children() []TComponent
	// Odrer of draw.
	SetZorder(int)
	GetZorder() int
	// Return application configuration.
	GetMessageBus() Bus
	// Set function when receive message.
	SetOnReceiveMessage(OnReceiveMessage)
	// GetOnReceiveMessage return function to be execute when receive message.
	GetOnReceiveMessage() OnReceiveMessage
	// Set function when set enable.
	SetOnEnabled(OnEnabled)
	// GetOnEnabled return function to be execute when receive enable message.
	GetOnEnabled() OnEnabled
}

TComponent is the base object of all widget.

type TView

type TView interface {
	TComponent
	// External component size.
	SetBounds(Rect)
	GetBounds() Rect
	// Focus component.
	SetFocused(bool)
	GetFocused() bool
	// Visible component.
	SetVisible(bool)
	GetVisible() bool
	// Client size.
	GetClientBounds() Rect
	// Color of component.
	GetBackgroundColor() tcell.Color
	SetBackgroundColor(tcell.Color)
	GetForegroundColor() tcell.Color
	SetForegroundColor(tcell.Color)
	// Draw component
	Draw()
	// Canvas of view.
	Canvas() TCanvas
	// Client canvas of view.
	ClientCanvas() TCanvas
	SetOnDraw(OnDraw)
	GetOnDraw() OnDraw
	// Change bounds
	SetOnChangeBounds(OnChangeBounds)
	GetOnChangeBounds() OnChangeBounds
	// Activate
	SetOnActivate(OnActivate)
	GetOnActivate() OnActivate
}

TView is the base object of all visual widget.

type View

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

View is the base object of all visual widget.

func NewView

func NewView(name string, message Bus, parentCanvas TCanvas) View

NewView create new timer.

func (*View) AddChild

func (v *View) AddChild(c TComponent)

AddChild add a child to component.

func (*View) Canvas

func (v *View) Canvas() TCanvas

Canvas of view.

func (*View) Children

func (v *View) Children() []TComponent

Children return list of children of component.

func (*View) ClientCanvas

func (v *View) ClientCanvas() TCanvas

ClientCanvas return client canvas of view.

func (*View) Draw

func (v *View) Draw()

Draw the view.

func (*View) GetBackgroundColor

func (v *View) GetBackgroundColor() tcell.Color

GetBackgroundColor return background color.

func (*View) GetBounds

func (v *View) GetBounds() Rect

GetBounds return view size.

func (*View) GetClientBounds

func (v *View) GetClientBounds() Rect

GetClientBounds return client size.

func (*View) GetEnabled

func (v *View) GetEnabled() bool

GetEnabled return is component is enable.

func (*View) GetFocused

func (v *View) GetFocused() bool

GetFocused return true if component has focus.

func (*View) GetForegroundColor

func (v *View) GetForegroundColor() tcell.Color

GetForegroundColor return text color.

func (*View) GetMessageBus

func (v *View) GetMessageBus() Bus

GetMessageBus return application config.

func (*View) GetOnActivate

func (v *View) GetOnActivate() OnActivate

GetOnActivate return OnActivate event.

func (*View) GetOnChangeBounds

func (v *View) GetOnChangeBounds() OnChangeBounds

GetOnChangeBounds return OnChangeBounds event.

func (*View) GetOnDraw

func (v *View) GetOnDraw() OnDraw

GetOnDraw get ondraw callback.

func (*View) GetOnEnabled

func (v *View) GetOnEnabled() OnEnabled

GetOnEnabled return function to be execute when receive enable message.

func (*View) GetOnReceiveMessage

func (v *View) GetOnReceiveMessage() OnReceiveMessage

GetOnReceiveMessage return function to be execute when receive message.

func (*View) GetParent

func (v *View) GetParent() TComponent

GetParent get parent component.

func (*View) GetVisible

func (v *View) GetVisible() bool

GetVisible if component is visible.

func (*View) GetZorder

func (v *View) GetZorder() int

GetZorder return odrer of draw.

func (*View) HandleMessage

func (v *View) HandleMessage(msg Message) bool

HandleMessage is use to manage message.

func (*View) Handler

func (v *View) Handler() uuid.UUID

Handler of component (UUID).

func (*View) Name

func (v *View) Name() string

Name of component.

func (*View) RemoveChild

func (v *View) RemoveChild(c TComponent)

RemoveChild remove a child to component.

func (*View) SetBackgroundColor

func (v *View) SetBackgroundColor(c tcell.Color)

SetBackgroundColor change background color.

func (*View) SetBounds

func (v *View) SetBounds(r Rect)

SetBounds set view size.

func (*View) SetEnabled

func (v *View) SetEnabled(e bool)

SetEnabled enable component.

func (*View) SetFocused

func (v *View) SetFocused(f bool)

SetFocused of component.

func (*View) SetForegroundColor

func (v *View) SetForegroundColor(c tcell.Color)

SetForegroundColor change text color.

func (*View) SetOnActivate

func (v *View) SetOnActivate(f OnActivate)

SetOnActivate set OnActivate event.

func (*View) SetOnChangeBounds

func (v *View) SetOnChangeBounds(f OnChangeBounds)

SetOnChangeBounds set OnChangeBounds event.

func (*View) SetOnDraw

func (v *View) SetOnDraw(f OnDraw)

SetOnDraw set ondraw callback.

func (*View) SetOnEnabled

func (v *View) SetOnEnabled(f OnEnabled)

SetOnEnabled set function when set enable.

func (*View) SetOnReceiveMessage

func (v *View) SetOnReceiveMessage(f OnReceiveMessage)

SetOnReceiveMessage set function when receive message.

func (*View) SetParent

func (v *View) SetParent(p TComponent)

SetParent set parent component.

func (*View) SetVisible

func (v *View) SetVisible(s bool)

SetVisible if component is visible.

func (*View) SetZorder

func (v *View) SetZorder(o int)

SetZorder set the new odrer of draw.

Directories

Path Synopsis
_demo
Package components is standard component library of GoVision.
Package components is standard component library of GoVision.

Jump to

Keyboard shortcuts

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