Skip to content

Commit 5adc569

Browse files
authored
Merge pull request DFHack#433 from myk002/myk_launcher_rewrap
[gui/launcher] wrap text from helpdb for the current window size
2 parents 773a6ec + b465f3b commit 5adc569

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

gui/launcher.lua

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function AutocompletePanel:init()
129129
self:addviews{
130130
widgets.Label{
131131
frame={l=0, t=0},
132-
text='Autocomplete'
132+
text='Click or select via'
133133
},
134134
widgets.HotkeyLabel{
135135
frame={l=1, t=1},
@@ -309,26 +309,19 @@ HelpPanel = defclass(HelpPanel, widgets.Panel)
309309

310310
local DEFAULT_HELP_TEXT = [[Welcome to DFHack!
311311
312-
Type a command to see its help text here. Hit ENTER
313-
to run the command, or Shift-ENTER to run the
314-
command and close this dialog. The dialog also
315-
closes automatically if you run a command that shows
316-
a new GUI screen.
312+
Type a command to see its help text here. Hit ENTER to run the command, or Shift-ENTER to run the command and close this dialog. The dialog also closes automatically if you run a command that shows a new GUI screen.
317313
318-
Not sure what to do? Run the "help" command to get
319-
started!
314+
Not sure what to do? Run the "help" command to get started!
320315
321-
To see help for this command launcher, type
322-
"launcher" and hit the TAB key or click on
323-
"gui/launcher" to autocomplete.]]
316+
To see help for this command launcher, type "launcher" and hit the TAB key or click on "gui/launcher" to autocomplete.]]
324317

325318
function HelpPanel:init()
326-
self.cur_entry = ""
319+
self.cur_entry = ''
327320

328321
self:addviews{
329322
widgets.WrappedLabel{
330323
view_id='help_label',
331-
frame={l=0, t=0},
324+
frame={l=1, t=0, b=1},
332325
auto_height=false,
333326
scroll_keys={
334327
A_MOVE_N_DOWN=-1, -- Ctrl-Up
@@ -340,11 +333,14 @@ function HelpPanel:init()
340333
}
341334
end
342335

343-
function HelpPanel:set_help(help_text)
336+
function HelpPanel:set_help(help_text, in_layout)
344337
local label = self.subviews.help_label
345338
label.text_to_wrap = help_text
346-
label:postComputeFrame()
347-
label:updateLayout() -- to update the scroll arrows after rewrapping text
339+
if not in_layout then
340+
self.cur_entry = ''
341+
label:postComputeFrame()
342+
label:updateLayout() -- update the scroll arrows after rewrapping text
343+
end
348344
end
349345

350346
function HelpPanel:set_entry(entry_name)
@@ -354,8 +350,16 @@ function HelpPanel:set_entry(entry_name)
354350
if #entry_name == 0 or entry_name == self.cur_entry then
355351
return
356352
end
353+
self:set_help(helpdb.get_entry_long_help(entry_name,
354+
self.frame_body.width - 2))
357355
self.cur_entry = entry_name
358-
self:set_help(helpdb.get_entry_long_help(entry_name))
356+
end
357+
358+
function HelpPanel:postComputeFrame()
359+
if #self.cur_entry == 0 then return end
360+
self:set_help(helpdb.get_entry_long_help(self.cur_entry,
361+
self.frame_body.width - 2),
362+
true)
359363
end
360364

361365
function HelpPanel:onInput(keys)

0 commit comments

Comments
 (0)