ctxtcell

package module
v0.0.0-...-85362aa Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// is the last element that was hovered
	LastHoverElement TcElement
	// is the last element that was clicked
	LastMouseElement TcElement
	// is the element that has the focus
	FocusedElement TcElement

	// we need an incemental ID that we can use to identify the elements
	// this is used to identify the elements in the map
	ElementLastID int

	// messure the time we need to render the screen
	// this is only used for debugging
	RenderTime time.Duration
)

Functions

func CreatePosition

func CreatePosition(x, y int, isPercent bool) position

func Focus

func Focus(activated bool)

Types

type Coordinates

type Coordinates struct {
	TopLeft    position
	Dimensions dim
}

Coordinates is a struct that contains the position and the dimensions of an element

func NewCoordinates

func NewCoordinates(topLeft position, w int, h int) *Coordinates

type CtCell

type CtCell struct {
	MouseEnabled bool
	// contains filtered or unexported fields
}

func NewTcell

func NewTcell() *CtCell

func (*CtCell) ActiveText

func (c *CtCell) ActiveText(content string) *textElement

Text creates a new text element and returns a pointer to it. and sets the default behavior of an element to be clickable, can be focuses and can be hovered

func (*CtCell) AddDebugMessage

func (c *CtCell) AddDebugMessage(msg ...interface{})

func (*CtCell) AddElement

func (c *CtCell) AddElement(e TcElement) (int, error)

AddElement adds an element to the cell it also checks if the element is already in the cell, if an id is already set

func (*CtCell) CleanDebugMessages

func (c *CtCell) CleanDebugMessages()

func (*CtCell) ClearElements

func (c *CtCell) ClearElements()

ClearElements removes all elements from the cell

func (*CtCell) CycleFocus

func (c *CtCell) CycleFocus()

CycleFocus will cycle the focus to the next element

func (*CtCell) DrawAll

func (c *CtCell) DrawAll() int

Draws all elements and returns the amount of drawed elements

func (*CtCell) GetElementByID

func (c *CtCell) GetElementByID(id int) TcElement

GetElementByID returns the element with the given id

func (*CtCell) GetFocusedElement

func (c *CtCell) GetFocusedElement() TcElement

GetFocusedElement returns the element that has the focus

func (*CtCell) GetLastLoopTime

func (c *CtCell) GetLastLoopTime() time.Duration

func (*CtCell) GetOutput

func (c *CtCell) GetOutput() *CtOutput

func (*CtCell) GetScreen

func (c *CtCell) GetScreen() tcell.Screen

func (*CtCell) GetSortedElements

func (c *CtCell) GetSortedElements() []TcElement

GetSortedElements returns all elements sorted by their z-index

func (*CtCell) GetSortedKeys

func (c *CtCell) GetSortedKeys() []int

GetSortedKeys returns all keys sorted

func (*CtCell) Init

func (c *CtCell) Init() error

func (*CtCell) Loop

func (c *CtCell) Loop()

func (*CtCell) MouseHoverAll

func (c *CtCell) MouseHoverAll(pos position)

MouseHoverAll is called when the mouse is hovering

func (*CtCell) MousePressAll

func (c *CtCell) MousePressAll(pos position, trigger int)

MousePressAll is called when the mouse is pressed it will trigger the first element that is hit

func (*CtCell) MouseReleaseAll

func (c *CtCell) MouseReleaseAll(start position, end position, trigger int)

MouseReleaseAll is called when the mouse is released it will trigger the first element that is hit by the start coordinate

func (*CtCell) NewBox

func (c *CtCell) NewBox() *ctBox

func (*CtCell) NewMenu

func (c *CtCell) NewMenu() *ctMenu

NewMenu creates a new menu and sets the default style

func (*CtCell) RemoveElement

func (c *CtCell) RemoveElement(e TcElement)

RemoveElement removes an element from the cell

func (*CtCell) RemoveElementByID

func (c *CtCell) RemoveElementByID(id int)

RemoveElementByID removes an element from the cell by its id

func (*CtCell) ResetCaches

func (c *CtCell) ResetCaches()

ResetCaches resets the cache for the sorted elements

func (*CtCell) Run

func (c *CtCell) Run() error

func (*CtCell) SendEvent

func (c *CtCell) SendEvent(ev tcell.Event) error

func (*CtCell) SetDebug

func (c *CtCell) SetDebug(debug bool) *CtCell

func (*CtCell) SetFocusById

func (c *CtCell) SetFocusById(id int)

SetFocus set the focus of the element the old focus element will be unfocused

func (*CtCell) SetMouse

func (c *CtCell) SetMouse(mouse bool) *CtCell

func (*CtCell) SetNoClearScreen

func (c *CtCell) SetNoClearScreen(noclear bool) *CtCell

func (*CtCell) SetScreen

func (c *CtCell) SetScreen(s tcell.Screen) *CtCell

func (*CtCell) SortedCallBack

func (c *CtCell) SortedCallBack(doIt func(b TcElement) bool)

SortedCallBack will call the callback function for all elements the elements are sorted by their z-index

func (*CtCell) Stop

func (c *CtCell) Stop()

func (*CtCell) Text

func (c *CtCell) Text(content string) *textElement

Text creates a new text element and returns a pointer to it.

type CtOutput

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

this is the output filter for the tcell module that will be injected to ctxout

func NewCtOutput

func NewCtOutput(parent *CtCell) *CtOutput

func NewCtOutputNoTty

func NewCtOutputNoTty() *CtOutput

func (*CtOutput) Stream

func (c *CtOutput) Stream(msg ...interface{})

func (*CtOutput) StreamLn

func (c *CtOutput) StreamLn(msg ...interface{})

func (*CtOutput) Update

func (c *CtOutput) Update(info ctxout.CtxOutBehavior)
type MenuElement struct {
	OnSelect func(*MenuElement) // the function that is called when the element is selected
	// contains filtered or unexported fields
}

MenuElement is an element in a menu

func (m *MenuElement) GetReference() interface{}

GetReference returns the reference of the menu element this can be nil. it is an interface{} so it can be anything also this is only valid for MenuElements created with NewMenuElementWithRef

func (m *MenuElement) GetText() *textElement

GetText returns the text Element of the menu element

type TcElement

type TcElement interface {
	// Draw draw the element on the screen
	Draw(s tcell.Screen) Coordinates
	// MouseReleaseEvent is called when mouse is released
	MouseReleaseEvent(start position, end position, trigger int)
	// MousePressEvent is called when mouse is pressed
	MousePressEvent(pos position, trigger int)
	// MouseHoverEvent is called when mouse is hovering
	MouseHoverEvent(pos position)
	// MouseLeaveEvent is called when mouse is leaving
	MouseLeaveEvent()
	// Hit check if the element is hit by the mouse
	Hit(pos position, s tcell.Screen) bool
	// SetFocus set the focus of the element
	Focus(activated bool)
	// reports if the element is selectable and also can be focused
	IsSelectable() bool
	// reports if the element is visible. if not, it will not be drawn
	IsVisible() bool
	// set the visibility of the element
	SetVisible(visible bool)
	// set the ID of the element
	SetID(id int)
	// get the ID of the element
	GetID() int
}

Jump to

Keyboard shortcuts

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