layout

package module
v0.0.0-...-e8ceda1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: BSD-3-Clause Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gocui-relative-layout

This module provides a layout manager, appropriate for using with gocui's SetManager function. The manager builds a full screen layout, dividing between multiple items with the ratios or sizes provided.

Example

  +-------------------------------+
  | view 1                        |
  +-------------------------------+
  | view 2 |  view 3              |
  |        +----------------------+
  |        |  view 4              |
  |        +----------------------+
  |        |  view 5              |
  +-------------------------------+
  import (
	"github.com/awesome-gocui/gocui"
    "github.com/zigdon/gocui-relative-layout rl"
  )

  viewCol := rl.NewLevel(
    rl.LayoutVertical,
    rl.NewRatioItem(1, "view3", nil),                       # 33% of the space
    rl.NewRatioItem(1, "view4", nil),                       # 33% of the space
    rl.NewRatioItem(1, "view5", nil),                       # 33% of the space
  )

  content := rl.NewLevel(
    rl.LayoutHorizontal,
    rl.NewFixedItem(15, "view2", nil),                      # <--- 15 columns
    rl.NewRatioItem(1, "_viewCol", rl.WithInner(viewCol)),  # <--- remainin space
  )

  layout := rl.NewLevel(
    rl.LayoutVertical,
    rl.NewRatioItem(1, "view1", nil),                       # <--- 25% of the screen
    rl.NewRatioItem(3, "_content", rl.WithInner(content)),  # <--- 75% of the screen
  )

  gui := gocui.NewGui(gocui.OutputNormal, true)
  gui.SetManager(layout)

Creating Items

To create new items for the layout use the NewFixedItem or NewRatioItem functions. An "FixedItem" has a set number of lines in the UI. Any lines not used up by FixedItems are distributed between all the remainin RatioItems, weighted by each's item size.

Item Options
  • Hidden() - Create the view, but don't render it on screen
  • WithCreate() - Call the provided function after creating the new. Useful for setting additional attributes on the view.
  • WithUpdate() - Call the provided functoin each time the layout is rendered.
  • WithInner() - This item contains additional layout items, rather than gocui Views.

Hiding Items

Any section of the layout can be hidden. A hidden item still exists, the views within it are still rendered and their create/update functions are still called. Their contents, however, is not visible on the screen, instead it is rendered "below" the other visible views.

To change the visible of an item, call layout.HideItem(name, visibility), where the visiblity is one of LayoutHidden or LayoutVisible. Alternatively, use layout.ToggleItem(name) to switch between visible and hidden states.

Documentation

Index

Constants

View Source
const (
	LayoutHorizontal LayoutDirection = true
	LayoutVertical   LayoutDirection = false

	LayoutHidden  HideLayout = true
	LayoutVisible HideLayout = false
)

Variables

View Source
var InvalidValues = fmt.Errorf("Fixes and Ratio parameters are not compatible")

InvalidValues is an error returned when both fixes and ratios are specified for the same item.

View Source
var NotFound = fmt.Errorf("Item not found")

NotFound is an error returned when an item referenced by name does not exist.

Functions

func Hidden

func Hidden() layoutItemOption

Hidden is an item option indicating a given item should not be visible.

func NewFixedItem

func NewFixedItem(size int, name string, opts ...layoutItemOption) *layoutItem

NewFixedItem create a new item with the specified number of lines/columns.

func NewLevel

func NewLevel(direction LayoutDirection, items ...*layoutItem) *layoutLevel

NewLevel create a new set of items to be spread either horizontally or vertically.

func NewRatioItem

func NewRatioItem(weight int, name string, opts ...layoutItemOption) *layoutItem

NewRatioItem creates a new item, that is to take a given ratio of the total available space.

func WithCreate

func WithCreate(f func(*gocui.View) error) layoutItemOption

WithCreate passes a function that will be called once a new view is created. It is called only once per view.

func WithInner

func WithInner(inner *layoutLevel) layoutItemOption

WithInner is used when an item is to contain other items, rather than views.

func WithUpdate

func WithUpdate(f func(*gocui.View) error) layoutItemOption

WithUpdate passes a function that is called each time the layout is rendered.

Types

type HideLayout

type HideLayout bool

HideLayout identifies if an item should be hidden or visible.

type LayoutDirection

type LayoutDirection bool

LayoutDirection controls if layout items are spread horizontally or vertically.

Jump to

Keyboard shortcuts

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