widget

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2019 License: MIT Imports: 2 Imported by: 0

README

widget

Example widgets for creating a simple text-base interface, using the vt100 module.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RepeatRune

func RepeatRune(r rune, n uint) string

Repeat a rune, n number of times. Returns an empty string if memory can not be allocated within append.

func RepeatRune2

func RepeatRune2(r rune, n uint) (string, error)

Repeat a rune, n number of times

func SplitTrim

func SplitTrim(s string) []string

Split a string on any newline: \n, \r or \r\n Also removes empty lines and trims away whitespace.

Types

type Box

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

Box has one outer and one innner rectangle. This is useful when having margins that surrounds content.

func NewBox

func NewBox() *Box

Create a new Box / container.

func (*Box) BottomCenter

func (b *Box) BottomCenter(container *Box)

Place a box at the bottom center of a given container

func (*Box) Center

func (b *Box) Center(container *Box)

Place a Box at the center of the given container.

func (*Box) Fill

func (b *Box) Fill(container *Box)

Place a Box so that it fills the entire given container.

func (*Box) FillWithMargins

func (b *Box) FillWithMargins(container *Box, margins int)

Place a Box inside a given container, with the given margins. Margins are given in number of characters.

func (*Box) FillWithPercentageMargins

func (b *Box) FillWithPercentageMargins(container *Box, horizmarginp float32, vertmarginp float32)

Place a Box inside a given container, using the given percentage wise ratios. horizmarginp can for example be 0.1 for a 10% horizontal margin around the inner box. vertmarginp works similarly, but for the vertical margins.

func (*Box) GetContentPos

func (b *Box) GetContentPos() (int, int)

Retrieves the position of the inner rectangle.

func (*Box) GetFrame

func (b *Box) GetFrame() *Rect

Get the outer frame (box size + pos)

func (*Box) GetInner

func (b *Box) GetInner() *Rect

Get the inner rectangle (content size + pos)

func (*Box) Place

func (b *Box) Place(container *Box)

Place a Box within the given container.

func (*Box) SetFrame

func (b *Box) SetFrame(r *Rect)

Set the outer frame (box size + pos)

func (*Box) SetInner

func (b *Box) SetInner(r *Rect)

Set the inner rectangle (content size + pos)

func (*Box) SetNicePlacement

func (b *Box) SetNicePlacement(container *Box)

Place a Box so that it either fills the given container, or is placed 1/3 from the upper left edge, depending on how much space is left.

func (*Box) SetThirdPlace

func (b *Box) SetThirdPlace(container *Box)

Set the position of the Box to 1/3 of the size of the inner rectangle of the given container.

func (*Box) SetThirdSize

func (b *Box) SetThirdSize(container *Box)

Set the size of the Box to 1/3 of the size of the inner rectangle of the given container.

type Rect

type Rect struct {
	X int
	Y int
	W int
	H int
}

Rect is a position, width and height

type Theme

type Theme struct {
	Text, Background, Title,
	BoxLight, BoxDark, BoxBackground,
	ButtonFocus, ButtonText,
	ListFocus, ListText, ListBackground vt100.AttributeColor
	TL, TR, BL, BR, V, V2, H, H2 rune
}

func NewTheme

func NewTheme() *Theme

func (*Theme) DrawAsciiArt

func (t *Theme) DrawAsciiArt(c *vt100.Canvas, x, y int, text string) int

Outputs a multiline string at the given coordinates. Uses the box background color. Returns the final y coordinate after drawing.

func (*Theme) DrawBackground

func (t *Theme) DrawBackground()

Clear the canvas, set a background color and draw the canvas.

func (*Theme) DrawBox

func (t *Theme) DrawBox(c *vt100.Canvas, r *Box, extrude bool) *Rect

Draw a box using ASCII graphics. The given Box struct defines the size and placement. If extrude is True, the box looks a bit more like it's sticking out.

func (*Theme) DrawButton

func (t *Theme) DrawButton(c *vt100.Canvas, r *Box, text string, active bool)

Draws a button widget at the given placement, with the given text. If active is False, it will look more "grayed out".

func (*Theme) DrawList

func (t *Theme) DrawList(c *vt100.Canvas, r *Box, items []string, selected int)

Draw a list widget. Takes a Box struct for the size and position. Takes a list of strings to be listed and an int that represents which item is currently selected. Does not scroll or wrap.

func (*Theme) DrawRaw

func (t *Theme) DrawRaw(c *vt100.Canvas, x, y int, text string) int

Outputs a multiline string at the given coordinates. Uses the default background color. Returns the final y coordinate after drawing.

func (*Theme) Say

func (t *Theme) Say(c *vt100.Canvas, x, y int, text string)

Output text at the given coordinates, with the configured theme

func (*Theme) SetBackgroundColor

func (t *Theme) SetBackgroundColor(c vt100.AttributeColor)

Set the background color

func (*Theme) SetTextColor

func (t *Theme) SetTextColor(c vt100.AttributeColor)

Set the text color

Directories

Path Synopsis
cmd
box command

Jump to

Keyboard shortcuts

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