Skip to content

Commit

Permalink
recalculate displayed textures on render, not feed
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jan 2, 2023
1 parent 1323bd3 commit b4c8a5f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions devel/tile-browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function TileBrowser:init()
resizable=true,
resize_min={h=20},
frame_title='Tile Browser',
on_submit=self:callback('set_start_index'),
}
main_panel:addviews{
widgets.EditField{
Expand Down Expand Up @@ -75,8 +74,14 @@ function TileBrowser:set_start_index(idx)

idx = idx - (idx % 20) -- floor to nearest multiple of 20
self.subviews.start_index:setText(tostring(idx))
self.dirty = true
end

function TileBrowser:update_report()
if not self.dirty then return end

local end_idx = idx + 999
local idx = tonumber(self.subviews.start_index.text)
local end_idx = math.min(self.max_texpos, idx + 999)
local prefix_len = #tostring(idx) + 4

local guide = {}
Expand All @@ -87,7 +92,6 @@ function TileBrowser:set_start_index(idx)

local report = {}
for texpos=idx,end_idx do
if texpos > self.max_texpos then break end
if texpos % 20 == 0 then
table.insert(report, {text=tostring(texpos), width=prefix_len})
elseif texpos % 10 == 0 then
Expand All @@ -100,13 +104,12 @@ function TileBrowser:set_start_index(idx)
end

self.subviews.report:setText(report)
if self.parent_rect then
self.subviews.window:updateLayout()
end
self.subviews.window:updateLayout()
end

function TileBrowser:onRenderFrame()
self:renderParent()
self:update_report()
end

function TileBrowser:onInput(keys)
Expand Down

0 comments on commit b4c8a5f

Please sign in to comment.