sahar

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Sahar

a layout engine for text and images using basic primitives.

Installation

go get ella.to/sahar

Usage

	b := sahar.Stack(
		sahar.Padding(5, 5, 5, 5),

		sahar.FontFamily("Arial", "./testdata/Arial.ttf"),

		sahar.Width(200),
		sahar.Height(200),

		sahar.Stack(
			sahar.Alignments(sahar.Center, sahar.Middle),
			sahar.BackgroundColor("#FF0000"),

			sahar.Text(
				"Hello, World!",
				sahar.Color("#000000"),
				sahar.FontSize(8),
			),

			sahar.Image("./testdata/Sample.jpeg"),
		),
	)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func A1

func A1() *size

func A2

func A2() *size

func A3

func A3() *size

func A4

func A4() *size

func A4Lanscape

func A4Lanscape() *size

func A4Smal

func A4Smal() *size

func A5

func A5() *size

func Alignments

func Alignments(horizontal Horizontal, vertical Vertical) blockOpt

func ApplyMulti

func ApplyMulti(attrs ...blockOpt) blockOpt

func Attr

func Attr(key string, value any) blockOpt

func B4

func B4() *size

func B5

func B5() *size

func BackgroundColor

func BackgroundColor(color string) blockOpt

func Border

func Border(width float64, color string) blockOpt

func Color

func Color(color string) blockOpt

func FontFamily

func FontFamily(name string, src string) blockOpt

func FontSize

func FontSize(size float64) blockOpt

func FontWeight

func FontWeight(weight string) blockOpt

func Height

func Height(height float64) blockOpt

func IsType

func IsType(node *Node, typ Type) bool

func Padding

func Padding(top, right, bottom, left float64) blockOpt

func Reflow

func Reflow(node *Node) error

func Resize

func Resize(node *Node) error

func Size

func Size(w, h float64) *size

func Width

func Width(width float64) blockOpt

func X

func X(x float64) blockOpt

func XY

func XY(x, y float64) blockOpt

func Y

func Y(y float64) blockOpt

Types

type Horizontal

type Horizontal int
const (
	Left Horizontal = iota
	Center
	Right
)

type Node

type Node struct {
	X, Y          float64
	Width, Height float64
	Padding       [4]float64
	Order         Order
	Horizontal    Horizontal
	Vertical      Vertical
	Attributes    map[string]any
	Children      []*Node
}

func Block

func Block(order Order, opts ...blockOpt) *Node

func Group

func Group(opts ...blockOpt) *Node

func Image

func Image(src string) *Node

func Stack

func Stack(opts ...blockOpt) *Node

func Text

func Text(text string, opts ...blockOpt) *Node

func (*Node) AlignChildren

func (n *Node) AlignChildren()

func (*Node) GetChildrenContainer

func (n *Node) GetChildrenContainer() (x, y, w, h float64)

GetChildrenContainer used to calculate the max width and height of the all children for current node. It uses x and y coordinate of the parent

func (*Node) GetContainer

func (n *Node) GetContainer() (x, y, w, h float64)

GetContainer returns the x, y, width, and height of the container of the node. The container is the area where the children of the node are placed.

func (*Node) IsGroup

func (n *Node) IsGroup() bool

func (*Node) IsStack

func (n *Node) IsStack() bool

type Nodes added in v0.0.2

type Nodes []*Node

type Order

type Order int
const (
	StackOrder Order = iota
	GroupOrder
)

type Type

type Type int
const (
	ImageType Type
	TextType
)

type Vertical

type Vertical int
const (
	Top Vertical = iota
	Middle
	Bottom
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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