Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add table of contents to Gui/journal #1243

Merged
merged 27 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
26a603d
Add simple Table of Contents to journal
wiktor-obrebski Jul 18, 2024
04dc395
Move journal table of contents to right and add resize control
wiktor-obrebski Jul 20, 2024
1f265fb
Add button to toggle journal table of contest visiblity
wiktor-obrebski Jul 20, 2024
77c0beb
Add journal README for Table of contest
wiktor-obrebski Jul 20, 2024
dc008c8
Improve journal table of contents logic, add tests
wiktor-obrebski Jul 20, 2024
48c4b50
Polishing journal table of contents resize logic
wiktor-obrebski Jul 20, 2024
49b8f37
Add journal feat of saving entire layout (including table of contents)
wiktor-obrebski Jul 20, 2024
1204270
Fix journal issue with numpad keys not interpreted as text
wiktor-obrebski Jul 21, 2024
0f6e056
Add undo/redo feature to journal
wiktor-obrebski Jul 21, 2024
7f9976c
Restore journal last cursor position
wiktor-obrebski Jul 21, 2024
0e23cfe
Move journal scrollbar 1 pixel to the right to save space
wiktor-obrebski Jul 22, 2024
0c36c14
Implement new gui for journal table of contents collapsing mechanism
wiktor-obrebski Jul 28, 2024
f3de017
Adjust journal tests to new collapsing table of contents gui
wiktor-obrebski Jul 28, 2024
c3f6ddd
Merge master
wiktor-obrebski Jul 28, 2024
af181ab
Fix journal docs table of contents shortcut
wiktor-obrebski Jul 28, 2024
961c74b
Restore gui/journal fix for ASCII mode layout
wiktor-obrebski Jul 28, 2024
49053dd
Fix typo in gui/journal docs
wiktor-obrebski Jul 28, 2024
fff7aac
Improve journal resize gui, add bottom buttons bar
wiktor-obrebski Jul 28, 2024
a9c517e
Change journal words jump shortcuts to ctrl+left/ctrl+right
wiktor-obrebski Aug 1, 2024
59c54ff
Make journal selected section follows cursor
wiktor-obrebski Aug 1, 2024
e7001f4
Add keyboard navigation to journal table of contents
wiktor-obrebski Aug 1, 2024
17e3706
Fix journal issue with resize frame
wiktor-obrebski Aug 1, 2024
b42b847
Fix journal save layout defaults
wiktor-obrebski Aug 1, 2024
3cfeb81
Temporary disable journal test basing on 51+ DF version
wiktor-obrebski Aug 1, 2024
184ceb6
Add shortcuts to Journal previous/next feature
wiktor-obrebski Aug 2, 2024
1528d76
Merge branch 'master' into HEAD
myk002 Aug 2, 2024
61ec67d
guard DF51-only features
myk002 Aug 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions gui/journal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function JournalWindow:init()
view_id='table_of_contents_panel',
frame={l=0, w=toc_width, t=0, b=1},
visible=toc_visible,
frame_inset={l=0, t=1, b=1, r=1},
frame_inset={l=1, t=0, b=1, r=1},

resize_min={w=20},
resizable=true,
Expand All @@ -61,7 +61,8 @@ function JournalWindow:init()

if not colllapsed then
self.subviews.table_of_contents_panel:reload(
self.subviews.journal_editor:getText()
self.subviews.journal_editor:getText(),
self.subviews.journal_editor:getCursor()
)
end

Expand Down Expand Up @@ -107,39 +108,10 @@ function JournalWindow:init()
}
})

self.subviews.table_of_contents_panel:reload(self.init_text)
end

function JournalWindow:onInput(keys)
if (keys.A_MOVE_N_DOWN) then
local curr_cursor = self.subviews.journal_editor:getCursor()
local section_index, section = self.subviews.table_of_contents_panel:cursorSection(
curr_cursor
)

if section.line_cursor == curr_cursor then
self.subviews.table_of_contents_panel:setSelectedSection(
section_index - 1
)
self.subviews.table_of_contents_panel:submit()
else
self:onTableOfContentsSubmit(section_index, section)
end

return false
elseif (keys.A_MOVE_S_DOWN) then
local section_index = self.subviews.table_of_contents_panel:cursorSection(
self.subviews.journal_editor:getCursor()
)
self.subviews.table_of_contents_panel:setSelectedSection(
section_index + 1
)
self.subviews.table_of_contents_panel:submit()

