Skip to content

Commit

Permalink
protect against bad saved frames
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jun 21, 2024
1 parent cafb450 commit 87d88c6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
27 changes: 25 additions & 2 deletions gui/gm-editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,37 @@ function search_relevance(search, candidate)
return ret
end

local RESIZE_MIN = {w=30, h=20}

local function sanitize_frame(frame)
local w, h = dfhack.screen.getWindowSize()
local min = RESIZE_MIN
if frame.t and h - frame.t - (frame.b or 0) < min.h then
frame.t = h - min.h
frame.b = 0
end
if frame.b and h - frame.b - (frame.t or 0) < min.h then
frame.b = h - min.h
frame.t = 0
end
if frame.l and w - frame.l - (frame.r or 0) < min.w then
frame.l = w - min.w
frame.r = 0
end
if frame.r and w - frame.r - (frame.l or 0) < min.w then
frame.r = w - min.w
frame.l = 0
end
return frame
end

GmEditorUi = defclass(GmEditorUi, widgets.Window)
GmEditorUi.ATTRS{
frame=copyall(config.data.frame or {}),
frame=sanitize_frame(copyall(config.data.frame or {})),
frame_title="GameMaster's editor",
frame_inset=0,
resizable=true,
resize_min={w=30, h=20},
resize_min=RESIZE_MIN,
read_only=(config.data.read_only or false)
}

Expand Down
18 changes: 18 additions & 0 deletions gui/launcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,24 @@ function LauncherUI:init()
new_frame[k] = 0
end
end
local w, h = dfhack.screen.getWindowSize()
local min = MainPanel.ATTRS.resize_min
if new_frame.t and h - new_frame.t - (new_frame.b or 0) < min.h then
new_frame.t = h - min.h
new_frame.b = 0
end
if new_frame.b and h - new_frame.b - (new_frame.t or 0) < min.h then
new_frame.b = h - min.h
new_frame.t = 0
end
if new_frame.l and w - new_frame.l - (new_frame.r or 0) < min.w then
new_frame.l = w - min.w
new_frame.r = 0
end
if new_frame.r and w - new_frame.r - (new_frame.l or 0) < min.w then
new_frame.r = w - min.w
new_frame.l = 0
end
end
end
main_panel.frame = new_frame
Expand Down

0 comments on commit 87d88c6

Please sign in to comment.