gg #

fn dpi_scale #

fn dpi_scale() f32

fn high_dpi #

fn high_dpi() bool

fn new_context #

fn new_context(cfg Config) &Context

fn screen_size #

fn screen_size() Size

fn system_font_path #

fn system_font_path() string

fn window_size #

fn window_size() Size

window_size returns the Size of the active window

fn window_size_real_pixels #

fn window_size_real_pixels() Size

window_size_real_pixels returns the Size of the active window without scale

type FNCb #

type FNCb = fn (data voidptr)

type FNChar #

type FNChar = fn (c u32, data voidptr)

type FNClick #

type FNClick = fn (x f32, y f32, button MouseButton, data voidptr)

type FNEvent #

type FNEvent = fn (e &Event, data voidptr)

type FNFail #

type FNFail = fn (msg string, data voidptr)

type FNKeyDown #

type FNKeyDown = fn (c KeyCode, m Modifier, data voidptr)

type FNKeyUp #

type FNKeyUp = fn (c KeyCode, m Modifier, data voidptr)

type FNMove #

type FNMove = fn (x f32, y f32, data voidptr)

type FNUnClick #

type FNUnClick = fn (x f32, y f32, button MouseButton, data voidptr)

fn (FT) flush #

fn (ft &FT) flush()

enum KeyCode #

enum KeyCode {
	invalid = 0
	space = 32
	apostrophe = 39
	comma = 44
	minus = 45
	period = 46
	slash = 47
	_0 = 48
	_1 = 49
	_2 = 50
	_3 = 51
	_4 = 52
	_5 = 53
	_6 = 54
	_7 = 55
	_8 = 56
	_9 = 57
	semicolon = 59
	equal = 61
	a = 65
	b = 66
	c = 67
	d = 68
	e = 69
	f = 70
	g = 71
	h = 72
	i = 73
	j = 74
	k = 75
	l = 76
	m = 77
	n = 78
	o = 79
	p = 80
	q = 81
	r = 82
	s = 83
	t = 84
	u = 85
	v = 86
	w = 87
	x = 88
	y = 89
	z = 90
	left_bracket = 91
	backslash = 92
	right_bracket = 93
	grave_accent = 96
	world_1 = 161
	world_2 = 162
	escape = 256
	enter = 257
	tab = 258
	backspace = 259
	insert = 260
	delete = 261
	right = 262
	left = 263
	down = 264
	up = 265
	page_up = 266
	page_down = 267
	home = 268
	end = 269
	caps_lock = 280
	scroll_lock = 281
	num_lock = 282
	print_screen = 283
	pause = 284
	f1 = 290
	f2 = 291
	f3 = 292
	f4 = 293
	f5 = 294
	f6 = 295
	f7 = 296
	f8 = 297
	f9 = 298
	f10 = 299
	f11 = 300
	f12 = 301
	f13 = 302
	f14 = 303
	f15 = 304
	f16 = 305
	f17 = 306
	f18 = 307
	f19 = 308
	f20 = 309
	f21 = 310
	f22 = 311
	f23 = 312
	f24 = 313
	f25 = 314
	kp_0 = 320
	kp_1 = 321
	kp_2 = 322
	kp_3 = 323
	kp_4 = 324
	kp_5 = 325
	kp_6 = 326
	kp_7 = 327
	kp_8 = 328
	kp_9 = 329
	kp_decimal = 330
	kp_divide = 331
	kp_multiply = 332
	kp_subtract = 333
	kp_add = 334
	kp_enter = 335
	kp_equal = 336
	left_shift = 340
	left_control = 341
	left_alt = 342
	left_super = 343
	right_shift = 344
	right_control = 345
	right_alt = 346
	right_super = 347
	menu = 348
}

enum Modifier #

enum Modifier {
	shift
	ctrl
	alt
	super
}

enum MouseButton #

enum MouseButton {
	left = 0
	right = 1
	middle = 2
	invalid = 256
}

enum MouseButtons #

enum MouseButtons {
	left
	right
	middle
}

NB: unlike the MouseButton enum from above, the [flag]-ed enum here can have combined states, representing several pressed buttons at once.

enum PenLineType #

