bubbleboxer

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 4 Imported by: 0

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

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 ΒΆ

func SetFocusMsg ΒΆ

func SetFocusMsg(id string) tea.Msg

Types ΒΆ

type Boxer ΒΆ

type Boxer struct {

	// HandleMsg controls if updates are propagated to the currently focused bubble.
	// And if focus message should be sent.
	HandleMsg bool

	// 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
	// contains filtered or unexported fields
}

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

CreateLeaf is the only way to create a Node which is treated as a Leaf in the layout-tree. CreateLeaf panics when either address is the empty string or the model is nil.

func (Boxer) CurrentlyFocused ΒΆ

func (b Boxer) CurrentlyFocused() string

Returns the ID of the currently focused bubble

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)

func (*Boxer) UpdateSize ΒΆ

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

UpdateSize set the width and height of all Node's returns SizeErrorMsg if the area (width*height) is less or equal to zero for any node or leaf

panics if

  • a leaf has children

  • a leaf has a address without a model in the ModelMap (because it was deleted)

  • a Node (not a leaf) has no Children

  • the SizeFunc returned a slice with different length compared to the size of the Children

  • the combined space returned by the SizeFunc is greater than the provided size

func (Boxer) View ΒΆ

func (b Boxer) View() string

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

type FocusError ΒΆ

type FocusError setFocus

FocusError conveys that a SetFocusMsg had an incorrect ID given to it

type GainedFocus ΒΆ

type GainedFocus struct{}

type LostFocus ΒΆ

type LostFocus struct{}

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. 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 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