Skip to content

Commit

Permalink
Merge pull request #1255 from myk002/myk_journal
Browse files Browse the repository at this point in the history
[gui/journal] layout and widget behavior fixes
  • Loading branch information
myk002 authored Aug 3, 2024
2 parents aaf4c6a + e327af9 commit c483216
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
26 changes: 13 additions & 13 deletions gui/journal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ local text_editor = reqscript('internal/journal/text_editor')
local shifter = reqscript('internal/journal/shifter')
local table_of_contents = reqscript('internal/journal/table_of_contents')

local RESIZE_MIN = {w=32, h=10}
local RESIZE_MIN = {w=54, h=20}
local TOC_RESIZE_MIN = {w=24}

local JOURNAL_PERSIST_KEY = 'journal'

Expand All @@ -32,8 +33,7 @@ or
## My section subheading
Those headers will appear here, and you can click on them to jump to them in the text.
]=]
Those headers will appear here, and you can click on them to jump to them in the text.]=]

journal_config = journal_config or json.open('dfhack-config/journal.json')

Expand Down Expand Up @@ -65,7 +65,7 @@ function JournalWindow:init()
visible=toc_visible,
frame_inset={l=1, t=0, b=1, r=1},

resize_min={w=20},
resize_min=TOC_RESIZE_MIN,
resizable=true,
resize_anchors={l=false, t=false, b=true, r=true},

Expand All @@ -76,7 +76,7 @@ function JournalWindow:init()
subviews={
widgets.WrappedLabel{
view_id='table_of_contents_tutorial',
frame={l=0,t=0,r=0,b=0},
frame={l=0,t=0,r=0,b=3},
text_to_wrap=TOC_WELCOME_COPY,
visible=false
}
Expand Down Expand Up @@ -128,8 +128,10 @@ function JournalWindow:init()
frame_inset={l=1,r=1,t=0, w=100},
subviews={
widgets.HotkeyLabel{
frame={l=0},
key='CUSTOM_CTRL_O',
label='Table of Contents',
label='Toggle table of contents',
auto_width=true,
on_activate=function() self.subviews.shifter:toggle() end
}
}
Expand Down Expand Up @@ -206,11 +208,11 @@ function JournalWindow:loadConfig()
window_frame.w = window_frame.w or 80
window_frame.h = window_frame.h or 50

local table_of_contents = copyall(journal_config.data.toc or {})
table_of_contents.width = table_of_contents.width or 20
table_of_contents.visible = table_of_contents.visible or false
local toc = copyall(journal_config.data.toc or {})
toc.width = math.max(toc.width or 25, TOC_RESIZE_MIN.w)
toc.visible = toc.visible or false

return window_frame, table_of_contents.visible, table_of_contents.width or 25
return window_frame, toc.visible, toc.width
end

function JournalWindow:onPanelResizeBegin()
Expand Down Expand Up @@ -239,7 +241,7 @@ function JournalWindow:ensurePanelsRelSize()
local divider = self.subviews.table_of_contents_divider

toc_panel.frame.w = math.min(
math.max(toc_panel.frame.w, toc_panel.resize_min.w),
math.max(toc_panel.frame.w, TOC_RESIZE_MIN.w),
self.frame.w - editor.resize_min.w
)
editor.frame.l = toc_panel.visible and toc_panel.frame.w or 1
Expand Down Expand Up @@ -295,8 +297,6 @@ function JournalScreen:init()
JournalWindow{
view_id='journal_window',
frame={w=65, h=45},
resize_min={w=50, h=20},
resizable=true,

save_layout=self.save_layout,

Expand Down
32 changes: 28 additions & 4 deletions internal/journal/table_of_contents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,43 @@ function TableOfContents:init()
return
end

local function can_prev()
local toc = self.subviews.table_of_contents
return #toc:getChoices() > 0 and toc:getSelected() > 1
end
local function can_next()
local toc = self.subviews.table_of_contents
local num_choices = #toc:getChoices()
return num_choices > 0 and toc:getSelected() < num_choices
end

self:addviews{
widgets.HotkeyLabel{
frame={b=0},
frame={b=1, l=0},
key='A_MOVE_N_DOWN',
label='Previous Section',
label='Prev Section',
auto_width=true,
on_activate=self:callback('previousSection'),
enabled=can_prev,
},
widgets.Label{
frame={l=5, b=1, w=1},
text_pen=function() return can_prev() and COLOR_LIGHTGREEN or COLOR_GREEN end,
text=string.char(24),
},
widgets.HotkeyLabel{
frame={b=1},
frame={b=0, l=0},
key='A_MOVE_S_DOWN',
label='Next Section',
auto_width=true,
on_activate=self:callback('nextSection'),
}
enabled=can_next,
},
widgets.Label{
frame={l=5, b=0, w=1},
text_pen=function() return can_next() and COLOR_LIGHTGREEN or COLOR_GREEN end,
text=string.char(25),
},
}
end

Expand Down

0 comments on commit c483216

Please sign in to comment.