enum PenLineType {
	solid
	dashed
	dotted
}

struct Config #

struct Config {
pub:
	width         int
	height        int
	use_ortho     bool
	retina        bool
	resizable     bool
	user_data     voidptr
	font_size     int
	create_window bool

	window_title      string
	borderless_window bool
	always_on_top     bool
	bg_color          gx.Color
	init_fn           FNCb   = voidptr(0)
	frame_fn          FNCb   = voidptr(0)
	native_frame_fn   FNCb   = voidptr(0)
	cleanup_fn        FNCb   = voidptr(0)
	fail_fn           FNFail = voidptr(0)

	event_fn FNEvent = voidptr(0)
	quit_fn  FNEvent = voidptr(0)

	keydown_fn FNKeyDown = voidptr(0)
	keyup_fn   FNKeyUp   = voidptr(0)
	char_fn    FNChar    = voidptr(0)

	move_fn    FNMove    = voidptr(0)
	click_fn   FNClick   = voidptr(0)
	unclick_fn FNUnClick = voidptr(0)
	leave_fn   FNEvent   = voidptr(0)
	enter_fn   FNEvent   = voidptr(0)
	resized_fn FNEvent   = voidptr(0)
	scroll_fn  FNEvent   = voidptr(0)

	fullscreen    bool
	scale         f32 = 1.0
	sample_count  int
	swap_interval int = 1

	font_path             string
	custom_bold_font_path string
	ui_mode               bool

	font_bytes_normal []byte
	font_bytes_bold   []byte
	font_bytes_mono   []byte
	font_bytes_italic []byte
	native_rendering  bool

	enable_dragndrop             bool
	max_dropped_files            int = 1
	max_dropped_file_path_length int = 2048
}

struct Context #

struct Context {
mut:
	render_text bool = true

	image_cache   []Image
	needs_refresh bool = true
	ticks         int
pub:
	native_rendering bool
pub mut:
	scale f32 = 1.0

	width       int
	height      int
	clear_pass  C.sg_pass_action
	window      C.sapp_desc
	timage_pip  C.sgl_pipeline
	config      Config
	ft          &FT
	font_inited bool
	ui_mode     bool
	frame       u64

	mbtn_mask     byte
	mouse_buttons MouseButtons
	mouse_pos_x   int
	mouse_pos_y   int
	mouse_dx      int
	mouse_dy      int
	scroll_x      int
	scroll_y      int

	key_modifiers     Modifier
	key_repeat        bool
	pressed_keys      [key_code_max]bool
	pressed_keys_edge [key_code_max]bool
}

fn (Context) begin #

fn (gg &Context) begin()

fn (Context) cache_image #

fn (mut ctx Context) cache_image(img Image) int

fn (Context) create_image #

fn (mut ctx Context) create_image(file string) Image

TODO return ?Image

fn (Context) create_image_from_byte_array #

fn (mut ctx Context) create_image_from_byte_array(b []byte) Image

fn (Context) create_image_from_memory #

fn (mut ctx Context) create_image_from_memory(buf &byte, bufsize int) Image

fn (Context) create_image_with_size #

fn (mut ctx Context) create_image_with_size(file string, width int, height int) Image

TODO copypasta

fn (Context) draw_arc #

fn (ctx &Context) draw_arc(x f32, y f32, r int, start_angle f32, arc_angle f32, segments int, c gx.Color)

fn (Context) draw_arc_line #

fn (ctx &Context) draw_arc_line(x f32, y f32, r int, start_angle f32, arc_angle f32, segments int, c gx.Color)

fn (Context) draw_circle #

fn (ctx &Context) draw_circle(x f32, y f32, r f32, c gx.Color)

fn (Context) draw_circle_line #

fn (ctx &Context) draw_circle_line(x f32, y f32, r int, segments int, c gx.Color)

fn (Context) draw_circle_with_segments #

fn (ctx &Context) draw_circle_with_segments(x f32, y f32, r f32, segments int, c gx.Color)

fn (Context) draw_convex_poly #

fn (ctx &Context) draw_convex_poly(points []f32, c gx.Color)

draw_convex_poly draws a convex polygon, given an array of points, and a color.
Note that the points must be given in clockwise order.

