1 Menu_background_color
= {r
=0.6, g
=0.8, b
=0.6}
2 Menu_border_color
= {r
=0.6, g
=0.7, b
=0.6}
3 Menu_command_color
= {r
=0.2, g
=0.2, b
=0.2}
4 Menu_highlight_color
= {r
=0.5, g
=0.7, b
=0.3}
6 function source
.draw_menu_bar()
7 if App
.run_tests
then return end -- disable in tests
8 App
.color(Menu_background_color
)
9 love
.graphics
.rectangle('fill', 0,0, App
.screen
.width
, Menu_status_bar_height
)
10 App
.color(Menu_border_color
)
11 love
.graphics
.rectangle('line', 0,0, App
.screen
.width
, Menu_status_bar_height
)
12 App
.color(Menu_command_color
)
14 if Show_file_navigator
then
15 source
.draw_file_navigator()
18 add_hotkey_to_menu('ctrl+e: run')
19 if Focus
== 'edit' then
20 add_hotkey_to_menu('ctrl+g: switch file')
21 if Show_log_browser_side
then
22 add_hotkey_to_menu('ctrl+l: hide log browser')
24 add_hotkey_to_menu('ctrl+l: show log browser')
26 if Editor_state
.expanded
then
27 add_hotkey_to_menu('alt+b: collapse debug prints')
29 add_hotkey_to_menu('alt+b: expand debug prints')
31 add_hotkey_to_menu('alt+d: create/edit debug print')
32 add_hotkey_to_menu('ctrl+f: find in file')
33 add_hotkey_to_menu('alt+left alt+right: prev/next word')
34 elseif Focus
== 'log_browser' then
37 assert(false, 'unknown focus "'..Focus
..'"')
39 add_hotkey_to_menu('ctrl+z ctrl+y: undo/redo')
40 add_hotkey_to_menu('ctrl+x ctrl+c ctrl+v: cut/copy/paste')
41 add_hotkey_to_menu('ctrl+= ctrl+- ctrl+0: zoom')
44 function add_hotkey_to_menu(s
)
45 local s_text
= to_text(s
)
46 local width
= App
.width(s_text
)
47 if Menu_cursor
+ width
> App
.screen
.width
- 5 then
50 App
.color(Menu_command_color
)
51 App
.screen
.draw(s_text
, Menu_cursor
,5)
52 Menu_cursor
= Menu_cursor
+ width
+ 30
55 function source
.draw_file_navigator()
56 if File_navigation
.num_lines
== nil then
57 File_navigation
.num_lines
= source
.num_lines_for_file_navigator()
59 App
.color(Menu_background_color
)
60 love
.graphics
.rectangle('fill', 0,Menu_status_bar_height
, App
.screen
.width
, File_navigation
.num_lines
* Editor_state
.line_height
)
61 local x
,y
= 5, Menu_status_bar_height
62 for i
,filename
in ipairs(File_navigation
.candidates
) do
63 if filename
== 'source' then
64 App
.color(Menu_border_color
)
65 love
.graphics
.line(Menu_cursor
-10,2, Menu_cursor
-10,Menu_status_bar_height
-2)
67 x
,y
= add_file_to_menu(x
,y
, filename
, i
== File_navigation
.index
)
68 if Menu_cursor
>= App
.screen
.width
- 5 then
74 function source
.num_lines_for_file_navigator()
77 for i
,filename
in ipairs(File_navigation
.candidates
) do
78 local width
= App
.width(to_text(filename
))
79 if x
+ width
> App
.screen
.width
- 5 then
89 function add_file_to_menu(x
,y
, s
, cursor_highlight
)
90 local s_text
= to_text(s
)
91 local width
= App
.width(s_text
)
92 if x
+ width
> App
.screen
.width
- 5 then
93 y
= y
+ Editor_state
.line_height
96 if cursor_highlight
then
97 App
.color(Menu_highlight_color
)
98 love
.graphics
.rectangle('fill', x
-5,y
-2, width
+5*2,Editor_state
.line_height
+2*2)
100 App
.color(Menu_command_color
)
101 App
.screen
.draw(s_text
, x
,y
)
106 function keychord_pressed_on_file_navigator(chord
, key
)
107 if chord
== 'escape' then
108 Show_file_navigator
= false
109 elseif chord
== 'return' then
110 local candidate
= guess_source(File_navigation
.candidates
[File_navigation
.index
]..'.lua')
111 source
.switch_to_file(candidate
)
112 Show_file_navigator
= false
113 elseif chord
== 'left' then
114 if File_navigation
.index
> 1 then
115 File_navigation
.index
= File_navigation
.index
-1
117 elseif chord
== 'right' then
118 if File_navigation
.index
< #File_navigation
.candidates
then
119 File_navigation
.index
= File_navigation
.index
+1