-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotebook.lua
More file actions
146 lines (124 loc) · 4.02 KB
/
Copy pathnotebook.lua
File metadata and controls
146 lines (124 loc) · 4.02 KB
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
--
-- NoteBook example.
--
local core = require "core"
local keymap = require "core.keymap"
local command = require "core.command"
local style = require "core.style"
local NoteBook = require "widget.notebook"
local Button = require "widget.button"
local TextBox = require "widget.textbox"
local NumberBox = require "widget.numberbox"
local Toggle = require "widget.toggle"
local ProgressBar = require "widget.progressbar"
local CheckBox = require "widget.checkbox"
local ListBox = require "widget.listbox"
---@type widget.notebook
local notebook = NoteBook()
notebook.size.x = 250
notebook.size.y = 300
notebook.border.width = 0
local log = notebook:add_pane("log", "Messages")
local build = notebook:add_pane("build", "Build")
local errors = notebook:add_pane("errors", "Errors")
local diagnostics = notebook:add_pane("diagnostics", "Diagnostics")
notebook:set_pane_icon("log", "i")
notebook:set_pane_icon("build", "P")
notebook:set_pane_icon("errors", "!")
---@type widget.textbox
local textbox = TextBox(log, "", "placeholder...")
textbox:set_position(10, 20)
---@type widget.numberbox
local numberbox = NumberBox(log, 10)
numberbox:set_position(10, textbox:get_bottom() + 20)
---@type widget.toggle
local toggle = Toggle(log, "The Toggle:", true)
toggle:set_position(10, numberbox:get_bottom() + 20)
---@type widget.progressbar
local progress = ProgressBar(log, 33)
progress:set_position(textbox:get_right() + 50, 20)
---@type widget.checkbox
local checkbox = CheckBox(build, "Child checkbox")
checkbox:set_position(10, 20)
---@type widget.button
local button = Button(errors, "A test button")
button:set_position(10, 20)
button.on_click = function()
system.show_fatal_error("Message", "Hello World")
end
---@type widget.checkbox
local checkbox2 = CheckBox(errors, "Child checkbox2")
checkbox2:set_position(10, button:get_bottom() + 30)
---@type widget.listbox
diagnostics.scrollable = false
local listbox = ListBox(diagnostics)
listbox.border.width = 0
listbox:enable_expand(true)
listbox:add_column("Severity")
listbox:add_column("Message")
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error",
ListBox.COLEND,
"A message to display to the user."
})
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error",
ListBox.COLEND,
"Another message to display to the user\nwith new line characters\nfor the win."
})
core.add_thread(function()
for num=1, 1000 do
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error",
ListBox.COLEND,
tostring(num),
" Another message to display to the user\nwith new line characters\nfor the win."
}, num)
if num % 100 == 0 then
coroutine.yield()
end
end
listbox:add_row({
style.icon_font, style.syntax.string, "!", style.font, style.text, " Error",
ListBox.COLEND,
"Final message to display."
})
end)
listbox.on_row_click = function(self, idx, data)
if data then
system.show_fatal_error("Row Data", data)
end
self:remove_row(idx)
end
-- defer draw needs to be set to false when adding widget as a pragtical node
notebook.border.width = 0
notebook.draggable = false
notebook.defer_draw = false
-- reposition items on scale changes
notebook.update_size_position = function(self)
NoteBook.update_size_position(self)
textbox:set_position(10, 20)
numberbox:set_position(10, textbox:get_bottom() + 20)
toggle:set_position(10, numberbox:get_bottom() + 20)
progress:set_position(textbox:get_right() + 50, 20)
checkbox:set_position(10, 20)
button:set_position(10, 20)
checkbox2:set_position(10, button:get_bottom() + 30)
end
local inside_node = false
-- You can add the widget as a pragtical node
command.add(nil,{
["notebook-widget:toggle"] = function()
if inside_node then
notebook:toggle_visible()
else
local node = core.root_view:get_primary_node()
node:split("down", notebook, {y=true}, true)
notebook:show()
inside_node = true
end
end
})
keymap.add {
["alt+shift+m"] = "notebook-widget:toggle",
}