cutils

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cutils provides common parsing/conversion code for components to cut down on duplication

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombineErrors

func CombineErrors(history, latest error) error

CombineErrors combines two errors, maintaining a history of errors separated by newlines

func ExclusiveNor

func ExclusiveNor(args ...bool) bool

ExclusiveNor returns false if one and only one of the passed in booleans is true

func ExclusiveOr

func ExclusiveOr(args ...bool) bool

ExclusiveOr returns true if one and only one of the passed in booleans is true

func ExtractFloat

func ExtractFloat(raw, name string, props map[string][]string) (float64, map[string][]string, error)

ExtractFloat extracts a flot64 or variable(s) from the raw JSON data

func ExtractInt

func ExtractInt(raw, name string, props map[string][]string) (int, map[string][]string, error)

ExtractInt extracts an integer or variable(s) from the raw JSON data

func ExtractString

func ExtractString(raw, name string, props map[string][]string) (string, map[string][]string, error)

ExtractString extracts a string or variable(s) from the raw JSON data

func LoadFontFile

func LoadFontFile(fs vfs.FileSystem, fileName interface{}) (*truetype.Font, error)

LoadFontFile returns the font file found at the specified path on the specified file system

func ParseColourStrings

func ParseColourStrings(colours ColourStrings, prefix string, inputProps map[string][]string) (color.NRGBA, map[string][]string, error)

ParseColourStrings turns a set of colour strings and an optional identifying prefix representing a colour channel each into a color.NRGBA struct

func ParseFont

func ParseFont(fontName, fileName, url string, opts ParseFontOptions) (*truetype.Font, map[string][]string, error)

ParseFont turns a font name, file path or url into a truetype font

func ParsePoint

func ParsePoint(x, y, xName, yName string, props map[string][]string) (image.Point, map[string][]string, error)

ParsePoint turns an X and Y string into an image.Point

func ScaleFontsToWidth

func ScaleFontsToWidth(currentSize float64, currentWidth, maxWidth int, alignment TextAlignment) (newSize float64, alignmentOffset int)

ScaleFontsToWidth scales the input float to match the font size and alignment parameters

func SetBool

func SetBool(value interface{}) (bool, error)

SetBool turns an interface into a bool and an error

func SetColour

func SetColour(value interface{}) (color.Color, error)

SetColour turns an interface into a colour and an error

func SetFloat64

func SetFloat64(value interface{}) (float64, error)

SetFloat64 turns an interface into a float64 and an error

func SetImage

func SetImage(value interface{}) (image.Image, error)

SetImage turns an interface into an image and an error

func SetInt

func SetInt(value interface{}) (int, error)

SetInt turns an interface into a string and an error

func SetString

func SetString(value interface{}) (string, error)

SetString turns an interface into a string and an error

func SetTime

func SetTime(value interface{}) (time.Time, error)

SetTime turns an interface into a time and an error

func SetTimePointer

func SetTimePointer(value interface{}) (*time.Time, error)

SetTimePointer turns an interface into a time pointer and an error

func SetUint8

func SetUint8(value interface{}) (uint8, error)

SetUint8 turns an interface into a uint8 and an error

Types

type ColourStrings

type ColourStrings struct {
	// R, G, B, A are the colour channels
	R, G, B, A string
}

ColourStrings is an RGBA set of strings

type ParseFontOptions

type ParseFontOptions struct {
	// Props is the initial named properties map
	Props map[string][]string
	// FileSystem is the vfs FileSystem to use
	FileSystem vfs.FileSystem
	// FontPool is the gosysfonts Pool to use
	FontPool gosysfonts.Pool
}

ParseFontOptions are the optional parameters for ParseFont

type TextAlignment

type TextAlignment int

TextAlignment is a text alignment.

const (
	// TextAlignmentLeft aligns text left
	TextAlignmentLeft TextAlignment = iota
	// TextAlignmentRight aligns text right
	TextAlignmentRight
	// TextAlignmentCentre aligns text centrally
	TextAlignmentCentre
)

func ExtractTextAlignment

func ExtractTextAlignment(raw, name string, props map[string][]string) (TextAlignment, map[string][]string, error)

ExtractTextAlignment extracts a TextAlignment from the raw JSON data

func StringToAlignment

func StringToAlignment(alignment string) (converted TextAlignment)

StringToAlignment converts strings to TextAlignments, defaulting to Left

Jump to

Keyboard shortcuts

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