spartan

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

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

Go to latest
Published: Dec 16, 2017 License: MIT Imports: 4 Imported by: 0

README

spartan

A windowing toolkit based on termbox. Most of the paradigms used here are inspired from the Android UI system.

Currently Implemented
  • LinearLayout
  • TextView
Example
	app := spartan.New()

	layout := spartan.LinearLayout{
		Direction: direction.Vertical,
		View: spartan.View{
			Width:  size.MatchParent,
			Height: size.MatchParent,
		},
	}

	helloBox := spartan.TextView{
		Text: "Hello, World!",
		View: spartan.View{
			Width:           20,
			Height:          1,
			ForegroundColor: termbox.ColorWhite,
			BackgroundColor: termbox.ColorRed,
		},
	}

	triumphBox := spartan.TextView{
		Text: "This was a triumph",
		View: spartan.View{
			Width:           size.MatchParent,
			Height:          3,
			ForegroundColor: termbox.ColorBlack,
			BackgroundColor: termbox.ColorMagenta,
		},
	}

	noteBox := spartan.TextView{
		Text: "I am making a note here",
		View: spartan.View{
			Width:           6,
			Height:          size.MatchParent,
			LayoutGravity:   gravity.Center,
			ForegroundColor: termbox.ColorRed,
			BackgroundColor: termbox.ColorBlue,
		},
	}

	successBox := spartan.TextView{
		Text: "Huge success",
		View: spartan.View{
			Width:           15,
			Height:          size.MatchParent,
			RightMargin:     10,
			LayoutGravity:   gravity.Right,
			ForegroundColor: termbox.ColorGreen,
			BackgroundColor: termbox.ColorYellow,
		},
	}

	layout.AddChild(&helloBox)
	layout.AddChild(&triumphBox)
	layout.AddChild(&noteBox)
	layout.AddChild(&successBox)

	app.SetContent(&layout)

	eventChannel := make(chan termbox.Event)

	go EventHandler(eventChannel)

	app.Run(eventChannel)

produces the following

Linear layout example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

func New

func New() App

func (App) Redraw

func (a App) Redraw()

func (App) Run

func (a App) Run(eventChannel chan termbox.Event) error

func (*App) SetContent

func (a *App) SetContent(content Drawable)

type Divider

type Divider struct {
	View
	Direction direction.Type
}

func (Divider) Draw

func (d Divider) Draw(left uint32, top uint32, right uint32, bottom uint32)

type Drawable

type Drawable interface {
	Draw(left uint32, top uint32, right uint32, bottom uint32)

	GetLeftMargin() uint32
	GetRightMargin() uint32
	GetTopMargin() uint32
	GetBottomMargin() uint32
	GetHeight() size.Size
	GetWidth() size.Size
	GetLayoutGravity() gravity.Type

	OnStart()
}

type ImageView

type ImageView struct {
	View
	ImagePath string
}

func (ImageView) Draw

func (box ImageView) Draw(left uint32, top uint32, right uint32, bottom uint32)

type LinearLayout

type LinearLayout struct {
	ViewGroup
	View

	Direction  direction.Type
	IsBordered bool
	Title      string
}

func (*LinearLayout) DisableBorder

func (layout *LinearLayout) DisableBorder()

func (LinearLayout) Draw

func (layout LinearLayout) Draw(left uint32, top uint32, right uint32, bottom uint32)

func (*LinearLayout) EnableBorder

func (layout *LinearLayout) EnableBorder()

func (LinearLayout) GetAbsoluteHeight

func (layout LinearLayout) GetAbsoluteHeight() uint32

func (LinearLayout) GetAbsoluteWidth

func (layout LinearLayout) GetAbsoluteWidth() uint32

func (LinearLayout) GetAbsoluteX

func (layout LinearLayout) GetAbsoluteX() uint32

func (LinearLayout) GetAbsoluteY

func (layout LinearLayout) GetAbsoluteY() uint32

func (LinearLayout) OnStart

func (layout LinearLayout) OnStart()

type TextView

type TextView struct {
	View
	Text string
}

func (TextView) Draw

func (box TextView) Draw(left uint32, top uint32, right uint32, bottom uint32)

type View

type View struct {
	Parent          *ViewGroup
	ForegroundColor termbox.Attribute
	BackgroundColor termbox.Attribute

	LeftMargin   uint32
	TopMargin    uint32
	RightMargin  uint32
	BottomMargin uint32

	Width  size.Size
	Height size.Size

	LayoutGravity gravity.Type
}

func (View) GetBottomMargin

func (v View) GetBottomMargin() uint32

func (View) GetHeight

func (v View) GetHeight() size.Size

func (View) GetLayoutGravity

func (v View) GetLayoutGravity() gravity.Type

func (View) GetLeftMargin

func (v View) GetLeftMargin() uint32

func (View) GetRightMargin

func (v View) GetRightMargin() uint32

func (View) GetTopMargin

func (v View) GetTopMargin() uint32

func (View) GetWidth

func (v View) GetWidth() size.Size

func (View) OnStart

func (v View) OnStart()

type ViewGroup

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

func (*ViewGroup) AddChild

func (group *ViewGroup) AddChild(child Drawable)

func (ViewGroup) GetAbsoluteHeight

func (group ViewGroup) GetAbsoluteHeight() uint32

func (ViewGroup) GetAbsoluteWidth

func (group ViewGroup) GetAbsoluteWidth() uint32

func (ViewGroup) GetAbsoluteX

func (group ViewGroup) GetAbsoluteX() uint32

func (ViewGroup) GetAbsoluteY

func (group ViewGroup) GetAbsoluteY() uint32

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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