Skip to content

Commit 48ca7e8

Browse files
committed
DictQuickLookup: update to TitleBar widget
Also tweak ReaderHighlight:onHoldRelease() to avoid doing its stuff when onHold() is clearing highlight (previous CheckButton was closing/clearing on hold release, new TitleBar close button does that on hold).
1 parent 4546d82 commit 48ca7e8

2 files changed

Lines changed: 22 additions & 51 deletions

File tree

frontend/apps/reader/modules/readerhighlight.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,14 @@ function ReaderHighlight:onTranslateText(text)
13271327
end
13281328

13291329
function ReaderHighlight:onHoldRelease()
1330+
if self.clear_id then
1331+
-- Something has requested a clear id and is about to clear
1332+
-- the highlight: it may be a onHoldClose() that handled
1333+
-- "hold" and was closed, and can't handle "hold_release":
1334+
-- ignore this "hold_release" event.
1335+
return true
1336+
end
1337+
13301338
local default_highlight_action = G_reader_settings:readSetting("default_highlight_action", "ask")
13311339

13321340
if self.select_mode then -- extended highlighting, ending fragment

frontend/ui/widget/dictquicklookup.lua

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local BD = require("ui/bidi")
22
local Blitbuffer = require("ffi/blitbuffer")
33
local ButtonTable = require("ui/widget/buttontable")
44
local CenterContainer = require("ui/widget/container/centercontainer")
5-
local CloseButton = require("ui/widget/closebutton")
65
local Device = require("device")
76
local Geom = require("ui/geometry")
87
local Event = require("ui/event")
@@ -12,7 +11,6 @@ local GestureRange = require("ui/gesturerange")
1211
local IconButton = require("ui/widget/iconbutton")
1312
local InputContainer = require("ui/widget/container/inputcontainer")
1413
local InputDialog = require("ui/widget/inputdialog")
15-
local LineWidget = require("ui/widget/linewidget")
1614
local Math = require("optmath")
1715
local MovableContainer = require("ui/widget/container/movablecontainer")
1816
local OverlapGroup = require("ui/widget/overlapgroup")
@@ -21,6 +19,7 @@ local ScrollTextWidget = require("ui/widget/scrolltextwidget")
2119
local Size = require("ui/size")
2220
local TextWidget = require("ui/widget/textwidget")
2321
local TimeVal = require("ui/timeval")
22+
local TitleBar = require("ui/widget/titlebar")
2423
local Translator = require("ui/translator")
2524
local UIManager = require("ui/uimanager")
2625
local VerticalGroup = require("ui/widget/verticalgroup")
@@ -205,50 +204,16 @@ function DictQuickLookup:init()
205204
-- components, when we know how much height they are taking.
206205

207206
-- Dictionary title
208-
-- (a bit convoluted with margin & padding but no border, but let's
209-
-- do as other widgets to get the same look)
210-
local title_margin = Size.margin.title
211-
local title_padding = Size.padding.default
212-
local title_width = inner_width - 2*title_padding -2*title_margin
213-
local close_button = CloseButton:new{ window = self, padding_top = title_margin, }
214-
self.dict_title_text = TextWidget:new{
215-
text = self.displaydictname,
216-
face = Font:getFace("x_smalltfont"),
217-
bold = true,
218-
max_width = title_width - close_button:getSize().w + close_button.padding_left
219-
-- Allow text to eat on the CloseButton padding_left (which
220-
-- is quite large to ensure a bigger tap area)
221-
}
222-
local dict_title_widget = self.dict_title_text
223-
if self.is_wiki then
224-
-- Visual hint: title left aligned for dict, but centered for Wikipedia
225-
dict_title_widget = CenterContainer:new{
226-
dimen = Geom:new{
227-
w = title_width,
228-
h = self.dict_title_text:getSize().h,
229-
},
230-
self.dict_title_text,
231-
}
232-
end
233-
self.dict_title = FrameContainer:new{
234-
margin = title_margin,
235-
bordersize = 0,
236-
padding = title_padding,
237-
dict_title_widget,
238-
}
239-
local title_bar = OverlapGroup:new{
240-
dimen = {
241-
w = inner_width,
242-
h = self.dict_title:getSize().h
243-
},
244-
self.dict_title,
245-
close_button,
246-
}
247-
local title_sep = LineWidget:new{
248-
dimen = Geom:new{
249-
w = inner_width,
250-
h = Size.line.thick,
251-
}
207+
self.dict_title = TitleBar:new{
208+
width = inner_width,
209+
title = self.displaydictname,
210+
with_bottom_line = true,
211+
bottom_v_padding = 0, -- padding handled below
212+
close_callback = function() self:onClose() end,
213+
close_hold_callback = function() self:onHoldClose() end,
214+
-- visual hint: title left aligned for dict, centered for Wikipedia
215+
align = self.is_wiki and "center" or "left",
216+
show_parent = self,
252217
}
253218

254219
-- This padding and the resulting width apply to the content
@@ -577,8 +542,7 @@ function DictQuickLookup:init()
577542
self.align = "center"
578543

579544
local others_height = frame_bordersize * 2 -- DictQuickLookup border
580-
+ title_bar:getSize().h
581-
+ title_sep:getSize().h
545+
+ self.dict_title:getHeight()
582546
+ top_to_word_span:getSize().h
583547
+ lookup_word:getSize().h
584548
+ word_to_definition_span:getSize().h
@@ -684,8 +648,7 @@ function DictQuickLookup:init()
684648
background = Blitbuffer.COLOR_WHITE,
685649
VerticalGroup:new{
686650
align = "left",
687-
title_bar,
688-
title_sep,
651+
self.dict_title,
689652
top_to_word_span,
690653
-- word
691654
CenterContainer:new{
@@ -839,7 +802,7 @@ function DictQuickLookup:update()
839802
self[1]:free()
840803

841804
-- Update TextWidgets
842-
self.dict_title_text:setText(self.displaydictname)
805+
self.dict_title:setTitle(self.displaydictname)
843806
if self.displaynb then
844807
self.displaynb_text:setText(self.displaynb)
845808
end

0 commit comments

Comments
 (0)