Skip to content

Commit c880e24

Browse files
committed
Implement scrolling
1 parent e4c1628 commit c880e24

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/SCRIPTS/BF/ui.lua

+20-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ local telemetryScreenActive = false
2727
local menuActive = false
2828
local lastRunTS = 0
2929
local killEnterBreak = 0
30+
local scrollPixelsY = 0
3031

3132
Page = nil
3233

@@ -174,12 +175,24 @@ function drawScreenTitle(screen_title)
174175
end
175176

176177
local function drawScreen()
178+
local yMinLim = Page.yMinLimit or 0
179+
local yMaxLim = Page.yMaxLimit or LCD_H
180+
local currentLineY = Page.fields[currentLine].y
177181
local screen_title = Page.title
178182
drawScreenTitle("Betaflight / "..screen_title)
183+
if currentLine == 1 then
184+
scrollPixelsY = 0
185+
elseif currentLineY - scrollPixelsY <= yMinLim then
186+
scrollPixelsY = currentLineY - yMinLim
187+
elseif currentLineY - scrollPixelsY >= yMaxLim then
188+
scrollPixelsY = currentLineY - yMaxLim
189+
end
179190
for i=1,#(Page.text) do
180191
local f = Page.text[i]
181192
local textOptions = (f.to or 0) + globalTextOptions
182-
lcd.drawText(f.x, f.y, f.t, textOptions)
193+
if (f.y - scrollPixelsY) >= yMinLim and (f.y - scrollPixelsY) <= yMaxLim then
194+
lcd.drawText(f.x, f.y - scrollPixelsY, f.t, textOptions)
195+
end
183196
end
184197
local val = "---"
185198
for i=1,#(Page.fields) do
@@ -195,7 +208,9 @@ local function drawScreen()
195208
end
196209
local spacing = 20
197210
if f.t ~= nil then
198-
lcd.drawText(f.x, f.y, f.t, heading_options)
211+
if (f.y - scrollPixelsY) >= yMinLim and (f.y - scrollPixelsY) <= yMaxLim then
212+
lcd.drawText(f.x, f.y - scrollPixelsY, f.t, heading_options)
213+
end
199214
if f.sp ~= nil then
200215
spacing = f.sp
201216
end
@@ -211,7 +226,9 @@ local function drawScreen()
211226
val = f.table[f.value]
212227
end
213228
end
214-
lcd.drawText(f.x + spacing, f.y, val, value_options)
229+
if (f.y - scrollPixelsY) >= yMinLim and (f.y - scrollPixelsY) <= yMaxLim then
230+
lcd.drawText(f.x + spacing, f.y - scrollPixelsY, val, value_options)
231+
end
215232
end
216233
end
217234

0 commit comments

Comments
 (0)