Merge pull request #4057 from myk002/myk_sort_elevate_barony

[sort] prevent the overlay from being moved out of position when the screen size changes
develop
Myk 2023-11-24 17:31:22 -08:00 committed by GitHub
commit 910272fa00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 19 deletions

@ -98,13 +98,10 @@ function DiplomacyOverlay:get_sort()
end end
end end
function DiplomacyOverlay:onRenderFrame(dc, rect) function DiplomacyOverlay:preUpdateLayout(parent_rect)
local sw = dfhack.screen.getWindowSize() local margin = (parent_rect.width - 114) // 3
local margin = (sw - 114) // 3
self.frame.w = 57 + margin self.frame.w = 57 + margin
self.subviews.panel.frame.l = margin self.subviews.panel.frame.l = margin
DiplomacyOverlay.super.onRenderFrame(self, dc, rect)
end end
-- ---------------------- -- ----------------------
@ -130,15 +127,19 @@ function PreferenceOverlay:init()
} }
end end
function PreferenceOverlay:preUpdateLayout(parent_rect)
local list_height = parent_rect.height - 17
self.frame.w = parent_rect.width - 85
self.frame.h = list_height
local margin = (parent_rect.width - 114) // 3
self.subviews.annotations.frame.l = margin
end
function PreferenceOverlay:onRenderFrame(dc, rect) function PreferenceOverlay:onRenderFrame(dc, rect)
local sw, sh = dfhack.screen.getWindowSize() local margin = self.subviews.annotations.frame.l
local margin = (sw - 114) // 3 local num_elems = self.frame.h // 3
local list_height = sh - 17
local num_elems = list_height // 3
local max_elem = math.min(#diplomacy.land_holder_avail_hfid-1, local max_elem = math.min(#diplomacy.land_holder_avail_hfid-1,
diplomacy.scroll_position_land_holder_hf+num_elems-1) diplomacy.scroll_position_land_holder_hf+num_elems-1)
self.frame.w = sw - 85
self.frame.h = list_height
local annotations = {} local annotations = {}
for idx=diplomacy.scroll_position_land_holder_hf,max_elem do for idx=diplomacy.scroll_position_land_holder_hf,max_elem do
@ -156,8 +157,8 @@ function PreferenceOverlay:onRenderFrame(dc, rect)
table.insert(annotations, {text=']', pen=COLOR_RED}) table.insert(annotations, {text=']', pen=COLOR_RED})
table.insert(annotations, NEWLINE) table.insert(annotations, NEWLINE)
end end
self.subviews.annotations.frame.l = margin
self.subviews.annotations:setText(annotations) self.subviews.annotations:setText(annotations)
self.subviews.annotations:updateLayout()
PreferenceOverlay.super.onRenderFrame(self, dc, rect) PreferenceOverlay.super.onRenderFrame(self, dc, rect)
end end

@ -551,11 +551,16 @@ local function get_work_animal_counts()
return counts return counts
end end
function WorkAnimalOverlay:onRenderFrame(dc, rect) function WorkAnimalOverlay:preUpdateLayout(parent_rect)
local _, sh = dfhack.screen.getWindowSize()
local _, t = get_panel_offsets() local _, t = get_panel_offsets()
local list_height = sh - (17 + t) local list_height = parent_rect.height - (17 + t)
local num_elems = list_height // 3 self.frame.h = list_height + t
self.subviews.annotations.frame.t = t
end
function WorkAnimalOverlay:onRenderFrame(dc, rect)
local t = self.subviews.annotations.frame.t
local num_elems = (self.frame.h - t) // 3
local max_elem = math.min(#creatures.work_animal_recipient-1, local max_elem = math.min(#creatures.work_animal_recipient-1,
creatures.scroll_position_work_animal+num_elems-1) creatures.scroll_position_work_animal+num_elems-1)
@ -572,10 +577,8 @@ function WorkAnimalOverlay:onRenderFrame(dc, rect)
end end
table.insert(annotations, NEWLINE) table.insert(annotations, NEWLINE)
end end
self.subviews.annotations.frame.t = t
self.subviews.annotations:setText(annotations) self.subviews.annotations:setText(annotations)
self.frame.h = list_height + t self.subviews.annotations:updateLayout()
WorkAnimalOverlay.super.onRenderFrame(self, dc, rect) WorkAnimalOverlay.super.onRenderFrame(self, dc, rect)
end end