@ -234,7 +234,7 @@ function DictQuickLookup:init()
-- below the title: lookup word and definition
-- below the title: lookup word and definition
local content_padding_h = Size.padding . large
local content_padding_h = Size.padding . large
local content_padding_v = Size.padding . large -- added via VerticalSpan
local content_padding_v = Size.padding . large -- added via VerticalSpan
local content_width = inner_width - 2 * content_padding_h
self. content_width = inner_width - 2 * content_padding_h
-- Spans between components
-- Spans between components
local top_to_word_span = VerticalSpan : new { width = content_padding_v }
local top_to_word_span = VerticalSpan : new { width = content_padding_v }
@ -305,13 +305,13 @@ function DictQuickLookup:init()
text = self.displayword ,
text = self.displayword ,
face = Font : getFace ( word_font_face , word_font_size ) ,
face = Font : getFace ( word_font_face , word_font_size ) ,
bold = true ,
bold = true ,
max_width = content_width - math.max ( lookup_edit_button_w , lookup_word_nb_w ) ,
max_width = self. content_width - math.max ( lookup_edit_button_w , lookup_word_nb_w ) ,
padding = 0 , -- to be aligned with lookup_word_nb
padding = 0 , -- to be aligned with lookup_word_nb
}
}
-- Group these 3 widgets
-- Group these 3 widgets
local lookup_word = OverlapGroup : new {
local lookup_word = OverlapGroup : new {
dimen = {
dimen = {
w = content_width,
w = self. content_width,
h = lookup_height ,
h = lookup_height ,
} ,
} ,
self.lookup_word_text ,
self.lookup_word_text ,
@ -570,7 +570,7 @@ function DictQuickLookup:init()
local test_widget = ScrollTextWidget : new {
local test_widget = ScrollTextWidget : new {
text = " z " ,
text = " z " ,
face = self.content_face ,
face = self.content_face ,
width = content_width,
width = self. content_width,
height = self.definition_height ,
height = self.definition_height ,
}
}
self.definition_line_height = test_widget : getLineHeight ( )
self.definition_line_height = test_widget : getLineHeight ( )
@ -623,33 +623,8 @@ function DictQuickLookup:init()
end
end
end
end
if self.is_html then
-- Instantiate self.text_widget
self.text_widget = ScrollHtmlWidget : new {
self : _instantiateScrollWidget ( )
html_body = self.definition ,
css = self : getHtmlDictionaryCss ( ) ,
default_font_size = Screen : scaleBySize ( self.dict_font_size ) ,
width = content_width ,
height = self.definition_height ,
dialog = self ,
html_link_tapped_callback = function ( link )
self.html_dictionary_link_tapped_callback ( self.dictionary , link )
end ,
}
else
self.text_widget = ScrollTextWidget : new {
text = self.definition ,
face = self.content_face ,
width = content_width ,
height = self.definition_height ,
dialog = self ,
justified = G_reader_settings : nilOrTrue ( " dict_justify " ) , -- allow for disabling justification
lang = self.lang and self.lang : lower ( ) , -- only available on wikipedia results
para_direction_rtl = self.rtl_lang , -- only available on wikipedia results
auto_para_direction = not self.is_wiki , -- only for dict results (we don't know their lang)
image_alt_face = self.image_alt_face ,
images = self.images ,
}
end
-- word definition
-- word definition
self.definition_widget = FrameContainer : new {
self.definition_widget = FrameContainer : new {
@ -768,6 +743,39 @@ function DictQuickLookup:getHtmlDictionaryCss()
return css
return css
end
end
-- Used in init & update to instantiate the Scroll*Widget that self.text_widget points to
function DictQuickLookup : _instantiateScrollWidget ( )
if self.is_html then
self.shw_widget = ScrollHtmlWidget : new {
html_body = self.definition ,
css = self : getHtmlDictionaryCss ( ) ,
default_font_size = Screen : scaleBySize ( self.dict_font_size ) ,
width = self.content_width ,
height = self.definition_height ,
dialog = self ,
html_link_tapped_callback = function ( link )
self.html_dictionary_link_tapped_callback ( self.dictionary , link )
end ,
}
self.text_widget = self.shw_widget
else
self.stw_widget = ScrollTextWidget : new {
text = self.definition ,
face = self.content_face ,
width = self.content_width ,
height = self.definition_height ,
dialog = self ,
justified = G_reader_settings : nilOrTrue ( " dict_justify " ) , -- allow for disabling justification
lang = self.lang and self.lang : lower ( ) , -- only available on wikipedia results
para_direction_rtl = self.rtl_lang , -- only available on wikipedia results
auto_para_direction = not self.is_wiki , -- only for dict results (we don't know their lang)
image_alt_face = self.image_alt_face ,
images = self.images ,
}
self.text_widget = self.stw_widget
end
end
function DictQuickLookup : update ( )
function DictQuickLookup : update ( )
-- self[1] is a WidgetContainer, its free method will call free on each of its child widget with a free method.
-- self[1] is a WidgetContainer, its free method will call free on each of its child widget with a free method.
-- Here, that's the definitions' TextBoxWidget & HtmlBoxWidget,
-- Here, that's the definitions' TextBoxWidget & HtmlBoxWidget,
@ -794,17 +802,35 @@ function DictQuickLookup:update()
end
end
-- Update main text widgets
-- Update main text widgets
if self.is_html then
if self.is_html and self.shw_widget then
-- Re-use our ScrollHtmlWidget (self.shw_widget)
-- NOTE: The recursive free via our WidgetContainer (self[1]) above already released the previous MµPDF document instance ;)
self.text_widget . htmlbox_widget : setContent ( self.definition , self : getHtmlDictionaryCss ( ) , Screen : scaleBySize ( self.dict_font_size ) )
self.text_widget . htmlbox_widget : setContent ( self.definition , self : getHtmlDictionaryCss ( ) , Screen : scaleBySize ( self.dict_font_size ) )
else
-- Scroll back to top
self.text_widget : resetScroll ( )
elseif not self.is_html and self.stw_widget then
-- Re-use our ScrollTextWidget (self.stw_widget)
self.text_widget . text_widget.text = self.definition
self.text_widget . text_widget.text = self.definition
-- NOTE: The recursive free via our WidgetContainer (self[1]) above already free'd us ;)
-- NOTE: The recursive free via our WidgetContainer (self[1]) above already free'd us ;)
self.text_widget . text_widget : init ( )
self.text_widget . text_widget : init ( )
-- Scroll back to top
self.text_widget : resetScroll ( )
else
-- We jumped from HTML to Text (or vice-versa), we need a new widget instance
self : _instantiateScrollWidget ( )
-- Update *all* the references to self.text_widget
self.definition_widget [ 1 ] = self.text_widget
-- Destroy the previous "opposite type" widget
if self.is_html then
self.stw_widget = nil
else
self.shw_widget = nil
end
end
end
-- Reset alpha to avoid stacking transparency on top of the previous content.
-- Reset alpha to avoid stacking transparency on top of the previous content.
-- NOTE: This doesn't take care of the Scroll*Widget, which will preserve alpha on scroll,
-- NOTE: This doesn't take care of the Scroll*Widget, which will preserve alpha on scroll,
-- leading to increasingly opaque and muddy text as half-tarnsparent stuff gets stacked on top of each other...
-- leading to increasingly opaque and muddy text as half-t ra nsparent stuff gets stacked on top of each other...
self.movable . alpha = nil
self.movable . alpha = nil
UIManager : setDirty ( self , function ( )
UIManager : setDirty ( self , function ( )