Skip to content

Commit b1e1c21

Browse files
authored
Main menu improvements (#279)
Main menu improvements
2 parents 340bb39 + ea70f10 commit b1e1c21

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/SCRIPTS/BF/ui.lua

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ local popupMenuActive = false
2929
local lastRunTS = 0
3030
local killEnterBreak = 0
3131
local stopDisplay = true
32-
local scrollPixelsY = 0
32+
local pageScrollY = 0
33+
local mainMenuScrollY = 0
3334

3435
local Page = nil
3536

@@ -158,6 +159,7 @@ local function incPage(inc)
158159
currentPage = incMax(currentPage, inc, #(PageFiles))
159160
Page = nil
160161
currentLine = 1
162+
menuLine = currentPage
161163
collectgarbage()
162164
end
163165

@@ -197,17 +199,17 @@ local function drawScreen()
197199
local screen_title = Page.title
198200
drawScreenTitle("Betaflight / "..screen_title)
199201
if currentLineY <= Page.fieldLayout[1].y then
200-
scrollPixelsY = 0
201-
elseif currentLineY - scrollPixelsY <= yMinLim then
202-
scrollPixelsY = currentLineY - yMinLim
203-
elseif currentLineY - scrollPixelsY >= yMaxLim then
204-
scrollPixelsY = currentLineY - yMaxLim
202+
pageScrollY = 0
203+
elseif currentLineY - pageScrollY <= yMinLim then
204+
pageScrollY = currentLineY - yMinLim
205+
elseif currentLineY - pageScrollY >= yMaxLim then
206+
pageScrollY = currentLineY - yMaxLim
205207
end
206208
for i=1,#(Page.labels) do
207209
local f = Page.labels[i]
208210
local textOptions = radio.textSize + globalTextOptions
209-
if (f.y - scrollPixelsY) >= yMinLim and (f.y - scrollPixelsY) <= yMaxLim then
210-
lcd.drawText(f.x, f.y - scrollPixelsY, f.t, textOptions)
211+
if (f.y - pageScrollY) >= yMinLim and (f.y - pageScrollY) <= yMaxLim then
212+
lcd.drawText(f.x, f.y - pageScrollY, f.t, textOptions)
211213
end
212214
end
213215
local val = "---"
@@ -232,8 +234,8 @@ local function drawScreen()
232234
val = f.table[f.value]
233235
end
234236
end
235-
if (pos.y - scrollPixelsY) >= yMinLim and (pos.y - scrollPixelsY) <= yMaxLim then
236-
lcd.drawText(pos.x, pos.y - scrollPixelsY, val, value_options)
237+
if (pos.y - pageScrollY) >= yMinLim and (pos.y - pageScrollY) <= yMaxLim then
238+
lcd.drawText(pos.x, pos.y - pageScrollY, val, value_options)
237239
end
238240
end
239241
end
@@ -427,20 +429,20 @@ function run_ui(event)
427429
if (not PageFiles[i].requiredVersion) or (apiVersion == 0) or (apiVersion > 0 and PageFiles[i].requiredVersion < apiVersion) then
428430
local currentLineY = (menuLine-1)*lineSpacing + yMinLim
429431
if currentLineY <= yMinLim then
430-
scrollPixelsY = 0
431-
elseif currentLineY - scrollPixelsY <= yMinLim then
432-
scrollPixelsY = currentLineY - yMinLim
433-
elseif currentLineY - scrollPixelsY >= yMaxLim then
434-
scrollPixelsY = currentLineY - yMaxLim
432+
mainMenuScrollY = 0
433+
elseif currentLineY - mainMenuScrollY <= yMinLim then
434+
mainMenuScrollY = currentLineY - yMinLim
435+
elseif currentLineY - mainMenuScrollY >= yMaxLim then
436+
mainMenuScrollY = currentLineY - yMaxLim
435437
end
436438
local attr = (menuLine == i and INVERS or 0)
437439
if event == EVT_VIRTUAL_ENTER and attr == INVERS then
438440
invalidatePages()
439441
currentPage = i
440442
currentState = pageStatus.display
441443
end
442-
if ((i-1)*lineSpacing + yMinLim - scrollPixelsY) >= yMinLim and ((i-1)*lineSpacing + yMinLim - scrollPixelsY) <= yMaxLim then
443-
lcd.drawText(6, (i-1)*lineSpacing + yMinLim - scrollPixelsY, PageFiles[i].title, attr)
444+
if ((i-1)*lineSpacing + yMinLim - mainMenuScrollY) >= yMinLim and ((i-1)*lineSpacing + yMinLim - mainMenuScrollY) <= yMaxLim then
445+
lcd.drawText(6, (i-1)*lineSpacing + yMinLim - mainMenuScrollY, PageFiles[i].title, attr)
444446
end
445447
end
446448
end

0 commit comments

Comments
 (0)