File: 016-double.lua

package info (click to toggle)
lua-gtk 0.9%2B20100528-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,176 kB
  • ctags: 1,934
  • sloc: ansic: 9,571; sh: 373; makefile: 241
file content (37 lines) | stat: -rwxr-xr-x 639 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /usr/bin/env lua
-- vim:sw=4:sts=4
-- Example by Miles Bader <miles@gnu.org>

require "gtk"
require "cairo"

assert(cairo.version_string())

w = gtk.window_new(gtk.WINDOW_TOPLEVEL)
w:realize()

c = gdk.cairo_create(w.window)

str = "hello"
t_ext = cairo.new 'text_extents_t'
c:text_extents (str, t_ext)

-- look at the structure
-- gtk.dump_struct(t_ext)

-- read double elements of structures

a = t_ext.width
b = t_ext.height
c = t_ext.x_advance


-- write
t_ext.height = 95.5

-- and read again.  Check that the surrounding fields haven't changed.
assert(t_ext.width == a)
assert(t_ext.height == 95.5)
assert(t_ext.x_advance == c)