fn (Context) draw_cubic_bezier #

fn (ctx &Context) draw_cubic_bezier(points []f32, c gx.Color)

draw_cubic_bezier draws a cubic Bézier curve, also known as a spline, from four points.
The four points is provided as one points array which contains a stream of point pairs (x and y coordinates).
Thus a cubic Bézier could be declared as: points := [x1, y1, control_x1, control_y1, control_x2, control_y2, x2, y2].
Please see draw_cubic_bezier_in_steps to control the amount of steps (segments) used to draw the curve.

fn (Context) draw_cubic_bezier_in_steps #

fn (ctx &Context) draw_cubic_bezier_in_steps(points []f32, steps u32, c gx.Color)

draw_cubic_bezier_in_steps draws a cubic Bézier curve, also known as a spline, from four points.
The smoothness of the curve can be controlled with the steps parameter. steps determines how many iterations is taken to draw the curve.
The four points is provided as one points array which contains a stream of point pairs (x and y coordinates).
Thus a cubic Bézier could be declared as: points := [x1, y1, control_x1, control_y1, control_x2, control_y2, x2, y2].

fn (Context) draw_empty_poly #

fn (ctx &Context) draw_empty_poly(points []f32, c gx.Color)

draw_empty_poly - draws the borders of a polygon, given an array of points, and a color.
Note that the points must be given in clockwise order.

fn (Context) draw_empty_rect #

fn (ctx &Context) draw_empty_rect(x f32, y f32, w f32, h f32, c gx.Color)

fn (Context) draw_empty_rounded_rect #

fn (ctx &Context) draw_empty_rounded_rect(x f32, y f32, w f32, h f32, radius f32, border_color gx.Color)

fn (Context) draw_empty_square #

fn (ctx &Context) draw_empty_square(x f32, y f32, s f32, c gx.Color)

fn (Context) draw_image #

fn (ctx &Context) draw_image(x f32, y f32, width f32, height f32, img_ &Image)

draw_image draws the provided image onto the screen

fn (Context) draw_image_3d #

fn (ctx &Context) draw_image_3d(x f32, y f32, z f32, width f32, height f32, img_ &Image)

draw_image_3d draws an image with a z depth

fn (Context) draw_image_by_id #

fn (ctx &Context) draw_image_by_id(x f32, y f32, width f32, height f32, id int)

draw_image_by_id draws an image by its id

fn (Context) draw_image_flipped #

fn (ctx &Context) draw_image_flipped(x f32, y f32, width f32, height f32, img_ &Image)

draw_image_flipped draws the provided image flipped horizontally (use draw_image_with_config to flip vertically)

fn (Context) draw_image_part #

fn (ctx &Context) draw_image_part(img_rect Rect, part_rect Rect, img_ &Image)

Draw part of an image using uv coordinates img_rect is the size and position (in pixels on screen) of the displayed rectangle (ie the draw_image args) part_rect is the size and position (in absolute pixels in the image) of the wanted part eg. On a 600600 context, to display only the first 400400 pixels of a 2000*2000 image on the entire context surface, call : draw_image_part(Rect{0, 0, 600, 600}, Rect{0, 0, 400, 400}, img)

fn (Context) draw_image_with_config #

fn (ctx &Context) draw_image_with_config(config DrawImageConfig)

draw_image_with_config takes in a config that details how the provided image should be drawn onto the screen

fn (Context) draw_line #

fn (ctx &Context) draw_line(x f32, y f32, x2 f32, y2 f32, c gx.Color)

draw_line draws a line between the points provided

fn (Context) draw_line_with_config #

fn (ctx &Context) draw_line_with_config(x f32, y f32, x2 f32, y2 f32, config PenConfig)

draw_line_with_config draws a line between the points provided with the PenConfig

fn (Context) draw_rect #

fn (ctx &Context) draw_rect(x f32, y f32, w f32, h f32, c gx.Color)

fn (Context) draw_rounded_rect #

fn (ctx &Context) draw_rounded_rect(x f32, y f32, w f32, h f32, radius f32, color gx.Color)

fn (Context) draw_square #

fn (ctx &Context) draw_square(x f32, y f32, s f32, c gx.Color)

