-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibui.src
More file actions
111 lines (82 loc) · 2.77 KB
/
libui.src
File metadata and controls
111 lines (82 loc) · 2.77 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
MENU_BG_COLOR = "#00009977"
MENU_BG_CHARACTER_COLOR = "#0a0a31"
MENU_TEXT_COLOR = "#FFFFFF"
MENU_SELECTED_BG_COLOR = "#99990077"
MENU_SELECTED_TEXT_COLOR = "#FFFFFF"
MENU_PAGE_SIZE = 10
MENU_PADDING = 2
clear_screen
print_line = function( text, width, alignment, active)
ntext = text + " "*(width-text.len-2)
text_bg = MENU_BG_COLOR
if active then text_bg = MENU_SELECTED_BG_COLOR
print "<size=120%>"+
"<align="+alignment+">"+
"<mark="+MENU_BG_COLOR+">"+
"<color="+MENU_BG_CHARACTER_COLOR+">·</color>"+
"<color="+MENU_TEXT_COLOR+"> "+
"<mark="+text_bg+">"+
ntext+
"</mark></color> "+
"<mark="+MENU_BG_COLOR+">"+
"<color="+MENU_BG_CHARACTER_COLOR+">-</color>"+
"</mark>"
end function
my_clear_screen = function()
print " ", 1
end function
show_menu = function( title, choices, active_choice)
my_clear_screen
max_width = title.len
active_choice = active_choice % choices.len
for choice in choices
if choice[1].len > max_width then max_width = choice[1].len
end for
menu_width = max_width+MENU_PADDING
print_line( "", menu_width, "center")
print_line( title, menu_width, "center", false)
print_line( "<voffset=0.8em><s>"+" "*max_width+"</s>", menu_width, "center", false)
for choice in choices
print_line( choice[1], menu_width, "center", choices[active_choice] == choice)
end for
print_line( "", menu_width, "center")
print_line( "<voffset=0.8em><s>"+" "*max_width+"</s>", menu_width, "center", false)
end function
menu = function( title, choices)
page = 0
active = 0
max_page = floor(choices.len/10)
while true
display_title = title
if max_page > 0 then
display_title = "< "+ title +" ("+(page+1)+"/"+(max_page+1)+") >"
end if
show_menu(
display_title,
choices[page*MENU_PAGE_SIZE:(page+1)*MENU_PAGE_SIZE],
active)
wait 0.03
input = user_input( char(0), false, true)
if input == "DownArrow" or input == "2" or input == "s" then
active = active + 1
else if input == "UpArrow" or input == "8" or input == "w" then
active = active - 1
else if input == "RightArrow" or input == "6" or input == "d" then
page = (page + 1)%(max_page+1)
else if input == "LeftArrow" or input == "4" or input == "a" then
page = (max_page+page)%(max_page+1)
else if input=="Escape" then
exit
else if input == " " or input.len == 0 then
break
else
end if
current_page_size = MENU_PAGE_SIZE
if page == max_page then
current_page_size = (choices.len%MENU_PAGE_SIZE)
end if
active = (current_page_size+active)%current_page_size
last_page_size = (choices.len%MENU_PAGE_SIZE)
end while
return choices[active + page*MENU_PAGE_SIZE]
end function