util

package
v0.0.0-...-e7ac65d Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// Const for the middle of a gravity axis
	GravCenter = GravSide(0)
	// Const for the negative end of
	// a gravity axis (left, top, etc.)
	GravNeg = GravSide(-1)
	// Const for the positive end of
	// a gravity axis (right, bottom, etc.)
	GravPos = GravSide(1)
)
View Source
const DefaultOrientation = VerticalOrientation

Const of the default orientation

View Source
const DefaultScaleOption = ScaleToFit

Const for the default scale option

View Source
const HorizontalOrientation = Orientation("horizontal")

Const of a horizontal orientation

View Source
const NoScale = ScaleOption("none")

Const for not scaling an image

View Source
const Percent = Unit("%")

Const for a percentage "unit"

View Source
const Pixels = Unit("px")

Const for a unit of pixels

View Source
const ScaleToFill = ScaleOption("fill")

Const for image scaling to fill

View Source
const ScaleToFit = ScaleOption("fit")

Const for image scaling to fit

View Source
const Stretch = ScaleOption("stretch")

Const for stretching an image

View Source
const Tiled = ScaleOption("tiled")

Const for tiling an image

View Source
const VerticalOrientation = Orientation("vertical")

Const of a vertical orientation

View Source
const ZeroScaleOption = ScaleOption("")

A "zero" scale option, as in one where it is a zero value

Variables

View Source
var DefaultAbsoluteQuantity = AbsoluteQuantity{Quantity: 0, Unit: Pixels}

The default absolute quantity

View Source
var DefaultGravity = GravityTypes["top-left"]

The default gravity

View Source
var DefaultRelativeQuantity = RelativeQuantity{Quantity: 0, Unit: Pixels}

The default relative quantity

The default relative quantity

View Source
var GravityTypes = map[string]Gravity{
	"center":       {GravCenter, GravCenter},
	"top":          {GravCenter, GravNeg},
	"bottom":       {GravCenter, GravPos},
	"left":         {GravNeg, GravCenter},
	"right":        {GravPos, GravCenter},
	"top-left":     {GravNeg, GravNeg},
	"top-right":    {GravPos, GravNeg},
	"bottom-left":  {GravNeg, GravPos},
	"bottom-right": {GravPos, GravPos},
}

The possible gravity types as a map

View Source
var ZeroAbsoluteQuantity = AbsoluteQuantity{}

A "zero" absolute quantity, as in one where all the fields are zero values

View Source
var ZeroRelativeQuantity = RelativeQuantity{}

A "zero" relative quantity, as in one where all the fields are zero values

View Source
var ZeroRelativeSize = RelativeSize{}

A "zero" relative quantity, as in one where all the fields are zero values

Functions

func CreatePictureFromField

func CreatePictureFromField(fs http.FileSystem, field string) (pixel.Picture, error)

Function to create a picture from an XML string

func CreatePictureFromSVG

func CreatePictureFromSVG(svg *oksvg.SvgIcon, scale ScaleOption,
	w, h float64) pixel.Picture

Function to create a pixel.Picture from a given SVG

func LoadPicture

func LoadPicture(fs http.FileSystem, path string) (pixel.Picture, error)

Function to load an image and convert it to a pixel.Picture

func LoadSVG

func LoadSVG(fs http.FileSystem, path string,
	color color.RGBA) (*oksvg.SvgIcon, error)

Function to load an SVG

func ParseColor

func ParseColor(str string) (color.RGBA, error)

Function to parse a colour string to a color.RGBA type

Types

type AbsoluteQuantity

type AbsoluteQuantity struct {
	// The quantity itself
	Quantity int32

	// The unit. Only absolute units
	// are allowed (For example,
	// Pixel is allowed, Percent
	// isn't)
	Unit Unit
}

Type for the absolute size of something

func ParseAbsoluteQuantity

func ParseAbsoluteQuantity(str string) (size AbsoluteQuantity, err error)

Function to parse a string and convert it to an AbsoluteQuantity

type GravSide

type GravSide int8

type Gravity

type Gravity struct {
	// The horizontal gravity. Either
	// GravNeg (left), GravCenter
	// (center), GravPos (right)
	HorizGravity GravSide

	// The vertical gravity. Either
	// GravNeg (top), GravCenter
	// (center), GravPos (bottom)
	VertGravity GravSide
}

Type for the gravity of something

func ParseGravity

func ParseGravity(value string, def Gravity) (Gravity, error)

Function to parse a string into a gravity type. If value is not a valid gravity, the function returns an error. If the value is an empty string, the default gravity 'def' is used instead

func (*Gravity) String

func (g *Gravity) String() string

Function to convert a gravity to a string. Returns an empty string if the gravity type is unknown (or invalid)

type Orientation

type Orientation string

Type for the orientation of something

func ParseOrientation

func ParseOrientation(value string, def Orientation) (Orientation, error)

Function to parse a string into an orientation type. If value is not a valid orientation, the function returns an error. If the value is an empty string, the default orientation 'def' is used instead

type Ratio

type Ratio struct {
	// The left part of the ratio
	Left int
	// The right part of the ratio
	Right int
}

Type for a ratio (such as for an aspect ratio)

func ParseRatio

func ParseRatio(value string) (r Ratio, err error)

Function to parse a string into a ratio type. If value is not a valid ratio, the function returns an error

func (*Ratio) RestrictDimensions

func (r *Ratio) RestrictDimensions(dimensions pixel.Vec) pixel.Vec

Function to restrict the given dimensions so they fit the ratio todo this works but there's gotta be a better way

type RelativeQuantity

type RelativeQuantity struct {
	// The quantity itself. Zero if
	// MatchParent or MatchContent
	// are non-zero
	Quantity int32

	// The quantity's unit. Zero if
	// MatchParent or MatchContent
	// are non-zero
	Unit Unit
}

Type for a relative quantity

func ParseRelativeQuantity

func ParseRelativeQuantity(str string) (size RelativeQuantity, err error)

Function to parse a string and convert it to a RelativeQuantity

type RelativeSize

type RelativeSize struct {
	// Whether the quantity is the
	// same as the parent element
	MatchParent bool

	// Whether the quantity is the
	// same as the element's content
	MatchContent bool

	// Whether the quantity is the
	// same as the bounds from the
	// parent
	MatchBounds bool

	// The quantity itself. Zero if
	// MatchParent or MatchContent
	// are non-zero
	RelativeQuantity
}

Type for the relative size (usually width or height) of an element, which can match its parent, content or have a relative quantity

func ParseRelativeSize

func ParseRelativeSize(str string) (size RelativeSize, err error)

Function to parse a string and convert it to a RelativeSize

type ScaleOption

type ScaleOption string

Type for the scale option of something (usually an image)

func ParseScaleOption

func ParseScaleOption(value string) (ScaleOption, error)

Function to parse a string into a scale option type. If value is not a valid scale option, the function returns an error

type Unit

type Unit string

Type for a size unit

func ParseAbsoluteUnit

func ParseAbsoluteUnit(str string) (unit Unit, err error)

Function to parse a string and convert it to an absolute unit

func ParseUnit

func ParseUnit(str string) (unit Unit, err error)

Function to parse a string and convert it to a unit

Jump to

Keyboard shortcuts

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