mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #638 from houqp/new_ui_code_fix
zoom mode support in reader menu & menu module bug fix
This commit is contained in:
@@ -214,17 +214,21 @@ function Menu:init()
|
||||
text = self.title,
|
||||
face = self.tface,
|
||||
}
|
||||
|
||||
-- group for items
|
||||
self.item_group = VerticalGroup:new{}
|
||||
self.page_info = TextWidget:new{
|
||||
face = self.fface,
|
||||
}
|
||||
} -- VerticalGroup
|
||||
|
||||
-- group for menu layout
|
||||
local content = VerticalGroup:new{
|
||||
name = "haha",
|
||||
self.menu_title,
|
||||
self.item_group,
|
||||
self.page_info,
|
||||
} -- VerticalGroup
|
||||
self.content_group = content
|
||||
|
||||
if not self.is_borderless then
|
||||
self[1] = CenterContainer:new{
|
||||
@@ -256,8 +260,8 @@ function Menu:init()
|
||||
end
|
||||
|
||||
function Menu:updateItems(select_number)
|
||||
self.layout = {}
|
||||
self.item_group:clear()
|
||||
self.content_group:resetLayout()
|
||||
|
||||
for c = 1, self.perpage do
|
||||
local i = (self.page - 1) * self.perpage + c
|
||||
@@ -286,8 +290,6 @@ function Menu:updateItems(select_number)
|
||||
menu = self,
|
||||
}
|
||||
table.insert(self.item_group, item_tmp)
|
||||
table.insert(self.layout, {item_tmp})
|
||||
--self.last_shortcut = c
|
||||
end -- if i <= self.items
|
||||
end -- for c=1, self.perpage
|
||||
if self.item_group[1] then
|
||||
|
||||
@@ -21,6 +21,12 @@ function ReaderMenu:init()
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderMenu:genSetZoomModeCallBack(mode)
|
||||
return function()
|
||||
self.ui:handleEvent(Event:new("SetZoomMode", mode))
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderMenu:onShowMenu()
|
||||
local item_table = {}
|
||||
|
||||
@@ -31,14 +37,16 @@ function ReaderMenu:onShowMenu()
|
||||
text = "rotate 90 degree clockwise",
|
||||
callback = function()
|
||||
Screen:screenRotate("clockwise")
|
||||
self.ui:handleEvent(Event:new("SetDimensions", Screen:getSize()))
|
||||
self.ui:handleEvent(
|
||||
Event:new("SetDimensions", Screen:getSize()))
|
||||
end
|
||||
},
|
||||
{
|
||||
text = "rotate 90 degree anticlockwise",
|
||||
callback = function()
|
||||
Screen:screenRotate("anticlockwise")
|
||||
self.ui:handleEvent(Event:new("SetDimensions", Screen:getSize()))
|
||||
self.ui:handleEvent(
|
||||
Event:new("SetDimensions", Screen:getSize()))
|
||||
end
|
||||
},
|
||||
}
|
||||
@@ -50,9 +58,27 @@ function ReaderMenu:onShowMenu()
|
||||
sub_item_table = {
|
||||
{
|
||||
text = "Zoom to fit content width",
|
||||
callback = self:genSetZoomModeCallBack("contentwidth")
|
||||
},
|
||||
{
|
||||
text = "Zoom to fit content height",
|
||||
callback = self:genSetZoomModeCallBack("contentheight")
|
||||
},
|
||||
{
|
||||
text = "Zoom to fit page width",
|
||||
callback = self:genSetZoomModeCallBack("pagewidth")
|
||||
},
|
||||
{
|
||||
text = "Zoom to fit page height",
|
||||
callback = self:genSetZoomModeCallBack("pageheight")
|
||||
},
|
||||
{
|
||||
text = "Zoom to fit content",
|
||||
callback = self:genSetZoomModeCallBack("content")
|
||||
},
|
||||
{
|
||||
text = "Zoom to fit page",
|
||||
callback = self:genSetZoomModeCallBack("page")
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -57,7 +57,8 @@ end
|
||||
|
||||
function ReaderView:recalculate()
|
||||
if self.ui.document.info.has_pages then
|
||||
local page_size = self.ui.document:getPageDimensions(self.state.page, self.state.zoom, self.state.rotation)
|
||||
local page_size = self.ui.document:getPageDimensions(
|
||||
self.state.page, self.state.zoom, self.state.rotation)
|
||||
-- TODO: bbox
|
||||
self.page_area = page_size
|
||||
|
||||
@@ -68,7 +69,7 @@ function ReaderView:recalculate()
|
||||
else
|
||||
self.visible_area:setSizeTo(self.dimen)
|
||||
end
|
||||
-- flag a repaint
|
||||
-- flag a repaint so self:paintTo will be called
|
||||
UIManager:setDirty(self.dialog)
|
||||
end
|
||||
|
||||
@@ -105,7 +106,7 @@ function ReaderView:onPosUpdate(new_pos)
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:ZoomUpdate(zoom)
|
||||
function ReaderView:onZoomUpdate(zoom)
|
||||
self.state.zoom = zoom
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
@@ -1,13 +1,37 @@
|
||||
ReaderZooming = InputContainer:new{
|
||||
key_events = {
|
||||
ZoomIn = { { "Shift", Input.group.PgFwd }, doc = "zoom in", event = "Zoom", args = "in" },
|
||||
ZoomOut = { { "Shift", Input.group.PgBack }, doc = "zoom out", event = "Zoom", args = "out" },
|
||||
ZoomToFitPage = { {"A"}, doc = "zoom to fit page", event = "SetZoomMode", args = "page" },
|
||||
ZoomToFitContent = { {"Shift", "A"}, doc = "zoom to fit content", event = "SetZoomMode", args = "content" },
|
||||
ZoomToFitPageWidth = { {"S"}, doc = "zoom to fit page width", event = "SetZoomMode", args = "pagewidth" },
|
||||
ZoomToFitContentWidth = { {"Shift", "S"}, doc = "zoom to fit content width", event = "SetZoomMode", args = "contentwidth" },
|
||||
ZoomToFitPageHeight = { {"D"}, doc = "zoom to fit page height", event = "SetZoomMode", args = "pageheight" },
|
||||
ZoomToFitContentHeight = { {"Shift", "D"}, doc = "zoom to fit content height", event = "SetZoomMode", args = "contentheight" },
|
||||
ZoomIn = {
|
||||
{ "Shift", Input.group.PgFwd },
|
||||
doc = "zoom in", event = "Zoom", args = "in"
|
||||
},
|
||||
ZoomOut = {
|
||||
{ "Shift", Input.group.PgBack },
|
||||
doc = "zoom out", event = "Zoom", args = "out"
|
||||
},
|
||||
ZoomToFitPage = {
|
||||
{ "A" },
|
||||
doc = "zoom to fit page", event = "SetZoomMode", args = "page"
|
||||
},
|
||||
ZoomToFitContent = {
|
||||
{ "Shift", "A" },
|
||||
doc = "zoom to fit content", event = "SetZoomMode", args = "content"
|
||||
},
|
||||
ZoomToFitPageWidth = {
|
||||
{ "S" },
|
||||
doc = "zoom to fit page width", event = "SetZoomMode", args = "pagewidth"
|
||||
},
|
||||
ZoomToFitContentWidth = {
|
||||
{ "Shift", "S" },
|
||||
doc = "zoom to fit content width", event = "SetZoomMode", args = "contentwidth"
|
||||
},
|
||||
ZoomToFitPageHeight = {
|
||||
{ "D" },
|
||||
doc = "zoom to fit page height", event = "SetZoomMode", args = "pageheight"
|
||||
},
|
||||
ZoomToFitContentHeight = {
|
||||
{ "Shift", "D" },
|
||||
doc = "zoom to fit content height", event = "SetZoomMode", args = "contentheight"
|
||||
},
|
||||
},
|
||||
zoom = 1.0,
|
||||
zoom_mode = "free",
|
||||
@@ -32,7 +56,9 @@ function ReaderZooming:setZoom()
|
||||
end
|
||||
-- check if we're in bbox mode and work on bbox if that's the case
|
||||
local page_size = {}
|
||||
if self.zoom_mode == "content" or self.zoom_mode == "contentwidth" or self.zoom_mode == "content_height" then
|
||||
if self.zoom_mode == "content"
|
||||
or self.zoom_mode == "contentwidth"
|
||||
or self.zoom_mode == "contentheight" then
|
||||
-- TODO: enable this, still incomplete
|
||||
page_size = self.ui.document:getUsedBBox(self.current_page)
|
||||
self.view:handleEvent(Event:new("BBoxUpdate", page_size))
|
||||
@@ -59,7 +85,7 @@ function ReaderZooming:setZoom()
|
||||
elseif self.zoom_mode == "contentheight" or self.zoom_mode == "pageheight" then
|
||||
self.zoom = zoom_h
|
||||
end
|
||||
self.view:ZoomUpdate(self.zoom)
|
||||
self.view:onZoomUpdate(self.zoom)
|
||||
end
|
||||
|
||||
function ReaderZooming:onZoom(direction)
|
||||
@@ -71,7 +97,7 @@ function ReaderZooming:onZoom(direction)
|
||||
end
|
||||
DEBUG("zoom is now at", self.zoom)
|
||||
self:onSetZoomMode("free")
|
||||
self.view:ZoomUpdate(self.zoom)
|
||||
self.view:onZoomUpdate(self.zoom)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ FrameContainer = WidgetContainer:new{
|
||||
|
||||
function FrameContainer:getSize()
|
||||
local content_size = WidgetContainer.getSize(self)
|
||||
|
||||
return {
|
||||
w = content_size.w + ( self.margin + self.bordersize + self.padding ) * 2,
|
||||
h = content_size.h + ( self.margin + self.bordersize + self.padding ) * 2
|
||||
@@ -394,9 +395,18 @@ function HorizontalGroup:paintTo(bb, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
function HorizontalGroup:free()
|
||||
function HorizontalGroup:clear()
|
||||
self:free()
|
||||
WidgetContainer.clear(self)
|
||||
end
|
||||
|
||||
function HorizontalGroup:resetLayout()
|
||||
self._size = nil
|
||||
self._offsets = {}
|
||||
end
|
||||
|
||||
function HorizontalGroup:free()
|
||||
self:resetLayout()
|
||||
WidgetContainer.free(self)
|
||||
end
|
||||
|
||||
@@ -453,9 +463,18 @@ function VerticalGroup:paintTo(bb, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
function VerticalGroup:free()
|
||||
function VerticalGroup:clear()
|
||||
self:free()
|
||||
WidgetContainer.clear(self)
|
||||
end
|
||||
|
||||
function VerticalGroup:resetLayout()
|
||||
self._size = nil
|
||||
self._offsets = {}
|
||||
end
|
||||
|
||||
function VerticalGroup:free()
|
||||
self:resetLayout()
|
||||
WidgetContainer.free(self)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user