geom

package
v0.0.0-...-d3199ed Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

README

Line, Column, Row, Rectangle, Grid

All primitives are just a way of indicating a group of term.Pixel. A Line can be a collection of term.Pixel which can be horizontal, making it a Row or vertical, making it a Column. Using the LineFromPositions function from geom package, you can have non typical lines, like a diagonal or other arbitrary positioned line. Now, thinking about Rect : it's just a thicker Line, isn't it? The only particularity of a Rect is the orientation : a Rect can be organized vertically, making it an array of Rows - or horizontally, making it an array of Columns. A Grid is a collection of `Rect', right ? It is only special as it is "flexible", in terms that it should resize it's children to the desired sizes.

Center of a rectangle

Cases Column Even (e.g:2) Column Odd (e.g:3)
Row Even (e.g:2) Center Odd (0,0) Center SemiEven (1,0)
Row Odd (e.g:3) Center SemiEven (0,1) Center Even (1,1)

Page and it's context.Context

When a Page gets created, a cancellable context.Context should be passed to it, so it can free the collection of term.Pixel it orchestrates. Stepping back a little, a Page it's just a Rect which just fills the entire screen. Another particularity of a Page it's that will listen for term.ResizeEvent in order to fill the entire screen. Another important one is inheritance of BackgroundColor from the Page beneath itself. Last but least, a Page should be able to keep a stack of owners of a term.Pixel (think Dropdown or Autocomplete needs to "borrow" some pixels from a neighbour for a while).
Page listens for mouse events and dispatches them only to Rectangles that are in that position.

Documentation

Index

Constants

View Source
const (
	Debug = true // if set to false, the compiler will cleanup/remove the lines inside functions
)

Variables

This section is empty.

Functions

func NewPixel

func NewPixel(opts ...PixelOption) (term.Pixel, error)

NewPixel constructs a term.Pixel implementation, to be used as both term.Pixel and term.PixelSetter interfaces Note : the reason for which we're using image.Point relies on the functionality it provides regarding image package, e.g : image.Point.In(r image.Rectangle) Another note, important : the background and foreground needs to be defaulted to color.Default because engine performs extra steps otherwise. Search core.drawPixel method for `positions "needed" from geom.Pixel`

Types

type Cell

type Cell = px

Cell

type Item

type Item struct {
	Level     int        //
	Rectangle *Rectangle //
}

Item combines a text with a specific level. The level is the indent, which would normally be seen in a BulletList.

type LeveledList

type LeveledList []Item

LeveledList is a list, which contains multiple Item.

type Line

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

Line describes a colored line primitive. Lines are special as they can have a negative width or height to indicate an inverse slope (i.e. slope up vs down).

func NewLine

func NewLine(ctx context.Context, opts ...LineOption) *Line

NewLine returns a new Line instance

func (*Line) Hide

func (l *Line) Hide()

Hide will set this line to not be visible

func (*Line) MinSize

func (l *Line) MinSize() *term.Size

MinSize for a Line simply returns Size{1, 1} as there is no explicit content

func (*Line) Move

func (l *Line) Move(pos *term.Position)

Move the line object to a new position, relative to its children / canvas

func (*Line) Position

func (l *Line) Position() *term.Position

Position gets the current top-left position of this line object, relative to its children / canvas

func (*Line) Resize

func (l *Line) Resize(size term.Size)

Resize sets a new bottom-right position for the line object and it will then be refreshed.

func (*Line) Show

func (l *Line) Show()

Show will set this line to be visible

func (*Line) Size

func (l *Line) Size() *term.Size

Size returns the current size of bounding box for this line object

func (*Line) Visible

func (l *Line) Visible() bool

Visible returns true if this line// Show will set this circle to be visible is visible, false otherwise

type LineOption

type LineOption func(l *Line)

func WithBottomRight

func WithBottomRight(pos *term.Position) LineOption

WithBottomRight

func WithPositions

func WithPositions(from, to *term.Position) LineOption

func WithTopLeft

func WithTopLeft(pos *term.Position) LineOption

WithTopLeft

type LinearGradient

type LinearGradient struct {
	sync.RWMutex //

	StartColor color.Color // The beginning color of the gradient
	EndColor   color.Color // The end color of the gradient
	Angle      float64     // The angle of the gradient (0/180 for vertical; 90/270 for horizontal)
	Hidden     bool        // Is this object currently hidden
	// contains filtered or unexported fields
}

LinearGradient defines a Gradient travelling straight at a given angle. The only supported values for the angle are `0.0` (vertical) and `90.0` (horizontal), currently.

func NewHorizontalGradient

func NewHorizontalGradient(start, end color.Color) *LinearGradient

NewHorizontalGradient creates a new horizontally travelling linear gradient. The start color will be at the left of the gradient and the end color will be at the right.

func NewLinearGradient

func NewLinearGradient(start, end color.Color, angle float64) *LinearGradient

NewLinearGradient creates a linear gradient at a the specified angle. The angle parameter is the degree angle along which the gradient is calculated. A NewHorizontalGradient uses 270 degrees and NewVerticalGradient is 0 degrees.

func NewVerticalGradient

func NewVerticalGradient(start color.Color, end color.Color) *LinearGradient

NewVerticalGradient creates a new vertically travelling linear gradient. The start color will be at the top of the gradient and the end color will be at the bottom.

func (*LinearGradient) Generate

func (l *LinearGradient) Generate(iw, ih int) image.Image

Generate calculates an image of the gradient with the specified width and height.

func (*LinearGradient) Hide

func (l *LinearGradient) Hide()

Hide will set this object to not be visible

func (*LinearGradient) MinSize

func (l *LinearGradient) MinSize() *term.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise

func (*LinearGradient) Move

func (l *LinearGradient) Move(pos *term.Position)

Move the rectangle object to a new position, relative to its children / canvas

func (*LinearGradient) Position

func (l *LinearGradient) Position() *term.Position

CurrentPosition gets the current position of this rectangle object, relative to its children / canvas

func (*LinearGradient) Resize

func (l *LinearGradient) Resize(size *term.Size)

Resize sets a new size for the rectangle object

func (*LinearGradient) SetMinSize

func (l *LinearGradient) SetMinSize(size *term.Size)

SetMinSize specifies the smallest size this object should be

func (*LinearGradient) Show

func (l *LinearGradient) Show()

Show will set this object to be visible

func (*LinearGradient) Size

func (l *LinearGradient) Size() *term.Size

CurrentSize returns the current size of this rectangle object

func (*LinearGradient) Visible

func (l *LinearGradient) Visible() bool

IsVisible returns true if this object is visible, false otherwise

type Node

type Node struct {
	Children  []Node     //
	Rectangle *Rectangle //
	// contains filtered or unexported fields
}

Node is used as items in a Tree.

func NewTreeFromLeveledList

func NewTreeFromLeveledList(items LeveledList) Node

NewTreeFromLeveledList converts a TreeItems list to a Node and returns it.

type Owners

type Owners []Rectangle

Owners

func (*Owners) Add

func (ow *Owners) Add(pr *Rectangle)

Add

func (*Owners) ForgetFirst

func (ow *Owners) ForgetFirst()

ForgetFirst

func (*Owners) MoveToFront

func (ow *Owners) MoveToFront(pr *Rectangle)

MoveToFront

type Page

type Page struct {
	sync.RWMutex //
	sync.Once    // required for registering lifecycle goroutines exactly once
	// contains filtered or unexported fields
}

Page

func NewPage

func NewPage(ctx context.Context, opts ...PageOption) (*Page, error)

NewPage

func (*Page) Activate

func (p *Page) Activate()

Activate

func (*Page) Column

func (r *Page) Column(index int) Pixels

Column returns the column of pixels at index (absolute, starting with zero)

func (*Page) Columns

func (r *Page) Columns() PixelsMatrix

Columns

func (*Page) Deactivate

func (p *Page) Deactivate()

Deactivate

func (*Page) DyingChan

func (p *Page) DyingChan() chan struct{}

DyingChan

func (*Page) HasColumns

func (r *Page) HasColumns() bool

HasColumns

func (*Page) HasRows

func (r *Page) HasRows() bool

HasRows

func (*Page) KeyListen

func (p *Page) KeyListen() chan term.KeyEvent

KeyListen

func (*Page) MouseListen

func (p *Page) MouseListen() chan term.MouseEvent

MouseListen

func (*Page) NumColumns

func (r *Page) NumColumns() int

NumColumns - depends on orientation

func (*Page) NumRows

func (r *Page) NumRows() int

NumRows - depends on orientation

func (*Page) Orientation

func (r *Page) Orientation() style.Orientation

Orientation

func (*Page) ResizeListen

func (p *Page) ResizeListen() chan term.ResizeEvent

ResizeListen

func (*Page) Row

func (r *Page) Row(index int) Pixels

Row returns the row of pixels at index (absolute, starting with zero)

func (*Page) Rows

func (r *Page) Rows() PixelsMatrix

Rows

func (*Page) Shutdown

func (p *Page) Shutdown()

Shutdown

type PageOption

type PageOption func(p *Page)

PageOption

func WithEngine

func WithEngine(engine term.Engine) PageOption

WithEngine

func WithPageOrientation

func WithPageOrientation(o style.Orientation) PageOption

WithPageOrientation

type PixelOption

type PixelOption func(p *px)

PixelOption for functional options

func WithAttrs

func WithAttrs(m style.Mask) PixelOption

WithAttrs is optional

func WithBackground

func WithBackground(c color.Color) PixelOption

WithBackground is optional

func WithForeground

func WithForeground(c color.Color) PixelOption

WithForeground is optional

func WithPosition

func WithPosition(pos *term.Position) PixelOption

WithPosition is required - row is X, column is Y

func WithRune

func WithRune(r rune) PixelOption

WithRune is optional

func WithUnicode

func WithUnicode(u term.Unicode) PixelOption

WithUnicode is optional

type Pixels

type Pixels []px

type PixelsMatrix

type PixelsMatrix []Pixels

type RadialGradient

type RadialGradient struct {
	sync.RWMutex //

	StartColor    color.Color // The beginning color of the gradient
	EndColor      color.Color // The end color of the gradient
	CenterOffsetX float64     // The offset of the center for generation of the gradient. This is not a DP measure but relates to the width/height. A value of 0.5 would move the center by the half width/height.
	CenterOffsetY float64     //
	Hidden        bool        // Is this object currently hidden
	// contains filtered or unexported fields
}

RadialGradient defines a Gradient travelling radially from a center point outward.

func NewRadialGradient

func NewRadialGradient(start, end color.Color) *RadialGradient

NewRadialGradient creates a new radial gradient.

func (*RadialGradient) Generate

func (r *RadialGradient) Generate(iw, ih int) image.Image

Generate calculates an image of the gradient with the specified width and height.

func (*RadialGradient) Hide

func (r *RadialGradient) Hide()

Hide will set this object to not be visible

func (*RadialGradient) MinSize

func (r *RadialGradient) MinSize() *term.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise

func (*RadialGradient) Move

func (r *RadialGradient) Move(pos *term.Position)

Move the rectangle object to a new position, relative to its children / canvas

func (*RadialGradient) Position

func (r *RadialGradient) Position() *term.Position

CurrentPosition gets the current position of this rectangle object, relative to its children / canvas

func (*RadialGradient) Resize

func (r *RadialGradient) Resize(size *term.Size)

Resize sets a new size for the rectangle object

func (*RadialGradient) SetMinSize

func (r *RadialGradient) SetMinSize(size *term.Size)

SetMinSize specifies the smallest size this object should be

func (*RadialGradient) Show

func (r *RadialGradient) Show()

Show will set this object to be visible

func (*RadialGradient) Size

func (r *RadialGradient) Size() *term.Size

CurrentSize returns the current size of this rectangle object

func (*RadialGradient) Visible

func (r *RadialGradient) Visible() bool

IsVisible returns true if this object is visible, false otherwise

type Rectangle

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

Rectangle describes a colored rectangle primitive

func NewRectangle

func NewRectangle(ctx context.Context, opts ...RectangleOption) (*Rectangle, error)

TODO : thinking maybe this should be a private constructor. Ask Page to give you a Rectangle and it will give it already populated and ready to use. For now (testing purposes), I'll leave it as it is. NewRectangle returns a new Rectangle instance

func (*Rectangle) AtBegin

func (r *Rectangle) AtBegin() bool

AtBegin indicates alignment at the top left corner.

func (*Rectangle) AtBottom

func (r *Rectangle) AtBottom() bool

AtBottom indicates alignment on the bottom edge.

func (*Rectangle) AtEnd

func (r *Rectangle) AtEnd() bool

AtEnd indicates alignment at the bottom right corner.

func (*Rectangle) AtHorizontalCenter

func (r *Rectangle) AtHorizontalCenter() bool

AtHorizontalCenter indicates horizontally centered.

func (*Rectangle) AtLeft

func (r *Rectangle) AtLeft() bool

AtLeft indicates alignment on the left edge.

func (*Rectangle) AtMiddle

func (r *Rectangle) AtMiddle() bool

AtMiddle indicates full centering.

func (*Rectangle) AtRight

func (r *Rectangle) AtRight() bool

AtRight indicates alignment on the right edge.

func (*Rectangle) AtTop

func (r *Rectangle) AtTop() bool

AtTop indicates alignment on the top edge.

func (*Rectangle) AtVerticalCenter

func (r *Rectangle) AtVerticalCenter() bool

AtVerticalCenter indicates vertically centered.

func (*Rectangle) Bg

func (r *Rectangle) Bg() color.Color

Bg

func (*Rectangle) Bottom

func (r *Rectangle) Bottom() *term.Position

Bottom

func (*Rectangle) Center

func (r *Rectangle) Center() *term.Position

Center of a Rectangle

func (*Rectangle) Column

func (r *Rectangle) Column(index int) Pixels

Column returns the column of pixels at index (absolute, starting with zero)

func (*Rectangle) Columns

func (r *Rectangle) Columns() PixelsMatrix

Columns

func (*Rectangle) DyingChan

func (r *Rectangle) DyingChan() chan struct{}

DyingChan implementation of term.Death interface, listened in core for waiting graceful shutdown

func (*Rectangle) Empty

func (r *Rectangle) Empty() bool

Empty returns if the Rectangle is zero rows and zero columns

func (*Rectangle) Fg

func (r *Rectangle) Fg() color.Color

Fg

func (*Rectangle) HasColumns

func (r *Rectangle) HasColumns() bool

HasColumns

func (*Rectangle) HasPerfectCenter

func (r *Rectangle) HasPerfectCenter() bool

HasPerfectCenter - allows the caller of Center not to fool themselves (e.g. center is shifted towards top right)

func (*Rectangle) HasRows

func (r *Rectangle) HasRows() bool

HasRows

func (*Rectangle) Height

func (r *Rectangle) Height() int

Height returns r's height.

func (*Rectangle) Hide

func (r *Rectangle) Hide()

Hide will set this object to not be visible

func (*Rectangle) Id

func (r *Rectangle) Id() int

Id is used by Page to identify owners and operate them

func (*Rectangle) In

func (r *Rectangle) In(s *Rectangle) bool

In reports whether every point in r is in s.

func (*Rectangle) Intersect

func (r *Rectangle) Intersect(s *Rectangle) *Rectangle

Intersect returns the largest rectangle contained by both r and s. If the two rectangles do not overlap then the zero rectangle will be returned.

func (*Rectangle) Invalid

func (r *Rectangle) Invalid() bool

Invalid returns true if coordinates are NOT set

func (*Rectangle) MinSize

func (r *Rectangle) MinSize() *term.Size

MinSize returns the specified minimum size, if set, or nil otherwise

func (*Rectangle) Move

func (r *Rectangle) Move(pos *term.Position)

Move the rectangle object to a new position, relative to its children / canvas

func (*Rectangle) NumColumns

func (r *Rectangle) NumColumns() int

NumColumns - depends on orientation

func (*Rectangle) NumRows

func (r *Rectangle) NumRows() int

NumRows - depends on orientation

func (*Rectangle) Orientation

func (r *Rectangle) Orientation() style.Orientation

Orientation

func (*Rectangle) Overlaps

func (r *Rectangle) Overlaps(s *Rectangle) bool

Overlaps reports whether r and s have a non-empty intersection.

func (*Rectangle) PixelAskChan

func (r *Rectangle) PixelAskChan() chan term.Position

PixelAskChan - used by Page to deliver pixels

func (*Rectangle) PixelReceiverChan

func (r *Rectangle) PixelReceiverChan() chan px

PixelReceiverChan - used by Rectangle to get pixels from Page

func (*Rectangle) PixelReleaseChan

func (r *Rectangle) PixelReleaseChan() chan term.Position

PixelReleaseChan - use by Page to change owner of the pixel

func (*Rectangle) ResizeListen

func (r *Rectangle) ResizeListen() chan term.ResizeEvent

ResizeListen

func (*Rectangle) Row

func (r *Rectangle) Row(index int) Pixels

Row returns the row of pixels at index (absolute, starting with zero)

func (*Rectangle) Rows

func (r *Rectangle) Rows() PixelsMatrix

Rows

func (*Rectangle) SetChildren

func (r *Rectangle) SetChildren(children ...*Rectangle)

SetChildren - general convention that all siblings are registered together so we can perform calculations of positions and invalidate recursively the children rectangles

func (*Rectangle) SetMinSize

func (r *Rectangle) SetMinSize(size *term.Size)

SetMinSize specifies the smallest size this object should be

func (*Rectangle) Show

func (r *Rectangle) Show()

Show will set this object to be visible

func (*Rectangle) Size

func (r *Rectangle) Size() *term.Size

CurrentSize returns the current size of this rectangle object

func (*Rectangle) Top

func (r *Rectangle) Top() *term.Position

Top

func (*Rectangle) Union

func (r *Rectangle) Union(s *Rectangle) *Rectangle

Union returns the smallest rectangle that contains both r and s.

func (*Rectangle) Visible

func (r *Rectangle) Visible() bool

IsVisible returns true if this object is visible, false otherwise

func (*Rectangle) Width

func (r *Rectangle) Width() int

Width returns r's width.

type RectangleOption

type RectangleOption func(r *Rectangle)

RectangleOption

func AsColumn

func AsColumn(column, startRow, endRow int) RectangleOption

AsColumn

func AsLine

func AsLine(line, startColumn, endColumn int) RectangleOption

AsLine

func WithAcquisitionChan

func WithAcquisitionChan(pixelCh chan term.Position) RectangleOption

WithAcquisitionChan is provided by the caller, so we can "ask" for pixels

func WithAlignment

func WithAlignment(a style.Alignment) RectangleOption

WithAlignment

func WithBackgroundColor

func WithBackgroundColor(c color.Color) RectangleOption

WithBackgroundColor

func WithBottomCorner

func WithBottomCorner(col, row int) RectangleOption

WithBottomCorner

func WithChildren

func WithChildren(children ...*Rectangle) RectangleOption

WithChildren

func WithCore

func WithCore(engine term.Engine) RectangleOption

WithCore

func WithForegroundColor

func WithForegroundColor(c color.Color) RectangleOption

WithForegroundColor

func WithHeight

func WithHeight(percent int) RectangleOption

WithHeight

func WithMinSize

func WithMinSize(size *term.Size) RectangleOption

WithMinSize

func WithOrientation

func WithOrientation(o style.Orientation) RectangleOption

WithOrientation

func WithReleasingChan

func WithReleasingChan(relePixelCh chan term.Position) RectangleOption

WithReleasingChan is provided by the caller, so we can "free" pixels

func WithRowColAndSize

func WithRowColAndSize(row, column, numRows, numCols int) RectangleOption

WithRowColAndSize

func WithTopCorner

func WithTopCorner(col, row int) RectangleOption

WithTopCorner

func WithWidth

func WithWidth(percent int) RectangleOption

WithWidth

func WithWidthAndHeight

func WithWidthAndHeight(widthPercent, heightPercent int) RectangleOption

WithWidthAndHeight

type RootRectangle

type RootRectangle interface {
	Orientation() style.Orientation
	HasRows() bool
	NumRows() int
	Rows() PixelsMatrix
	Row(index int) Pixels
	HasColumns() bool
	NumColumns() int
	Columns() PixelsMatrix
	Column(index int) Pixels
}

RootRectangle interface

type Screen

type Screen = Rectangle

Screen

type Tree

type Tree struct {
	Root *Node //
	// contains filtered or unexported fields
}

Tree is able to render a list.

func NewTree

func NewTree(ctx context.Context, cols, rows int, ch chan term.Position, oriented style.Orientation, core term.Engine) Tree

newTree

func (*Tree) Register

func (t *Tree) Register(targets ...*Rectangle)

Register

type Window

type Window = Rectangle

Window

Jump to

Keyboard shortcuts

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