fn (Context) draw_text #

fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg)

fn (Context) draw_text_def #

fn (ctx &Context) draw_text_def(x int, y int, text string)

fn (Context) draw_triangle #

fn (ctx &Context) draw_triangle(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, c gx.Color)

fn (Context) end #

fn (gg &Context) end()

fn (Context) get_cached_image_by_idx #

fn (mut ctx Context) get_cached_image_by_idx(image_idx int) &Image

fn (Context) new_streaming_image #

fn (mut ctx Context) new_streaming_image(w int, h int, channels int, sicfg StreamingImageConfig) int

new_streaming_image returns a cached image_idx of a special image, that can be updated each frame by calling: gg.update_pixel_data(image_idx, buf) ... where buf is a pointer to the actual pixel data for the image.
NB: you still need to call app.gg.draw_image after that, to actually draw it.

fn (Context) quit #

fn (ctx &Context) quit()

quit closes the context window and exits the event loop for it

fn (Context) refresh_ui #

fn (mut ctx Context) refresh_ui()

fn (Context) resize #

fn (mut ctx Context) resize(width int, height int)

resize the context's Window

fn (Context) run #

fn (gg &Context) run()

fn (Context) set_bg_color #

fn (mut ctx Context) set_bg_color(c gx.Color)

fn (Context) set_cfg #

fn (ctx &Context) set_cfg(cfg gx.TextCfg)

fn (Context) set_pixel #

fn (ctx &Context) set_pixel(x f32, y f32, c gx.Color)

fn (Context) set_pixels #

fn (ctx &Context) set_pixels(points []f32, c gx.Color)

fn (Context) text_height #

fn (ctx &Context) text_height(s string) int

fn (Context) text_size #

fn (ctx &Context) text_size(s string) (int, int)

fn (Context) text_width #

fn (ctx &Context) text_width(s string) int

fn (Context) update_pixel_data #

fn (mut ctx Context) update_pixel_data(cached_image_idx int, buf &byte)

update_pixel_data is a helper for working with image streams (i.e. images, that are updated dynamically by the CPU on each frame)

struct DrawImageConfig #

struct DrawImageConfig {
pub:
	flip_x    bool
	flip_y    bool
	img       &Image = voidptr(0)
	img_id    int
	img_rect  Rect
	part_rect Rect
	rotate    int
	z         f32
	color     gx.Color = gx.white
}

DrawImageConfig struct defines the various options that can be used to draw an image onto the screen

struct Event #

struct Event {
pub mut:
	frame_count        u64
	typ                sapp.EventType
	key_code           KeyCode
	char_code          u32
	key_repeat         bool
	modifiers          u32
	mouse_button       MouseButton
	mouse_x            f32
	mouse_y            f32
	mouse_dx           f32
	mouse_dy           f32
	scroll_x           f32
	scroll_y           f32
	num_touches        int
	touches            [8]C.sapp_touchpoint
	window_width       int
	window_height      int
	framebuffer_width  int
	framebuffer_height int
}

struct Image #

struct Image {
pub mut:
	id          int
	width       int
	height      int
	nr_channels int
	ok          bool
	data        voidptr
	ext         string
	simg_ok     bool
	simg        C.sg_image
	path        string
}

fn (Image) init_sokol_image #

fn (mut img Image) init_sokol_image() &Image

fn (Image) update_pixel_data #

fn (mut img Image) update_pixel_data(buf &byte)

struct PenConfig #

struct PenConfig {
	color     gx.Color
	line_type PenLineType = .solid
	thickness int = 1
}

struct Rect #

struct Rect {
pub:
	x      f32
	y      f32
	width  f32
	height f32
}

struct Size #

struct Size {
pub:
	width  int
	height int
}

struct StreamingImageConfig #

struct StreamingImageConfig {
	pixel_format gfx.PixelFormat = .rgba8
	wrap_u       gfx.Wrap        = .clamp_to_edge
	wrap_v       gfx.Wrap        = .clamp_to_edge
	min_filter   gfx.Filter      = .linear
	mag_filter   gfx.Filter      = .linear
	num_mipmaps  int = 1
	num_slices   int = 1
}