From 6d6d7188a8f7832e7ce80dc53cf34935e40e6014 Mon Sep 17 00:00:00 2001 From: Tom Kirchner Date: Wed, 8 Jan 2025 21:24:27 -0800 Subject: [PATCH] Allow scrolling of license text --- lua/licenses.lua | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lua/licenses.lua b/lua/licenses.lua index 0ccbcb65..59251b51 100644 --- a/lua/licenses.lua +++ b/lua/licenses.lua @@ -7,6 +7,7 @@ local widgets = require("widgets") local font = require("font") local styles = require("styles") local screen = require("screen") +local lvgl = require("lvgl") local function show_license(text) backstack.push(widgets.MenuScreen:new { @@ -14,12 +15,22 @@ local function show_license(text) title = "Licenses", create_ui = function(self) widgets.MenuScreen.create_ui(self) - self.root:Label { - w = lvgl.PCT(100), - h = lvgl.SIZE_CONTENT, - text_font = font.fusion_10, - text = text, - } + -- Licenses are all longer than one screen, so we need to be able to + -- scroll to read all the text. Break up the content by line, and + -- insert an object after each line that the user can scroll to. + for line in text:gmatch("[^\r\n]+") do + self.root:Label { + w = lvgl.PCT(100), + h = lvgl.SIZE_CONTENT, + text_font = font.fusion_10, + text = line, + } + local scroller = self.root:Object { w = 1, h = 1 } + scroller:onevent(lvgl.EVENT.FOCUSED, function() + scroller:scroll_to_view(1) + end) + lvgl.group.get_default():add_obj(scroller) + end end }) end