Module gx stdlib

gx
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
1
Imported by:
12
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

Overview

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

gx is going to be merged with gg soon.

Aliases

This section is empty.

Constants

#constant black

black = Color{
	r: 0
	g: 0
	b: 0
}

#constant gray

gray = Color{
	r: 128
	g: 128
	b: 128
}

#constant white

white = Color{
	r: 255
	g: 255
	b: 255
}

#constant red

red = Color{
	r: 255
	g: 0
	b: 0
}

#constant green

green = Color{
	r: 0
	g: 255
	b: 0
}

#constant blue

blue = Color{
	r: 0
	g: 0
	b: 255
}

#constant yellow

yellow = Color{
	r: 255
	g: 255
	b: 0
}

#constant magenta

magenta = Color{
	r: 255
	g: 0
	b: 255
}

#constant cyan

cyan = Color{
	r: 0
	g: 255
	b: 255
}

#constant orange

orange = Color{
	r: 255
	g: 165
	b: 0
}

#constant purple

purple = Color{
	r: 128
	g: 0
	b: 128
}

#constant indigo

indigo = Color{
	r: 75
	g: 0
	b: 130
}

#constant pink

pink = Color{
	r: 255
	g: 192
	b: 203
}

#constant violet

violet = Color{
	r: 238
	g: 130
	b: 238
}

#constant dark_blue

dark_blue = Color{
	r: 0
	g: 0
	b: 139
}

#constant dark_gray

dark_gray = Color{
	r: 169
	g: 169
	b: 169
}

#constant dark_green

dark_green = Color{
	r: 0
	g: 100
	b: 0
}

#constant dark_red

dark_red = Color{
	r: 139
	g: 0
	b: 0
}

#constant light_blue

light_blue = Color{
	r: 173
	g: 216
	b: 230
}

#constant light_gray

light_gray = Color{
	r: 211
	g: 211
	b: 211
}

#constant light_green

light_green = Color{
	r: 144
	g: 238
	b: 144
}

#constant light_red

light_red = Color{
	r: 255
	g: 204
	b: 203
}

#constant align_left

align_left  = HorizontalAlign.left

TODO: remove these, and use the enum everywhere

#constant align_right

align_right = HorizontalAlign.right

TODO: remove these, and use the enum everywhere

Sum types

This section is empty.

Functions

#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

#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

Structs

#struct Color

pub 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) operator+

fn (a Color) + (b Color) Color

+ adds b to a, with a maximum value of 255 for each channel

#fn (Color) operator-

fn (a Color) - (b Color) Color

- subtracts b from a, with a minimum value of 0 for each channel

#fn (Color) operator*

fn (c Color) * (c2 Color) Color

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

#fn (Color) operator/

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

inline
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

inline
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

inline
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

pub 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
pub struct TextCfg {
pub:
	color          Color = 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'.

Interfaces

This section is empty.

Enums

#enum HorizontalAlign

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

#enum VerticalAlign

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

#enum HorizontalAlign

JavaScript
pub enum HorizontalAlign {
	left
	center
	right
}

pub enum VerticalAlign {