components

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package components implements re-usable sections of UI which can be used by multiple sections of the program in multiple different ways.

They are designed to be as self-contained and as simple to use as possible, with immediate-mode UI used as a reference model.

As a general rule, it is safe to assume that none of this package is thread-safe, as it is only really designed for use by the UI thread. That being said, there is nothing stopping you from connecting some methods up to channel listeners or just locking the UI using a mutex either.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column added in v1.1.1

type Column struct {
	Label string
	Width float64
	Color int16
}

A Column is a vertical section of a table, defined by a pair of both a "width" and a "label".

The width is the fraction of the table width the column should take up (defined between zero and one). Table's render method will panic if any column has a "width" of less than zero or greater than one, or if an impossible combination of widths was requested.

The width is the label which will be displayed at the top of the table The color is the ncurses color to activate when selected

type Menu struct {
	W, H  int
	X, Y  int
	Items []string
	Win   goncurses.Window

	Selected bool
	// contains filtered or unexported fields
}

Menu represents a vertical panel menu of cellular entries taking up an entire row from X to W

Menu handles focus, scrolling and the managing of elements at each render.

This component is not thread safe and should only be modified directly one a single thread

func (m *Menu) ChangeSelection(index int)

ChangeSelection changes the selection to the index specified. If index is out of range, no action is taken.

func (m *Menu) GetSelection() string

GetSelection returns the text of the currently selected menu element. If there are no items selected, GetSelection returns an empty string.

func (m *Menu) MoveSelection(offset int)

MoveSelection changes the selected item relative to the current position. If the new selection would be out of range, no action is taken.

func (m *Menu) Render()

Render immediately renders the menu to the specified fields X, Y, H and W.

type Table added in v1.1.1

type Table struct {
	X, Y int
	W, H int
	Win  *goncurses.Window

	// See column struct for docs
	Columns []Column
	// Each sub-slice represents each column entry (eg, 0 = first column)
	Items [][]string
	// contains filtered or unexported fields
}

Table represents a vertical, headed table structure, useful for displaying a slice of structs

func (*Table) ChangeSelection added in v1.1.1

func (t *Table) ChangeSelection(index int)

ChangeSelection changes the selection to the index specified. If index is out of range, no action is taken.

func (*Table) GetSelection added in v1.1.1

func (t *Table) GetSelection() (int, []string)

GetSelection returns the text of the currently selected menu element. If there are no items selected, GetSelection returns an empty slice.

func (*Table) MoveSelection added in v1.1.1

func (t *Table) MoveSelection(offset int)

MoveSelection changes the selected item relative to the current position. If the new selection would be out of range, no action is taken.

func (*Table) Render added in v1.1.1

func (t *Table) Render()

Render immediately renders the table to the requested coords X and Y with the space taken up limited to the space W*H

Jump to

Keyboard shortcuts

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