attribute

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Overview

package attribute contains property for view interface.

Index

Constants

View Source
const (
	DefaultColorFg = 0xffffff // white
	DefaultColorBg = 0x000000 // black
)
View Source
const (
	EdgeNone = iota
	EdgeLeft
	EdgeRight
	EdgeTop
	EdgeBottom
)

Variables

default colors.

View Source
var HTMLColorTable = map[string]uint32{}/* 148 elements not displayed */

html color name to hex color table

Functions

func ColorOfName

func ColorOfName(name string) (uint32, bool)

get hex color of given name. if not found return black

Types

type Alignment

type Alignment int8

text alignment

const (
	AlignmentLeft Alignment = iota
	AlignmentCenter
	AlignmentRight
)

type Attributes

type Attributes struct {
	Alignment
	Colors
}

attribute set

type Colors

type Colors struct {
	Fg, Bg uint32
}

Colors has foreground and background 16bit color as like 0xRRGGBB.

func (Colors) IsDefault

func (c Colors) IsDefault() bool

check both fore and back color is default?

type Edge

type Edge uint8

Edge is used for FixedSplit.

type LayoutData

type LayoutData struct {
	Type     LayoutType
	Children []*LayoutData

	// ParentValue is sepecified by its' Parent LayoutData, for example,
	// Flow references a weight for each child to layout its children.
	// Value is sepecified by itself, such as Image's source name.
	//
	// Since these are interface{} and data type is undefined,
	// use utility functions to get a specific value after
	// LayoutData's Type is detected.
	ParentValue, Value interface{}
}

LayoutData is a plan of Layouting which is defined by its Type and children. It can construct LayoutData tree to build complex layout structure.

func NewFixedSplit

func NewFixedSplit(e Edge, fixedC, restC *LayoutData) *LayoutData

return FixedVertical LayoutData with its children. it will be occurs panic if first child fixedC has no fixed size. To specify fixed size for first child, use: fixedC = WithChildValue(fixedC, size).

func NewFlowHorizontal

func NewFlowHorizontal(ls ...*LayoutData) *LayoutData

return FlowHorizontal LayoutData with its children. no children occurs panic. each child may have a weight to fill Flow's space. weight is set by using WithChildValue(child, weight).

func NewFlowVertical

func NewFlowVertical(ls ...*LayoutData) *LayoutData

return FlowVertical LayoutData with its children. no children occurs panic. each child may have a weight to fill Flow's space. weight is set by using WithChildValue(child, weight).

func NewSingleImage

func NewSingleImage(src string) *LayoutData

return SingleImage LayoutData with image source name.

func NewSingleText

func NewSingleText(name string) *LayoutData

return SingleText LayoutData with a uniq name for it.

func WithParentValue

func WithParentValue(l *LayoutData, v interface{}) *LayoutData

set a value which is used by its parent LayoutData. return given LayoutData itself after set value.

func WithValue

func WithValue(l *LayoutData, v interface{}) *LayoutData

set a value which is used by itself. return given LayoutData itself after set value.

func (*LayoutData) FixedChildSize

func (l *LayoutData) FixedChildSize() int

get a size from a child LayoutData of Fixed. a size means string width or line count for horizontal or vertical respectively.

func (*LayoutData) FixedEdge

func (l *LayoutData) FixedEdge() Edge

get a edge type from a LayoutData of FixedSplit.

func (*LayoutData) FlowChildWeight

func (l *LayoutData) FlowChildWeight() int

get a weight from a child LayoutData of LayoutData type Flow.

	 flow := LayoutData{Type: TypeFlowVertical, Children: ... }
  for _, c := range flow.Children {
		 weight := c.FlowChildWeight()
  }

func (*LayoutData) SingleImageSrc

func (l *LayoutData) SingleImageSrc() string

get source name from LayoutData of type SingleImage.

func (*LayoutData) SingleTextName

func (l *LayoutData) SingleTextName() string

get a uniq name from LayoutData of type SingleText.

type LayoutType

type LayoutType uint32

LayoutType indicates a type of layout.

const (
	// * Single
	// Single has only one window and the implemetation for content view.
	// it *MUST* have specific value to define its content.
	// - TypeSingleText has a Value as Name to identify text windows.
	// - TypeSingleImage has a  Value as Src to detect what image to show.
	//
	// single window showing text.
	TypeSingleText LayoutType = iota
	// single window showing image
	TypeSingleImage

	// * Flow
	// Flow has auto resized multiple windows aligend by its direction, horizontal or vertical.
	// its each child can have weight (int) to indicate how much child fill Flow's area.
	// If any child has no weight, zero or not set, all of children set 1 weight so that
	// the Flow's area is distributed equlitity.
	// a space of acrossing direction of Flow is filled to max size of Flow.
	// For example, If FlowHorizontal has width 100 (unit is unknown) and its 3 Children have
	// weights 6, 3 and 1, these children have width 60, 30 and 10.
	//
	// A 0 weight means a child will be not showed on screen but exist.
	// Remenber that set weight for all children if any child has weight.
	//
	// auto resized multiple window, align vertically.
	TypeFlowVertical
	// auto resized multiple window, align horizontally
	TypeFlowHorizontal

	// * FixedSplit
	// FixedSplit has 2 children, fixed sized child close to specific Edge and
	// fluided sized child at away from the Edge.
	// Split line's axis is same as Edge.
	// its first child must have size (int) to indicate how much first child fill the area.
	// a size means string width or line count for horizontal or vertical respectively.
	// a space along the Edge is filled to max size of Fixed.
	// For example, If FixedSplit had EdgeTop and 2 Children, and the first had fixed size 40,
	// first child has line count 40 and the second has rest of Fixed.
	TypeFixedSplit
)

Jump to

Keyboard shortcuts

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