mirror of
https://github.com/koreader/koreader
synced 2024-11-16 06:12:56 +00:00
e699a1ee22
Alternative code to size, split lines and draw text with the help of the xtext Lua C module. Enabled by default (can be disabled via an added menu item in "Developer options"). New properties can be specified by calling widgets, only used when xtext is used: - lang: use specified language instead of the UI language - para_direction_rtl: true/false to override the default direction for the UI language - auto_para_direction: detect direction of each paragraph in text - alignment_strict: prevent the inversion of the specified alignment= that is done when a paragraph direction is set or detected as RTL. Also: fix possible memory leak (present even when not using xtext) by calling :free() in onCloseWidget() like it's done in ImageWidget.
58 lines
1.8 KiB
Lua
58 lines
1.8 KiB
Lua
describe("TextBoxWidget module", function()
|
|
local TextBoxWidget, Font
|
|
setup(function()
|
|
require("commonrequire")
|
|
Font = require("ui/font")
|
|
TextBoxWidget = require("ui/widget/textboxwidget")
|
|
end)
|
|
|
|
it("should select the correct word on HoldWord event", function()
|
|
local tw = TextBoxWidget:new{
|
|
dimen = {x = 0, y = 0},
|
|
face = Font:getFace("cfont", 25),
|
|
text = 'YOOOOOOOOOOOOOOOO\nFoo.\nBar.\nFoo welcomes Bar into the fun.',
|
|
}
|
|
|
|
local pos={x=110,y=4}
|
|
tw:onHoldStartText(nil, {pos=pos})
|
|
tw:onHoldReleaseText(function(w)
|
|
assert.is.same(w, 'YOOOOOOOOOOOOOOOO')
|
|
end, {pos=pos})
|
|
|
|
pos={x=0,y=50}
|
|
tw:onHoldStartText(nil, {pos=pos})
|
|
tw:onHoldReleaseText(function(w)
|
|
assert.is.same(w, 'Foo')
|
|
end, {pos=pos})
|
|
|
|
pos={x=20,y=80}
|
|
tw:onHoldStartText(nil, {pos=pos})
|
|
tw:onHoldReleaseText(function(w)
|
|
assert.is.same(w, 'Bar')
|
|
end, {pos=pos})
|
|
|
|
tw:onHoldStartText(nil, {pos={x=50, y=100}})
|
|
tw:onHoldReleaseText(function(w)
|
|
assert.is.same(w, 'welcomes Bar into')
|
|
end, {pos={x=240, y=100}})
|
|
|
|
tw:onHoldStartText(nil, {pos={x=20, y=80}})
|
|
tw:onHoldReleaseText(function(w)
|
|
assert.is.same(w, 'Bar.\nFoo welcomes Bar into')
|
|
end, {pos={x=240, y=100}})
|
|
|
|
--[[
|
|
-- No more used, not implemented when use_xtext=true
|
|
tw:onHoldWord(function(w)
|
|
assert.is.same(w, 'YOOOOOOOOOOOOOOOO')
|
|
end, {pos={x=110,y=4}})
|
|
tw:onHoldWord(function(w)
|
|
assert.is.same(w, 'Foo')
|
|
end, {pos={x=0,y=50}})
|
|
tw:onHoldWord(function(w)
|
|
assert.is.same(w, 'Bar')
|
|
end, {pos={x=20,y=80}})
|
|
]]--
|
|
end)
|
|
end)
|