<commit_before>require "ui/widget/container"

--[[
Display quick lookup word definition
]]
DictQuickLookup = InputContainer:new{
	dict = nil,
	definition = nil,
	id = nil,
	lang = nil,
	
	title_face = Font:getFace("tfont", 20),
	content_face = Font:getFace("cfont", 18),
}

function DictQuickLookup:init()
	if Device:hasKeyboard() then
		key_events = {
			AnyKeyPressed = { { Input.group.Any },
				seqtext = "any key", doc = _("close dialog") }
		}
	else
		self.ges_events.TapClose = {
			GestureRange:new{
				ges = "tap",
				range = Geom:new{
					x = 0, y = 0,
					w = Screen:getWidth(),
					h = Screen:getHeight(),
				}
			}
		}
	end
	-- we construct the actual content here because self.text is only available now
	self[1] = CenterContainer:new{
		dimen = Screen:getSize(),
		FrameContainer:new{
			margin = 2,
			background = 0,
			VerticalGroup:new{
				align = "center",
				-- title bar
				TextBoxWidget:new{
					text = self.dict,
					face = self.title_face,
					width = Screen:getWidth() - 100,
				},
				VerticalSpan:new{ width = 20 },
				TextBoxWidget:new{
					text = self.definition,
					face = self.content_face,
					width = Screen:getWidth() - 100,
				}
			}
		}
	}
end

function DictQuickLookup:onAnyKeyPressed()
	-- triggered by our defined key events
	UIManager:close(self)
	return true
end

function DictQuickLookup:onTapClose()
	UIManager:close(self)
	return true
end<commit_msg>add faked tap when closing dict window<commit_after>require "ui/widget/container"

--[[
Display quick lookup word definition
]]
DictQuickLookup = InputContainer:new{
	dict = nil,
	definition = nil,
	id = nil,
	lang = nil,
	
	title_face = Font:getFace("tfont", 20),
	content_face = Font:getFace("cfont", 18),
}

function DictQuickLookup:init()
	if Device:hasKeyboard() then
		key_events = {
			AnyKeyPressed = { { Input.group.Any },
				seqtext = "any key", doc = _("close dialog") }
		}
	else
		self.ges_events.TapClose = {
			GestureRange:new{
				ges = "tap",
				range = Geom:new{
					x = 0, y = 0,
					w = Screen:getWidth(),
					h = Screen:getHeight(),
				}
			}
		}
	end
	-- we construct the actual content here because self.text is only available now
	self[1] = CenterContainer:new{
		dimen = Screen:getSize(),
		FrameContainer:new{
			margin = 2,
			background = 0,
			VerticalGroup:new{
				align = "center",
				-- title bar
				TextBoxWidget:new{
					text = self.dict,
					face = self.title_face,
					width = Screen:getWidth() - 100,
				},
				VerticalSpan:new{ width = 20 },
				TextBoxWidget:new{
					text = self.definition,
					face = self.content_face,
					width = Screen:getWidth() - 100,
				}
			}
		}
	}
end

function DictQuickLookup:onAnyKeyPressed()
	-- triggered by our defined key events
	UIManager:close(self)
	return true
end

function DictQuickLookup:onTapClose()
	UIManager:close(self)
	self.ui:handleEvent(Event:new("Tap"))
	return true
end
{'fraction_non_alphanumeric': 0.12551867219917012, 'fraction_numerical': 0.011756569847856155, 'mean_word_length': 3.217201166180758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '939626', 'n_tokens_mistral': 1208, 'n_tokens_neox': 995, 'n_words': 240}