forked from koreader/koreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wtest.lua
executable file
·284 lines (260 loc) · 6.36 KB
/
wtest.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!./koreader-base
require "defaults"
print(package.path)
package.path = "./frontend/?.lua;./?.lua"
local UIManager = require("ui/uimanager")
local RenderText = require("ui/rendertext")
local Font = require("ui/font")
local Geom = require("ui/geometry")
local Menu = require("ui/widget/menu")
local Widget = require("ui/widget/widget")
local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local CenterContainer = require("ui/widget/container/centercontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local ConfirmBox = require("ui/widget/confirmbox")
local TouchMenu = require("ui/widget/touchmenu")
local InputText = require("ui/widget/inputtext")
local DocumentRegistry = require("document/documentregistry")
local ReaderUI = require("ui/readerui")
local Dbg = require("dbg")
local Device = require("ui/device")
local Screen = require("ui/screen")
-----------------------------------------------------
-- widget that paints the grid on the background
-----------------------------------------------------
TestGrid = Widget:new{}
function TestGrid:paintTo(bb)
v_line = math.floor(bb:getWidth() / 50)
h_line = math.floor(bb:getHeight() / 50)
for i=1,h_line do
y_num = i*50
RenderText:renderUtf8Text(bb, 0, y_num+10, Font:getFace("ffont", 12), y_num, true)
bb:paintRect(0, y_num, bb:getWidth(), 1, 10)
end
for i=1,v_line do
x_num = i*50
RenderText:renderUtf8Text(bb, x_num, 10, Font:getFace("ffont", 12), x_num, true)
bb:paintRect(x_num, 0, 1, bb:getHeight(), 10)
end
end
-----------------------------------------------------
-- we create a widget that paints a background:
-----------------------------------------------------
Background = InputContainer:new{
is_always_active = true, -- receive events when other dialogs are active
key_events = {
OpenDialog = { { "Press" } },
OpenConfirmBox = { { "Del" } },
QuitApplication = { { {"Home","Back"} } }
},
-- contains a gray rectangular desktop
FrameContainer:new{
background = 3,
bordersize = 0,
dimen = Screen:getSize(),
Widget:new{
dimen = {
w = Screen:getWidth(),
h = Screen:getHeight(),
}
},
}
}
function Background:onOpenDialog()
UIManager:show(InfoMessage:new{
text = "Example message.",
timeout = 10
})
end
function Background:onOpenConfirmBox()
UIManager:show(ConfirmBox:new{
text = "Please confirm delete"
})
end
function Background:onInputError()
UIManager:quit()
end
function Background:onQuitApplication()
UIManager:quit()
end
-----------------------------------------------------
-- example widget: a clock
-----------------------------------------------------
Clock = FrameContainer:new{
background = 0,
bordersize = 1,
margin = 0,
padding = 1
}
function Clock:schedFunc()
self[1]:free()
self[1] = self:getTextWidget()
UIManager:setDirty(self)
-- reschedule
-- TODO: wait until next real second shift
UIManager:scheduleIn(1, function() self:schedFunc() end)
end
function Clock:onShow()
self[1] = self:getTextWidget()
self:schedFunc()
end
function Clock:getTextWidget()
return CenterContainer:new{
dimen = { w = 300, h = 25 },
TextWidget:new{
text = os.date("%H:%M:%S"),
face = Font:getFace("cfont", 12)
}
}
end
-----------------------------------------------------
-- a confirmbox box widget
-----------------------------------------------------
Quiz = ConfirmBox:new{
text = "Tell me the truth, isn't it COOL?!",
width = 300,
ok_text = "Yes, of course.",
cancel_text = "No, it's ugly.",
cancel_callback = function()
UIManager:show(InfoMessage:new{
text="You liar!",
})
end,
}
-----------------------------------------------------
-- a menu widget
-----------------------------------------------------
menu_items = {
{text = "item1"},
{text = "item2"},
{text = "This is a very very log item whose length should exceed the width of the menu."},
{text = "item3"},
{text = "item4"},
{text = "item5"},
{text = "item6"},
{text = "item7"},
{text = "item8"},
{text = "item9"},
{text = "item10"},
{text = "item11"},
{text = "item12"},
{text = "item13"},
{text = "item14"},
{text = "item15"},
{text = "item16"},
{text = "item17"},
}
M = Menu:new{
title = "Test Menu",
item_table = menu_items,
width = 500,
height = 600,
}
-----------------------------------------------------
-- a reader view widget
-----------------------------------------------------
readerwindow = CenterContainer:new{
dimen = Screen:getSize(),
FrameContainer:new{
background = 0
}
}
reader = ReaderUI:new{
dialog = readerwindow,
dimen = Geom:new{ w = Screen:getWidth() - 100, h = Screen:getHeight() - 100 },
document = DocumentRegistry:openDocument("test/2col.pdf")
--document = DocumentRegistry:openDocument("test/djvu3spec.djvu")
--document = DocumentRegistry:openDocument("./README.TXT")
}
readerwindow[1][1] = reader
touch_menu = TouchMenu:new{
title = "Document menu",
width = Screen:getWidth(),
tab_item_table = {
{
icon = "resources/icons/appbar.pokeball.png",
{
text = "item1",
callback = function()
end,
},
{
text = "item2",
callback = function()
end,
},
{
text = "item3",
callback = function()
end,
},
{
text = "item4",
callback = function()
end,
},
{
text = "item5",
callback = function()
end,
},
{
text = "item6",
callback = function()
end,
},
{
text = "item7",
callback = function()
end,
},
{
text = "item8",
callback = function()
end,
},
{
text = "item9",
callback = function()
end,
},
},
{
icon = "resources/icons/appbar.page.corner.bookmark.png",
{
text = "item10",
callback = function()
end,
},
{
text = "item11",
callback = function()
end,
},
},
{
icon = "resources/icons/appbar.home.png",
callback = function()
DEBUG("hello world!")
end
}
},
}
inputtext = InputText:new{
width = 400,
height = 300,
}
-----------------------------------------------------------------------
-- you may want to uncomment following show calls to see the changes
-----------------------------------------------------------------------
UIManager:show(Background:new())
UIManager:show(TestGrid)
--UIManager:show(Clock:new())
--UIManager:show(M)
--UIManager:show(Quiz)
--UIManager:show(readerwindow)
--UIManager:show(touch_menu)
--UIManager:show(keyboard)
UIManager:show(inputtext)
UIManager:run()