bubbleboxer

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: MIT Imports: 4 Imported by: 4

README

bubbleboxer 🥊 - compose bubbles into boxes 📦

A way to compose multiple bubbles into one layout.

To layout the bubbles with bubbleboxer, one would construct a layout-tree 🌲. Each node holds a arbitrary amount of children as well as the orientation (horizontal/vertical) and the spacing of them. Each leaf is linked (via an address) to one Model which satisfies the bubbletea Model-interface. With this address one can access this Models and change them independently from the layout-tree.

 1╭>list of something │ some    0 │ a                       V
  │ ----------------- │ status  1 │  text                  / \
 2├ which you may     │ infor-  2 │   logo                /   \
  │ edit as you wish  │ mation  4 │    even!             H    l5
 3├ or just use it    │           │                     / \
 4├ to display        │ l2        │ l3                 /   \
 5├ and scroll        │──────────────────────         l1    V
                      │ Maybe here is a                    / \
                      │ note written to each              /   \
                      │ list entry, in a                 H    l4
                      │ bubbles viewport.               / \
                      │                                /   \
 l1                   │ l4                            l2   l3
─────────────────────────────────────────────
 maybe a progressbar or a command input? 100% 

 l5

// TODO write about the need for embedding boxer into a other model and about nobordernodes beeing non recursive

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NEWLINE is used to separat the lines
	NEWLINE = "\n"
	// SPACE is used to fill up the lines, make sure it is only one column wide and a single character
	SPACE = " "
	// HorizontalSeparator is used to make a visible border between the horizontal arranged children
	// in the layout-tree, make sure it is only one column wide and a single character
	HorizontalSeparator = "│"
	// VerticalSeparator is used to make a visible border between the vertical arranged children
	// in the layout-tree, make sure it is only one column wide and a single character
	VerticalSeparator = "─"
)

Functions

This section is empty.

Types

type Boxer

type Boxer struct {

	// LayoutTree holds the root node and thus the hole LayoutTree
	// Change it as you like as long as every node without children was
	// created with CreateLeaf (to make sure that every leave has a corresponding ModelMap entry)
	// After deleting a Leaf delete the corresponding entry from ModelMap if you care about memory-leaks
	LayoutTree Node

	// ModelMap is a mapping between the Address of a Leaf and the according Model.
	// A valid entry can only be created with CreateLeaf,
	// because entries without a corresponding Node in the LayoutTree are meaningless.
	ModelMap map[string]tea.Model
}

Boxer is a way to render multiple tea.Model's in a specific layout according to a LayoutTree. The Model's are kept separate from the LayoutTree so that changing a Model does not require traversing the LayoutTree.

func (*Boxer) CreateLeaf

func (b *Boxer) CreateLeaf(address string, model tea.Model) (Node, error)

CreateLeaf is the only way to create a Node which is treated as a Leaf in the layout-tree.

func (*Boxer) EditLeaf added in v0.2.0

func (b *Boxer) EditLeaf(address string, editFunc func(tea.Model) (tea.Model, error)) error

EditLeaf is a saver way to interact with the Leafs, since it can not be forgotten to save back the Model after changing. If the editFunc returns an error the Model is not saved.

func (Boxer) Init

func (b Boxer) Init() tea.Cmd

Init satisfies the tea.Model interface

func (Boxer) Update

func (b Boxer) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles WindowSizeMsg and ctrl+c

func (*Boxer) UpdateSize

func (b *Boxer) UpdateSize(size tea.WindowSizeMsg) error

UpdateSize set the width and height of all Node's

func (Boxer) View

func (b Boxer) View() string

View renders the contained tea.Model's according to the LayoutTree

type Node

type Node struct {
	Children []Node

	// VerticalStacked specifies the orientation of the Children to each other
	VerticalStacked bool

	// SizeFunc specifies the width or height (depending on the orientation) provided to each child.
	// Here by should the sum of the returned int's be the same as the argument 'widthOrHeight'.
	// The length of the returned slice should be the same as the amount of children of the node argument.
	SizeFunc func(node Node, widthOrHeight int) []int
	// contains filtered or unexported fields
}

Node is a node in a layout tree or when created with CreateLeaf its a valid leave of the LayoutTree

func CreateNoBorderNode

func CreateNoBorderNode() Node

CreateNoBorderNode is a constructor for a Node which does not draw a Border around its children. Be aware that this is not recursiv, so all contained children may still have borderes. The Border attribute is private, because the changing of the attribute has to be accompanied with a change of size of all its descendants and is not trivial to facilitate in a save manner.

func (*Node) GetAddress

func (n *Node) GetAddress() string

GetAddress returns the Address of the Node The address of a Node is only settable through CreateLeaf

func (*Node) GetHeight

func (n *Node) GetHeight() int

GetHeight returns the current with of this node

func (*Node) GetWidth

func (n *Node) GetWidth() int

GetWidth returns the current with of this node

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

IsLeaf returns if the node is a leaf.

type NotFoundError added in v0.2.0

type NotFoundError error

NotFoundError convey that the address was not found.

type SizeError

type SizeError error

SizeError conveys that for at leased one node or leaf in the Layout-tree there was not enough space left

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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