<commit_before>--[[
Display some text in scrollable view
]]
local Blitbuffer = require("ffi/blitbuffer")
local ButtonTable = require("ui/widget/buttontable")
local CenterContainer = require("ui/widget/container/centercontainer")
local CloseButton = require("ui/widget/closebutton")
local Device = require("device")
local Geom = require("ui/geometry")
local Font = require("ui/font")
local FrameContainer = require("ui/widget/container/framecontainer")
local GestureRange = require("ui/gesturerange")
local InputContainer = require("ui/widget/container/inputcontainer")
local LineWidget = require("ui/widget/linewidget")
local OverlapGroup = require("ui/widget/overlapgroup")
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
local TextWidget = require("ui/widget/textwidget")
local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local logger = require("logger")
local _ = require("gettext")
local Screen = Device.screen

local TextViewer = InputContainer:new{
    title = nil,
    text = nil,
    width = nil,
    height = nil,

    title_face = Font:getFace("x_smalltfont"),
    text_face = Font:getFace("x_smallinfofont"),
    title_padding = Screen:scaleBySize(5),
    title_margin = Screen:scaleBySize(2),
    text_padding = Screen:scaleBySize(10),
    text_margin = Screen:scaleBySize(2),
    button_padding = Screen:scaleBySize(14),
}

function TextViewer:init()
    local orig_dimen = self.frame and self.frame.dimen or Geom:new{}
    -- calculate window dimension
    self.align = "center"
    self.region = Geom:new{
        x = 0, y = 0,
        w = Screen:getWidth(),
        h = Screen:getHeight(),
    }
    self.width = self.width or Screen:getWidth() - Screen:scaleBySize(30)
    self.height = self.height or Screen:getHeight() - Screen:scaleBySize(30)

    if Device:hasKeys() then
        self.key_events = {
            Close = { {"Back"}, doc = "close text viewer" }
        }
    end

    if Device:isTouchDevice() then
        self.ges_events = {
            TapClose = {
                GestureRange:new{
                    ges = "tap",
                    range = Geom:new{
                        x = 0, y = 0,
                        w = Screen:getWidth(),
                        h = Screen:getHeight(),
                    }
                },
            },
            Swipe = {
                GestureRange:new{
                    ges = "swipe",
                    range = Geom:new{
                        x = 0, y = 0,
                        w = Screen:getWidth(),
                        h = Screen:getHeight(),
                    }
                },
            },
        }
    end

    local title_text = TextWidget:new{
        text = self.title,
        face = self.title_face,
        bold = true,
        width = self.width - 2*self.title_padding - 2*self.title_margin,
    }
    local titlew = FrameContainer:new{
        padding = self.title_padding,
        margin = self.title_margin,
        bordersize = 0,
        CenterContainer:new{
            dimen = Geom:new{
                w = self.width,
                h = title_text:getSize().h,
            },
            title_text
        }
    }
    titlew = OverlapGroup:new{
        dimen = {
            w = self.width,
            h = titlew:getSize().h
        },
        titlew,
        CloseButton:new{ window = self, },
    }
<commit_msg>Wrap text in TextViewer (#3036)<commit_after>--[[
Display some text in scrollable view
]]
local Blitbuffer = require("ffi/blitbuffer")
local ButtonTable = require("ui/widget/buttontable")
local CenterContainer = require("ui/widget/container/centercontainer")
local CloseButton = require("ui/widget/closebutton")
local Device = require("device")
local Geom = require("ui/geometry")
local Font = require("ui/font")
local FrameContainer = require("ui/widget/container/framecontainer")
local GestureRange = require("ui/gesturerange")
local InputContainer = require("ui/widget/container/inputcontainer")
local LineWidget = require("ui/widget/linewidget")
local OverlapGroup = require("ui/widget/overlapgroup")
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
local TextBoxWidget = require("ui/widget/textboxwidget")
local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local logger = require("logger")
local _ = require("gettext")
local Screen = Device.screen

local TextViewer = InputContainer:new{
    title = nil,
    text = nil,
    width = nil,
    height = nil,

    title_face = Font:getFace("x_smalltfont"),
    text_face = Font:getFace("x_smallinfofont"),
    title_padding = Screen:scaleBySize(5),
    title_margin = Screen:scaleBySize(2),
    text_padding = Screen:scaleBySize(10),
    text_margin = Screen:scaleBySize(2),
    button_padding = Screen:scaleBySize(14),
}

function TextViewer:init()
    local orig_dimen = self.frame and self.frame.dimen or Geom:new{}
    -- calculate window dimension
    self.align = "center"
    self.region = Geom:new{
        x = 0, y = 0,
        w = Screen:getWidth(),
        h = Screen:getHeight(),
    }
    self.width = self.width or Screen:getWidth() - Screen:scaleBySize(30)
    self.height = self.height or Screen:getHeight() - Screen:scaleBySize(30)

    if Device:hasKeys() then
        self.key_events = {
            Close = { {"Back"}, doc = "close text viewer" }
        }
    end

    if Device:isTouchDevice() then
        self.ges_events = {
            TapClose = {
                GestureRange:new{
                    ges = "tap",
                    range = Geom:new{
                        x = 0, y = 0,
                        w = Screen:getWidth(),
                        h = Screen:getHeight(),
                    }
                },
            },
            Swipe = {
                GestureRange:new{
                    ges = "swipe",
                    range = Geom:new{
                        x = 0, y = 0,
                        w = Screen:getWidth(),
                        h = Screen:getHeight(),
                    }
                },
            },
        }
    end

    local closeb = CloseButton:new{ window = self, }
    local title_text = TextBoxWidget:new{
        text = self.title,
        face = self.title_face,
        bold = true,
        width = self.width - 2*self.title_padding - 2*self.title_margin - closeb:getSize().w,
    }
    local titlew = FrameContainer:new{
        padding = self.title_padding,
        margin = self.title_margin,
        bordersize = 0,
        CenterContainer:new{
            dimen = Geom:new{
                w = self.width,
                h = title_text:getSize().h,
            },
            title_text
        }
    }
    titlew = OverlapGroup:new{
        dimen = {
            w = self.width,
            h = titlew:getSize().h
        },
        titlew,
        closeb,
    }

{'fraction_non_alphanumeric': 0.11536273115220484, 'fraction_numerical': 0.006258890469416785, 'mean_word_length': 2.0689655172413794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1190419', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1984, 'n_words': 428}