Skip to content

Commit

Permalink
Make gui/notes center on note on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktor-obrebski committed Sep 8, 2024
1 parent 17e86bc commit 166675b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
49 changes: 36 additions & 13 deletions gui/notes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function NotesWindow:init()
visible=true,
frame_inset={l=1, t=1, b=1, r=1},
autoarrange_subviews=true,

subviews={
widgets.HotkeyLabel {
key='CUSTOM_ALT_S',
Expand All @@ -46,14 +45,35 @@ function NotesWindow:init()
frame={l=0,h=3},
frame_style=gui.FRAME_INTERIOR,
one_line_mode=true,
on_text_change=self:callback('loadFilteredNotes')
on_text_change=self:callback('loadFilteredNotes'),
on_submit=function()
self.subviews.note_list:submit()
end
},
widgets.Panel{
frame={h=2},
frame_inset={t=1},
subviews={
widgets.HotkeyLabel {
key='CUSTOM_ALT_L',
label='Notes',
frame={l=0,t=0},
auto_width=true,
on_activate=function()
self.subviews.note_list:setFocus(true)
end,
},
}
},
widgets.List{
view_id='note_list',
frame={l=0},
frame_inset={t=1},
frame_inset={t=0},
row_height=1,
on_submit=function (ind, note) self:loadNote(note) end
on_submit=function (ind, note)
self:loadNote(note)
dfhack.gui.pauseRecenter(note.point.pos)
end
},
}
},
Expand Down Expand Up @@ -160,15 +180,16 @@ function NotesWindow:loadNote(note)
return
end

local note_width = self.subviews.name_panel.frame_body.width
local wrapped_name = note.point.name:wrap(note_width)
local wrapped_comment = note.point.comment:wrap(note_width)
local note_details_frame = self.subviews.name_panel.frame_body
if note_details_frame ~= nil then
local note_width = self.subviews.name_panel.frame_body.width
local wrapped_name = note.point.name:wrap(note_width)
local wrapped_comment = note.point.comment:wrap(note_width)

self.subviews.name:setText(wrapped_name)
self.subviews.comment:setText(wrapped_comment)
self.subviews.note_details:updateLayout()

dfhack.gui.pauseRecenter(note.point.pos)
self.subviews.name:setText(wrapped_name)
self.subviews.comment:setText(wrapped_comment)
self.subviews.note_details:updateLayout()
end
end

function NotesWindow:loadFilteredNotes(search_phrase, force)
Expand Down Expand Up @@ -210,7 +231,9 @@ function NotesWindow:loadFilteredNotes(search_phrase, force)
end

self.subviews.note_list:setChoices(choices)
self.subviews.note_list:submit()

local sel_ind, sel_note = self.subviews.note_list:getSelected()
self:loadNote(sel_note)
end)
end

Expand Down
10 changes: 9 additions & 1 deletion internal/journal/text_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ TextEditor.ATTRS{
select_pen = COLOR_CYAN,
on_text_change = DEFAULT_NIL,
on_cursor_change = DEFAULT_NIL,
-- called on submit, only in one line mode
on_submit = DEFAULT_NIL,
one_line_mode = false,
debug = false
}
Expand All @@ -112,6 +114,7 @@ function TextEditor:init()
select_pen=self.select_pen,
debug=self.debug,
one_line_mode=self.one_line_mode,
on_submit=self.on_submit,

on_text_change=function (val)
self:updateLayout()
Expand Down Expand Up @@ -255,6 +258,7 @@ TextEditorView.ATTRS{
enable_cursor_blink = true,
debug = false,
one_line_mode = false,
on_submit = DEFAULT_NIL,
history_size = 10,
}

Expand Down Expand Up @@ -796,7 +800,11 @@ end
function TextEditorView:onTextManipulationInput(keys)
if keys.SELECT then
-- handle enter
if not self.one_line_mode then
if self.one_line_mode then
if self.on_submit then
self:on_submit()
end
else
self.history:store(
HISTORY_ENTRY.WHITESPACE_BLOCK,
self.text,
Expand Down

0 comments on commit 166675b

Please sign in to comment.