Merge pull request #4006 from ToxicBananaParty/placesort

Port auto-resize code from info.lua
develop
Myk 2023-11-12 00:35:01 -08:00 committed by GitHub
commit 584cc2062c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

@ -364,7 +364,7 @@ function InfoOverlay:get_key()
end end
end end
local function resize_overlay(self) function resize_overlay(self)
local sw = dfhack.screen.getWindowSize() local sw = dfhack.screen.getWindowSize()
local overlay_width = math.min(40, sw-(self.frame_rect.x1 + 30)) local overlay_width = math.min(40, sw-(self.frame_rect.x1 + 30))
if overlay_width ~= self.frame.w then if overlay_width ~= self.frame.w then
@ -377,7 +377,7 @@ local function is_tabs_in_two_rows()
return dfhack.screen.readTile(64, 6, false).ch == 0 return dfhack.screen.readTile(64, 6, false).ch == 0
end end
local function get_panel_offsets() function get_panel_offsets()
local tabs_in_two_rows = is_tabs_in_two_rows() local tabs_in_two_rows = is_tabs_in_two_rows()
local shift_right = info.current_mode == df.info_interface_mode_type.ARTIFACTS or local shift_right = info.current_mode == df.info_interface_mode_type.ARTIFACTS or
info.current_mode == df.info_interface_mode_type.LABOR info.current_mode == df.info_interface_mode_type.LABOR
@ -386,7 +386,8 @@ local function get_panel_offsets()
if tabs_in_two_rows then if tabs_in_two_rows then
t_offset = shift_right and 0 or 3 t_offset = shift_right and 0 or 3
end end
if info.current_mode == df.info_interface_mode_type.JOBS then if info.current_mode == df.info_interface_mode_type.JOBS or
info.current_mode == df.info_interface_mode_type.BUILDINGS then
t_offset = t_offset - 1 t_offset = t_offset - 1
end end
return l_offset, t_offset return l_offset, t_offset

@ -2,6 +2,7 @@ local _ENV = mkmodule('plugins.sort.places')
local sortoverlay = require('plugins.sort.sortoverlay') local sortoverlay = require('plugins.sort.sortoverlay')
local locationselector = require('plugins.sort.locationselector') local locationselector = require('plugins.sort.locationselector')
local info_overlay = require('plugins.sort.info')
local widgets = require('gui.widgets') local widgets = require('gui.widgets')
local utils = require('utils') local utils = require('utils')
@ -124,6 +125,7 @@ PlacesOverlay.ATTRS{
function PlacesOverlay:init() function PlacesOverlay:init()
self:addviews{ self:addviews{
widgets.BannerPanel{ widgets.BannerPanel{
view_id='panel',
frame={l=0, t=0, r=0, h=1}, frame={l=0, t=0, r=0, h=1},
visible=self:callback('get_key'), visible=self:callback('get_key'),
subviews={ subviews={
@ -154,4 +156,24 @@ function PlacesOverlay:get_key()
end end
end end
function PlacesOverlay:updateFrames()
local ret = info_overlay.resize_overlay(self)
local l, t = info_overlay.get_panel_offsets()
local frame = self.subviews.panel.frame
if frame.l == l and frame.t == t then return ret end
frame.l, frame.t = l, t
local frame2 = self.subviews.subset_panel.frame
frame2.l, frame2.t = l, t + 1
local frame3 = self.subviews.subfilter_panel.frame
frame3.l, frame3.t = l, t + 2
return true
end
function PlacesOverlay:onRenderBody(dc)
PlacesOverlay.super.onRenderBody(self, dc)
if self:updateFrames() then
self:updateLayout()
end
end
return _ENV return _ENV