return false
end

return JournalWindow.super.onInput(self, keys)
self.subviews.table_of_contents_panel:reload(
self.init_text,
self.subviews.journal_editor:getCursor() or self.init_cursor
)
end

function JournalWindow:sanitizeFrame(frame)
Expand Down Expand Up @@ -239,9 +211,8 @@ function JournalWindow:postUpdateLayout()
end

function JournalWindow:onCursorChange(cursor)
local section_index = self.subviews.table_of_contents_panel:cursorSection(
cursor
)
self.subviews.table_of_contents_panel:setCursor(cursor)
local section_index = self.subviews.table_of_contents_panel:currentSection()
self.subviews.table_of_contents_panel:setSelectedSection(section_index)

if self.on_cursor_change ~= nil then
Expand All @@ -250,7 +221,10 @@ function JournalWindow:onCursorChange(cursor)
end

function JournalWindow:onTextChange(text)
self.subviews.table_of_contents_panel:reload(text)
self.subviews.table_of_contents_panel:reload(
text,
self.subviews.journal_editor:getCursor()
)

if self.on_text_change ~= nil then
self.on_text_change(text)
Expand Down
63 changes: 50 additions & 13 deletions internal/journal/table_of_contents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,81 @@ TableOfContents = defclass(TableOfContents, widgets.Panel)
TableOfContents.ATTRS {
frame_style=INVISIBLE_FRAME,
frame_background = gui.CLEAR_PEN,
on_submit=DEFAULT_NIL
on_submit=DEFAULT_NIL,
text_cursor=DEFAULT_NIL
}

function TableOfContents:init()
self:addviews({
widgets.List{
frame={l=1, t=0, r=1, b=0},
frame={l=0, t=0, r=0, b=3},
view_id='table_of_contents',
choices={},
on_submit=self.on_submit
},
widgets.HotkeyLabel{
frame={b=0},
key='A_MOVE_N_DOWN',
myk002 marked this conversation as resolved.
Show resolved Hide resolved
label='Previous Section',
on_activate=self:callback('previousSection'),
},
widgets.HotkeyLabel{
frame={b=1},
key='A_MOVE_S_DOWN',
label='Next Section',
on_activate=self:callback('nextSection'),
}
})
end

function TableOfContents:cursorSection(cursor)
local section_ind = nil
function TableOfContents:previousSection()
local section_cursor, section = self:currentSection()

for ind, choice in ipairs(self.subviews.table_of_contents.choices) do
if choice.line_cursor > cursor then
break
end
section_ind = ind
if section.line_cursor == self.text_cursor then
self.subviews.table_of_contents:setSelected(section_cursor - 1)
end

return section_ind, self.subviews.table_of_contents.choices[section_ind]
self.subviews.table_of_contents:submit()
end

function TableOfContents:nextSection()
local curr_sel = self.subviews.table_of_contents:getSelected()

local target_sel = self.text_cursor and
self:currentSection() + 1 or curr_sel + 1

if curr_sel ~= target_sel then
self.subviews.table_of_contents:setSelected(target_sel)
self.subviews.table_of_contents:submit()
end
end

function TableOfContents:setSelectedSection(section_index)
local curr_sel = self.subviews.table_of_contents:getSelected()

if curr_sel ~= section_index then
self.subviews.table_of_contents:setSelected(section_index)
end
end

function TableOfContents:submit()
return self.subviews.table_of_contents:submit()
function TableOfContents:currentSection()
local section_ind = nil

for ind, choice in ipairs(self.subviews.table_of_contents.choices) do
if choice.line_cursor > self.text_cursor then
break
end
section_ind = ind
end

return section_ind, self.subviews.table_of_contents.choices[section_ind]
end

function TableOfContents:setCursor(cursor)
self.text_cursor = cursor
end

function TableOfContents:reload(text)
function TableOfContents:reload(text, cursor)
if not self.visible then
return
end
Expand All @@ -70,5 +106,6 @@ function TableOfContents:reload(text)
line_cursor = line_cursor + #line + 1
end

self.text_cursor = cursor
self.subviews.table_of_contents:setChoices(sections)
end
Loading