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 ¶
- func AreSame[T comparable](s Sides[T]) bool
- func AreZero[T comparable](s Sides[T]) bool
- type Colors
- type Floats
- func (sf Floats) Add(other Floats) Floats
- func (sf Floats) Max(other Floats) Floats
- func (sf Floats) Min(other Floats) Floats
- func (sf Floats) MulScalar(s float32) Floats
- func (sf Floats) Pos() math32.Vector2
- func (sf Floats) Round() Floats
- func (sf Floats) Size() math32.Vector2
- func (sf Floats) Sub(other Floats) Floats
- func (sf Floats) ToValues() Values
- type Indexes
- func (i Indexes) Desc() string
- func (i Indexes) Int64() int64
- func (i Indexes) MarshalText() ([]byte, error)
- func (i *Indexes) SetInt64(in int64)
- func (i *Indexes) SetString(s string) error
- func (i Indexes) String() string
- func (i *Indexes) UnmarshalText(text []byte) error
- func (i Indexes) Values() []enums.Enum
- type Sides
- func (s *Sides[T]) Set(vals ...T) *Sides[T]
- func (s *Sides[T]) SetAll(val T) *Sides[T]
- func (s *Sides[T]) SetAny(a any) error
- func (s *Sides[T]) SetBottom(bottom T) *Sides[T]
- func (s *Sides[T]) SetHorizontal(val T) *Sides[T]
- func (s *Sides[T]) SetLeft(left T) *Sides[T]
- func (s *Sides[T]) SetRight(right T) *Sides[T]
- func (s *Sides[T]) SetString(str string) error
- func (s *Sides[T]) SetTop(top T) *Sides[T]
- func (s *Sides[T]) SetVertical(val T) *Sides[T]
- func (s *Sides[T]) Zero() *Sides[T]
- type Values
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 ¶
Colors contains color values for each side/corner of a box
func NewColors ¶
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.
type Floats ¶
Floats contains float32 values for each side/corner of a box
func NewFloats ¶
NewFloats is a helper that creates new side/corner floats and calls Set on them with the given values.
func (Floats) Max ¶
Max returns a new side floats containing the maximum values of the two side floats
func (Floats) Min ¶
Min returns a new side floats containing the minimum values of the two side floats
func (Floats) MulScalar ¶
MulScalar multiplies each side by the given scalar value and returns the result.
func (Floats) Round ¶
Round returns a new side floats with each side value rounded to the nearest whole number.
func (Floats) Size ¶
Size returns the toal size the side/corner values take up (Left + Right, Top + Bottom)
func (Floats) ToValues ¶
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 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) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Indexes) SetString ¶
SetString sets the Indexes value from its string representation, and returns an error if the string is invalid.
func (*Indexes) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
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 ¶
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 ¶
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]) SetHorizontal ¶
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]) SetVertical ¶
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
type Values ¶
Values contains units.Value values for each side/corner of a box
func NewValues ¶
NewValues is a helper that creates new side/corner values and calls Set on them with the given values.