sides

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: BSD-3-Clause Imports: 10 Imported by: 1

Documentation

Overview

Package sides provides flexible representation of box sides or corners, with either a single value for all, or different values for subsets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreSame

func AreSame[T comparable](s Sides[T]) bool

AreSame returns whether all of the sides/corners are the same

func AreZero

func AreZero[T comparable](s Sides[T]) bool

AreZero returns whether all of the sides/corners are equal to zero

Types

type Colors

type Colors struct {
	Sides[color.RGBA]
}

Colors contains color values for each side/corner of a box

func NewColors

func NewColors(vals ...color.RGBA) Colors

NewColors is a helper that creates new side/corner colors and calls Set on them with the given values. It does not return any error values and just logs them.

func (*Colors) SetAny

func (s *Colors) SetAny(a any, base color.Color) error

SetAny sets the sides/corners from the given value of any type

func (*Colors) SetString

func (s *Colors) SetString(str string, base color.Color) error

SetString sets the sides/corners from the given string value

type Floats

type Floats struct {
	Sides[float32]
}

Floats contains float32 values for each side/corner of a box

func NewFloats

func NewFloats(vals ...float32) Floats

NewFloats is a helper that creates new side/corner floats and calls Set on them with the given values.

func (Floats) Add

func (sf Floats) Add(other Floats) Floats

Add adds the side floats to the other side floats and returns the result

func (Floats) Max

func (sf Floats) Max(other Floats) Floats

Max returns a new side floats containing the maximum values of the two side floats

func (Floats) Min

func (sf Floats) Min(other Floats) Floats

Min returns a new side floats containing the minimum values of the two side floats

func (Floats) MulScalar

func (sf Floats) MulScalar(s float32) Floats

MulScalar multiplies each side by the given scalar value and returns the result.

func (Floats) Pos

func (sf Floats) Pos() math32.Vector2

Pos returns the position offset casued by the side/corner values (Left, Top)

func (Floats) Round

func (sf Floats) Round() Floats

Round returns a new side floats with each side value rounded to the nearest whole number.

func (Floats) Size

func (sf Floats) Size() math32.Vector2

Size returns the toal size the side/corner values take up (Left + Right, Top + Bottom)

func (Floats) Sub

func (sf Floats) Sub(other Floats) Floats

Sub subtracts the other side floats from the side floats and returns the result

func (Floats) ToValues

func (sf Floats) ToValues() Values

ToValues returns the side floats a Values composed of units.UnitDot values

type Indexes

type Indexes int32 //enums:enum

Indexes provides names for the Sides in order defined

const (
	Top Indexes = iota
	Right
	Bottom
	Left
)
const IndexesN Indexes = 4

IndexesN is the highest valid value for type Indexes, plus one.

func IndexesValues

func IndexesValues() []Indexes

IndexesValues returns all possible values for the type Indexes.

func (Indexes) Desc

func (i Indexes) Desc() string

Desc returns the description of the Indexes value.

func (Indexes) Int64

func (i Indexes) Int64() int64

Int64 returns the Indexes value as an int64.

func (Indexes) MarshalText

func (i Indexes) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Indexes) SetInt64

func (i *Indexes) SetInt64(in int64)

SetInt64 sets the Indexes value from an int64.

func (*Indexes) SetString

func (i *Indexes) SetString(s string) error

SetString sets the Indexes value from its string representation, and returns an error if the string is invalid.

func (Indexes) String

func (i Indexes) String() string

String returns the string representation of this Indexes value.

func (*Indexes) UnmarshalText

func (i *Indexes) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Indexes) Values

func (i Indexes) Values() []enums.Enum

Values returns all possible values for the type Indexes.

type Sides

type Sides[T any] struct {

	// top/top-left value
	Top T

	// right/top-right value
	Right T

	// bottom/bottom-right value
	Bottom T

	// left/bottom-left value
	Left T
}

Sides contains values for each side or corner of a box. If Sides contains sides, the struct field names correspond directly to the side values (ie: Top = top side value). If Sides contains corners, the struct field names correspond to the corners as follows: Top = top left, Right = top right, Bottom = bottom right, Left = bottom left.

func NewSides

func NewSides[T any](vals ...T) *Sides[T]

NewSides is a helper that creates new sides/corners of the given type and calls Set on them with the given values.

func (*Sides[T]) Set

func (s *Sides[T]) Set(vals ...T) *Sides[T]

Set sets the values of the sides/corners from the given list of 0 to 4 values. If 0 values are provided, all sides/corners are set to the zero value of the type. If 1 value is provided, all sides/corners are set to that value. If 2 values are provided, the top/top-left and bottom/bottom-right are set to the first value and the right/top-right and left/bottom-left are set to the second value. If 3 values are provided, the top/top-left is set to the first value, the right/top-right and left/bottom-left are set to the second value, and the bottom/bottom-right is set to the third value. If 4 values are provided, the top/top-left is set to the first value, the right/top-right is set to the second value, the bottom/bottom-right is set to the third value, and the left/bottom-left is set to the fourth value. If more than 4 values are provided, the behavior is the same as with 4 values, but Set also logs a programmer error. This behavior is based on the CSS multi-side/corner setting syntax, like that with padding and border-radius (see https://www.w3schools.com/css/css_padding.asp and https://www.w3schools.com/cssref/css3_pr_border-radius.php)

func (*Sides[T]) SetAll

func (s *Sides[T]) SetAll(val T) *Sides[T]

SetAll sets the values for all of the sides/corners to the given value

func (*Sides[T]) SetAny

func (s *Sides[T]) SetAny(a any) error

SetAny sets the sides/corners from the given value of any type

func (*Sides[T]) SetBottom

func (s *Sides[T]) SetBottom(bottom T) *Sides[T]

SetBottom sets the bottom side to the given value

func (*Sides[T]) SetHorizontal

func (s *Sides[T]) SetHorizontal(val T) *Sides[T]

SetHorizontal sets the values for the sides/corners in the horizontal/diagonally ascending direction (right/top-right and left/bottom-left) to the given value

func (*Sides[T]) SetLeft

func (s *Sides[T]) SetLeft(left T) *Sides[T]

SetLeft sets the left side to the given value

func (*Sides[T]) SetRight

func (s *Sides[T]) SetRight(right T) *Sides[T]

SetRight sets the right side to the given value

func (*Sides[T]) SetString

func (s *Sides[T]) SetString(str string) error

SetString sets the sides/corners from the given string value

func (*Sides[T]) SetTop

func (s *Sides[T]) SetTop(top T) *Sides[T]

SetTop sets the top side to the given value

func (*Sides[T]) SetVertical

func (s *Sides[T]) SetVertical(val T) *Sides[T]

SetVertical sets the values for the sides/corners in the vertical/diagonally descending direction (top/top-left and bottom/bottom-right) to the given value

func (*Sides[T]) Zero

func (s *Sides[T]) Zero() *Sides[T]

Zero sets the values of all of the sides to zero.

type Values

type Values struct {
	Sides[units.Value]
}

Values contains units.Value values for each side/corner of a box

func NewValues

func NewValues(vals ...units.Value) Values

NewValues is a helper that creates new side/corner values and calls Set on them with the given values.

func (Values) Dots

func (sv Values) Dots() Floats

Dots returns the dot values of the sides/corners as a Floats. It does not compute them; see ToDots for that.

func (*Values) ToDots

func (sv *Values) ToDots(uc *units.Context) Floats

ToDots converts the values for each of the sides/corners to raw display pixels (dots) and sets the Dots field for each of the values. It returns the dot values as a Floats.

Jump to

Keyboard shortcuts

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