Skip to content

Commit d52e774

Browse files
authored
readerhighlight: anchor style and color selectors
1 parent a2b4ffd commit d52e774

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

frontend/apps/reader/modules/readerhighlight.lua

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
464464
return self.view.highlight.saved_drawer == "lighten"
465465
end,
466466
callback = function(touchmenu_instance)
467-
local spin_widget = SpinWidget:new{
467+
UIManager:show(SpinWidget:new{
468468
value = G_reader_settings:readSetting("highlight_lighten_factor"),
469469
value_min = 0,
470470
value_max = 1,
@@ -481,8 +481,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
481481
UIManager:setDirty(self.dialog, "ui")
482482
touchmenu_instance:updateItems()
483483
end,
484-
}
485-
UIManager:show(spin_widget)
484+
})
486485
end,
487486
})
488487
table.insert(hl_sub_item_table, {
@@ -493,7 +492,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
493492
return self.view.highlight.saved_drawer == "lighten" or self.view.highlight.saved_drawer == "invert"
494493
end,
495494
callback = function(touchmenu_instance)
496-
local spin_widget = SpinWidget:new{
495+
UIManager:show(SpinWidget:new{
497496
value = G_reader_settings:readSetting("highlight_height_pct") or 100,
498497
value_min = 0,
499498
value_max = 100,
@@ -510,8 +509,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
510509
UIManager:setDirty(self.dialog, "ui")
511510
touchmenu_instance:updateItems()
512511
end,
513-
}
514-
UIManager:show(spin_widget)
512+
})
515513
end,
516514
})
517515
table.insert(hl_sub_item_table, {
@@ -732,9 +730,9 @@ If you wish your highlights to be saved in the document, just move it to a writa
732730
})
733731
end
734732
-- highlight dialog position
735-
local sub_item_table = {}
733+
local position_sub_item_table = {}
736734
for i, v in ipairs(highlight_dialog_position) do
737-
table.insert(sub_item_table, {
735+
position_sub_item_table[i] = {
738736
text = v[1],
739737
checked_func = function()
740738
return G_reader_settings:readSetting("highlight_dialog_position", "center") == v[2]
@@ -743,7 +741,7 @@ If you wish your highlights to be saved in the document, just move it to a writa
743741
callback = function()
744742
G_reader_settings:saveSetting("highlight_dialog_position", v[2])
745743
end,
746-
})
744+
}
747745
end
748746
table.insert(menu_items.long_press.sub_item_table, {
749747
text_func = function()
@@ -754,7 +752,7 @@ If you wish your highlights to be saved in the document, just move it to a writa
754752
end
755753
end
756754
end,
757-
sub_item_table = sub_item_table,
755+
sub_item_table = position_sub_item_table,
758756
})
759757
-- highlight prompt
760758
local prompt_sub_item_table = {}
@@ -790,7 +788,7 @@ If you wish your highlights to be saved in the document, just move it to a writa
790788
end,
791789
keep_menu_open = true,
792790
callback = function(touchmenu_instance)
793-
local items = SpinWidget:new{
791+
UIManager:show(SpinWidget:new{
794792
title_text = _("Highlight very-long-press interval"),
795793
info_text = _("If a long-press is not released in this interval, it is considered a very-long-press. On document text, single word selection will not be triggered."),
796794
width = math.floor(self.screen_w * 0.75),
@@ -809,8 +807,7 @@ If you wish your highlights to be saved in the document, just move it to a writa
809807
G_reader_settings:saveSetting("highlight_long_hold_threshold_s", value)
810808
touchmenu_instance:updateItems()
811809
end,
812-
}
813-
UIManager:show(items)
810+
})
814811
end,
815812
})
816813
end
@@ -2269,7 +2266,8 @@ end
22692266

22702267
function ReaderHighlight:editHighlightStyle(index)
22712268
local item = self.ui.annotation.annotations[index]
2272-
UIManager:show(ButtonSelector:new{
2269+
local style_selector
2270+
style_selector = ButtonSelector:new{
22732271
current_value = item.drawer,
22742272
values = highlight_style,
22752273
callback = function(value)
@@ -2284,12 +2282,17 @@ function ReaderHighlight:editHighlightStyle(index)
22842282
UIManager:setDirty(self.dialog, "ui")
22852283
self.ui:handleEvent(Event:new("AnnotationsModified", { item }))
22862284
end,
2287-
})
2285+
anchor = function()
2286+
return self:_getDialogAnchor(style_selector, index)
2287+
end,
2288+
}
2289+
UIManager:show(style_selector)
22882290
end
22892291

22902292
function ReaderHighlight:editHighlightColor(index)
22912293
local item = self.ui.annotation.annotations[index]
2292-
UIManager:show(ButtonSelector:new{
2294+
local color_selector
2295+
color_selector = ButtonSelector:new{
22932296
current_value = item.color,
22942297
values = self.highlight_colors,
22952298
bg_colors = self:getHighlightColorList(),
@@ -2305,7 +2308,11 @@ function ReaderHighlight:editHighlightColor(index)
23052308
UIManager:setDirty(self.dialog, "ui")
23062309
self.ui:handleEvent(Event:new("AnnotationsModified", { item }))
23072310
end,
2308-
})
2311+
anchor = function()
2312+
return self:_getDialogAnchor(color_selector, index)
2313+
end,
2314+
}
2315+
UIManager:show(color_selector)
23092316
end
23102317

23112318
function ReaderHighlight:showHighlightPrompt(caller_callback, prompt)
@@ -2333,7 +2340,8 @@ function ReaderHighlight:showHighlightPrompt(caller_callback, prompt)
23332340
prompt = prompt or G_reader_settings:readSetting("highlight_prompt")
23342341
if prompt then
23352342
if prompt == "color" then
2336-
UIManager:show(ButtonSelector:new{
2343+
local color_selector
2344+
color_selector = ButtonSelector:new{
23372345
current_value = self.view.highlight.saved_color,
23382346
values = self.highlight_colors,
23392347
bg_colors = self:getHighlightColorList(),
@@ -2345,9 +2353,14 @@ function ReaderHighlight:showHighlightPrompt(caller_callback, prompt)
23452353
tap_close_callback = function()
23462354
do_highlight()
23472355
end,
2348-
})
2356+
anchor = function()
2357+
return self:_getDialogAnchor(color_selector)
2358+
end,
2359+
}
2360+
UIManager:show(color_selector)
23492361
else -- "style", "all"
2350-
UIManager:show(ButtonSelector:new{
2362+
local style_selector
2363+
style_selector = ButtonSelector:new{
23512364
current_value = self.view.highlight.saved_drawer,
23522365
values = highlight_style,
23532366
apply_current_value = true,
@@ -2358,7 +2371,11 @@ function ReaderHighlight:showHighlightPrompt(caller_callback, prompt)
23582371
tap_close_callback = function()
23592372
do_highlight(prompt == "all" and self.selected_text.drawer ~= "invert")
23602373
end,
2361-
})
2374+
anchor = function()
2375+
return self:_getDialogAnchor(style_selector)
2376+
end,
2377+
}
2378+
UIManager:show(style_selector)
23622379
end
23632380
else
23642381
do_highlight()

0 commit comments

Comments
 (0)