Skip to content

gx #

Description

gx is a complementary module to gg, that just provides some predefined graphical color names/operations.

Note > gx is going to be merged with gg soon.

Constants #

const black = Color{
	r: 0
	g: 0
	b: 0
}
const gray = Color{
	r: 128
	g: 128
	b: 128
}
const white = Color{
	r: 255
	g: 255
	b: 255
}
const red = Color{
	r: 255
	g: 0
	b: 0
}
const green = Color{
	r: 0
	g: 255
	b: 0
}
const blue = Color{
	r: 0
	g: 0
	b: 255
}
const yellow = Color{
	r: 255
	g: 255
	b: 0
}
const magenta = Color{
	r: 255
	g: 0
	b: 255
}
const cyan = Color{
	r: 0
	g: 255
	b: 255
}
const orange = Color{
	r: 255
	g: 165
	b: 0
}
const purple = Color{
	r: 128
	g: 0
	b: 128
}
const indigo = Color{
	r: 75
	g: 0
	b: 130
}
const pink = Color{
	r: 255
	g: 192
	b: 203
}
const violet = Color{
	r: 238
	g: 130
	b: 238
}
const dark_blue = Color{
	r: 0
	g: 0
	b: 139
}
const dark_gray = Color{
	r: 169
	g: 169
	b: 169
}
const dark_green = Color{
	r: 0
	g: 100
	b: 0
}
const dark_red = Color{
	r: 139
	g: 0
	b: 0
}
const light_blue = Color{
	r: 173
	g: 216
	b: 230
}
const light_gray = Color{
	r: 211
	g: 211
	b: 211
}
const light_green = Color{
	r: 144
	g: 238
	b: 144
}
const light_red = Color{
	r: 255
	g: 204
	b: 203
}
const align_left = HorizontalAlign.left

Todo: remove these, and use the enum everywhere

const align_right = HorizontalAlign.right

fn color_from_string #

fn color_from_string(s string) Color

color_from_string returns a Color, corresponding to the given string or black Color if string is not found in lookup table, or a hex color if starting with #

fn hex #

fn hex(color int) Color

hex takes in a 32 bit integer and splits it into 4 byte values

fn rgb #

fn rgb(r u8, g u8, b u8) Color

rgb builds a Color instance from given r, g, b values

fn rgba #

fn rgba(r u8, g u8, b u8, a u8) Color

rgba builds a Color instance from given r, g, b, a values

enum HorizontalAlign #

enum HorizontalAlign {
	left   = C.FONS_ALIGN_LEFT
	center = C.FONS_ALIGN_CENTER
	right  = C.FONS_ALIGN_RIGHT
}

enum VerticalAlign #

enum VerticalAlign {
	top      = C.FONS_ALIGN_TOP
	middle   = C.FONS_ALIGN_MIDDLE
	bottom   = C.FONS_ALIGN_BOTTOM
	baseline = C.FONS_ALIGN_BASELINE
}

struct Color #

struct Color {
pub mut:
	r u8
	g u8
	b u8
	a u8 = 255
}

Color represents a 32 bit color value in sRGB format

fn (Color) + #

fn (a Color) + (b Color) Color
  • adds b to a, with a maximum value of 255 for each channel

fn (Color) - #

fn (a Color) - (b Color) Color
  • subtracts b from a, with a minimum value of 0 for each channel

fn (Color) * #

fn (c Color) * (c2 Color) Color
  • multiplies Color c and c2 keeping channel values in [0, 255] range

fn (Color) / #

fn (c Color) / (c2 Color) Color

/ divides c by c2 and converts each channel's value to u8(int)

fn (Color) over #

fn (a Color) over(b Color) Color

over implements an a over b operation. see https://keithp.com/~keithp/porterduff/p253-porter.pdf

fn (Color) eq #

fn (c Color) eq(c2 Color) bool

eq checks if color c and c2 are equal in every channel

fn (Color) str #

fn (c Color) str() string

str returns a string representation of the Color c

fn (Color) rgba8 #

fn (c Color) rgba8() int

rgba8 converts a color value to an int in the RGBA8 order. see https://developer.apple.com/documentation/coreimage/ciformat

fn (Color) bgra8 #

fn (c Color) bgra8() int

bgra8 converts a color value to an int in the BGRA8 order. see https://developer.apple.com/documentation/coreimage/ciformat

fn (Color) abgr8 #

fn (c Color) abgr8() int

abgr8 converts a color value to an int in the ABGR8 order. see https://developer.apple.com/documentation/coreimage/ciformat

fn (Color) to_css_string #

fn (c Color) to_css_string() string

to_css_string returns a CSS compatible string e.g. rgba(10,11,12,13) of the color c.

struct Image #

struct Image {
mut:
	obj voidptr
pub:
	id     int
	width  int
	height int
}

fn (Image) is_empty #

fn (i Image) is_empty() bool

is_empty returns true if the Image i is empty.

struct TextCfg #

@[params]
struct TextCfg {
pub:
	color          Color = gx.black
	size           int   = 16
	align          HorizontalAlign = .left
	vertical_align VerticalAlign   = .top
	max_width      int
	family         string
	bold           bool
	mono           bool
	italic         bool
}

fn (TextCfg) to_css_string #

fn (cfg TextCfg) to_css_string() string

to_css_string returns a CSS compatible string of the TextCfg cfg. For example: 'mono 14px serif'.