-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlayerlib_demo.lua
184 lines (147 loc) · 4.11 KB
/
layerlib_demo.lua
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
--go @ luajit -joff -jv *
jit.off(true, true)
local ffi = require'ffi'
local nw = require'nw'
local ll = require'layerlib_h'
local glue = require'glue'
local cairo = require'cairo'
local app = nw:app()
local win = app:window{
w = 1200, h = 700,
}
local fonts = {
glue.readfile'OpenSans-Regular.ttf';
glue.readfile'OpenSans-Bold.ttf';
}
local function load_font(font_id, file_data_buf, file_size_buf)
local s = assert(fonts[font_id+1])
file_data_buf[0] = ffi.cast('void*', s)
file_size_buf[0] = #s
end
local function unload_font(font_id, file_data_buf, file_size_buf)
file_data_buf[0] = nil
file_size_buf[0] = 0
end
local s = glue.readfile('lorem_ipsum.txt')
--assert(ll.memtotal() == 0)
local llib = ll.layerlib(load_font, unload_font)
local font1_id = llib:font()
local font2_id = llib:font()
local e = llib:layer(nil)
local e1, e2 = e:child(0), e:child(1)
e.clip_content = ll.CLIP_PADDING
--e.clip_content = ll.CLIP_NONE
e.padding_left = 50
e.padding_top = 50
e.padding_right = 50
e.padding_bottom = 50
--e.border_width_left = 2
--e.border_width_top = 2
--e.border_width_right = 2
--e.border_width_bottom = 2
e.border_color_left = 0xff00ffff
e.border_color_top = 0xffff00ff
e.border_color_right = 0x008800ff
e.border_color_bottom = 0x888888ff
e.corner_radius_bottom_left = 20
e.corner_radius_bottom_right = 10
e.corner_radius_kappa = 1.2
e.padding = 20
e.border_width = 10
e.border_color = 0xff0000ff
e.background_type = ll.BACKGROUND_COLOR
e.background_color = 0x00336699 --0x336699ff
--e.background_type = ll.background_LINEAR_GRADIENT
e.background_y2 = 100
e:set_background_color_stop_offset(0, 0)
e:set_background_color_stop_offset(1, 1)
e:set_background_color_stop_color(0, 0xff0000ff)
e:set_background_color_stop_color(1, 0x0000ffff)
e.background_x1 = 1
e:set_shadow_x (0, 6)
e:set_shadow_y (0, 6)
e:set_shadow_blur (0, 4)
e:set_shadow_color (0, 0x000000ff)
e:set_shadow_content (0, false)
e:set_shadow_inset (0, false)
e:set_shadow_x (1, 4)
e:set_shadow_y (1, 4)
e:set_shadow_blur (1, 0)
e:set_shadow_color (1, 0xffffffff)
e:set_shadow_content (1, false)
e:set_shadow_inset (1, false)
e.layout_type = ll.LAYOUT_FLEX
--e.flex_flow = ll.FLEX_FLOW_Y
e1.clip_content = ll.CLIP_BACKGROUND
e2.clip_content = ll.CLIP_PADDING
e2.background_type = ll.BACKGROUND_COLOR
e2.background_color = 0x33333366
e1.border_width = 10; e1.padding = 20
e2.border_width = 10; e2.padding = 20
e1.border_color = 0xffff00ff
e2.border_color = 0x00ff00ff
e1.min_cw = 10; e1.min_ch = 10
e2.min_cw = 10; e2.min_ch = 10
--llib.subpixel_x_resolution = 1/2
--llib.glyph_cache_size = 0
--llib.glyph_run_cache_size = 0
--e1:set_text_utf8(s, -1)
e1:set_text_span_font_id (0, font1_id)
e1:set_text_span_font_size(0, 14)
e1:set_text_span_color (0, 0xffffffff)
e1.text_align_y = ll.ALIGN_TOP
e1.text_align_x = ll.ALIGN_RIGHT
e1:set_shadow_x (2, 1)
e1:set_shadow_y (2, 1)
e1:set_shadow_blur (2, 1)
e1:set_shadow_color (2, 0x000000ff)
e1:set_shadow_content (2, true)
e1:set_shadow_inset (2, false)
--e1.visible = false
--e2.visible = false
do local e = e2
--e:set_text_utf8('Yea but it\'s live!!', -1)
e:set_text_span_font_id (0, font2_id)
e:set_text_span_font_size(0, 100)
e:set_text_span_color (0, 0x333333ff)
e.text_align_y = ll.ALIGN_CENTER
e.text_align_x = ll.ALIGN_CENTER
e:set_shadow_x (0, 0)
e:set_shadow_y (0, 1)
e:set_shadow_blur (0, 2)
e:set_shadow_color (0, 0x000000ff)
e:set_shadow_content (0, true)
e:set_shadow_inset (0, true)
e:set_shadow_x (1, 0)
e:set_shadow_y (1, 1)
e:set_shadow_blur (1, 1)
e:set_shadow_color (1, 0x888888ff)
e:set_shadow_content (1, true)
e:set_shadow_inset (1, false)
end
function win:repaint()
local cr = self:bitmap():cairo()
cr:identity_matrix()
cr:rgba(1, 1, 1, 1)
cr:paint()
local w, h = self:client_size()
cr:translate(50, 50)
e:sync(w - 100, h - 100)
--print'synced'
e:draw(cr)
--e1:set_text_utf8('', -1)
--e:clear_text_runs()
end
function win:keyup(key)
if key == 'esc' then
self:close()
end
end
app:run()
e:free()
e1:free()
e2:free()
llib:dump_stats()
llib:free()
ll.memreport()
assert(ll.memtotal() == 0)