mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
TextViewer: insert TitleBar (#8625)
This commit is contained in:
parent
a1cbc3bb9e
commit
1bd7b4f088
@ -12,19 +12,16 @@ local BD = require("ui/bidi")
|
|||||||
local Blitbuffer = require("ffi/blitbuffer")
|
local Blitbuffer = require("ffi/blitbuffer")
|
||||||
local ButtonTable = require("ui/widget/buttontable")
|
local ButtonTable = require("ui/widget/buttontable")
|
||||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||||
local CloseButton = require("ui/widget/closebutton")
|
|
||||||
local Device = require("device")
|
local Device = require("device")
|
||||||
local Geom = require("ui/geometry")
|
local Geom = require("ui/geometry")
|
||||||
local Font = require("ui/font")
|
local Font = require("ui/font")
|
||||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||||
local GestureRange = require("ui/gesturerange")
|
local GestureRange = require("ui/gesturerange")
|
||||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||||
local LineWidget = require("ui/widget/linewidget")
|
|
||||||
local MovableContainer = require("ui/widget/container/movablecontainer")
|
local MovableContainer = require("ui/widget/container/movablecontainer")
|
||||||
local OverlapGroup = require("ui/widget/overlapgroup")
|
|
||||||
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
|
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
|
||||||
local Size = require("ui/size")
|
local Size = require("ui/size")
|
||||||
local TextBoxWidget = require("ui/widget/textboxwidget")
|
local TitleBar = require("ui/widget/titlebar")
|
||||||
local UIManager = require("ui/uimanager")
|
local UIManager = require("ui/uimanager")
|
||||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||||
@ -51,11 +48,11 @@ local TextViewer = InputContainer:new{
|
|||||||
auto_para_direction = true,
|
auto_para_direction = true,
|
||||||
alignment_strict = false,
|
alignment_strict = false,
|
||||||
|
|
||||||
title_face = Font:getFace("x_smalltfont"),
|
title_face = nil, -- use default from TitleBar
|
||||||
|
title_multilines = nil, -- see TitleBar for details
|
||||||
|
title_shrink_font_to_fit = nil, -- see TitleBar for details
|
||||||
text_face = Font:getFace("x_smallinfofont"),
|
text_face = Font:getFace("x_smallinfofont"),
|
||||||
fgcolor = Blitbuffer.COLOR_BLACK,
|
fgcolor = Blitbuffer.COLOR_BLACK,
|
||||||
title_padding = Size.padding.default,
|
|
||||||
title_margin = Size.margin.title,
|
|
||||||
text_padding = Size.padding.large,
|
text_padding = Size.padding.large,
|
||||||
text_margin = Size.margin.small,
|
text_margin = Size.margin.small,
|
||||||
button_padding = Size.padding.default,
|
button_padding = Size.padding.default,
|
||||||
@ -103,43 +100,20 @@ function TextViewer:init()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local closeb = CloseButton:new{ window = self, padding_top = Size.padding.tiny, }
|
local titlebar = TitleBar:new{
|
||||||
local title_text = TextBoxWidget:new{
|
width = self.width,
|
||||||
text = self.title,
|
align = "left",
|
||||||
face = self.title_face,
|
with_bottom_line = true,
|
||||||
bold = true,
|
title = self.title,
|
||||||
width = self.width - 2*self.title_padding - 2*self.title_margin - closeb:getSize().w,
|
title_face = self.title_face,
|
||||||
}
|
title_multilines = self.title_multilines,
|
||||||
local titlew = FrameContainer:new{
|
title_shrink_font_to_fit = self.title_shrink_font_to_fit,
|
||||||
padding = self.title_padding,
|
close_callback = function() self:onClose() end,
|
||||||
-- TextBoxWidget has less text top & bottom padding than TextWidget
|
show_parent = self,
|
||||||
-- (for a reasonable line height with multi lines), but we
|
|
||||||
-- can get the same as TextWidget by simply adding Size.padding.small
|
|
||||||
padding_top = self.title_padding + Size.padding.small,
|
|
||||||
padding_bottom = self.title_padding + Size.padding.small,
|
|
||||||
margin = self.title_margin,
|
|
||||||
bordersize = 0,
|
|
||||||
title_text
|
|
||||||
}
|
|
||||||
titlew = OverlapGroup:new{
|
|
||||||
dimen = {
|
|
||||||
w = self.width,
|
|
||||||
h = titlew:getSize().h
|
|
||||||
},
|
|
||||||
titlew,
|
|
||||||
closeb,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local separator = LineWidget:new{
|
local buttons = self.buttons_table or
|
||||||
dimen = Geom:new{
|
{
|
||||||
w = self.width,
|
|
||||||
h = Size.line.thick,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local buttons
|
|
||||||
if self.buttons_table == nil then
|
|
||||||
buttons = {
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
text = _("Close"),
|
text = _("Close"),
|
||||||
@ -149,19 +123,14 @@ function TextViewer:init()
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
else
|
|
||||||
buttons = self.buttons_table
|
|
||||||
end
|
|
||||||
local button_table = ButtonTable:new{
|
local button_table = ButtonTable:new{
|
||||||
width = self.width - 2*self.button_padding,
|
width = self.width - 2*self.button_padding,
|
||||||
button_font_face = "cfont",
|
|
||||||
button_font_size = 20,
|
|
||||||
buttons = buttons,
|
buttons = buttons,
|
||||||
zero_sep = true,
|
zero_sep = true,
|
||||||
show_parent = self,
|
show_parent = self,
|
||||||
}
|
}
|
||||||
|
|
||||||
local textw_height = self.height - titlew:getSize().h - separator:getSize().h - button_table:getSize().h
|
local textw_height = self.height - titlebar:getHeight() - button_table:getSize().h
|
||||||
|
|
||||||
self.scroll_text_w = ScrollTextWidget:new{
|
self.scroll_text_w = ScrollTextWidget:new{
|
||||||
text = self.text,
|
text = self.text,
|
||||||
@ -190,9 +159,7 @@ function TextViewer:init()
|
|||||||
margin = 0,
|
margin = 0,
|
||||||
background = Blitbuffer.COLOR_WHITE,
|
background = Blitbuffer.COLOR_WHITE,
|
||||||
VerticalGroup:new{
|
VerticalGroup:new{
|
||||||
align = "left",
|
titlebar,
|
||||||
titlew,
|
|
||||||
separator,
|
|
||||||
CenterContainer:new{
|
CenterContainer:new{
|
||||||
dimen = Geom:new{
|
dimen = Geom:new{
|
||||||
w = self.width,
|
w = self.width,
|
||||||
|
Loading…
Reference in New Issue
Block a user