[MultiInputDialog] Split password field and checkbox (#15234)

This commit is contained in:
David authored and GitHub committed 2026-04-08 10:26:33 +02:00
1 parent 6121412202
commit 9cef2f1198
3 files changed
+62 -53

No files matched your search

+15
View File
@@ -393,6 +393,10 @@ function InputDialog:init()
charpos = self._charpos,
}
table.insert(self.layout[1], self._input_widget)
self._password_toggle_widget = self._input_widget:getPasswordToggleWidget()
if self._password_toggle_widget then
table.insert(self.layout, { self._password_toggle_widget })
end
self:mergeLayoutInVertical(self.button_table)
-- NOTE: Never send a Focus event, as, on hasDPad device, InputText's onFocus *will* call onShowKeyboard,
-- and that will wreak havoc on toggleKeyboard...
@@ -430,6 +434,17 @@ function InputDialog:init()
vspan_after_input_text,
buttons_container,
}
if self._password_toggle_widget then
local toggle_row = CenterContainer:new{
dimen = Geom:new{
w = self.width,
h = self._password_toggle_widget:getSize().h,
},
self._password_toggle_widget,
}
-- Keep password toggle between input field and the post-input spacer.
table.insert(self.vgroup, 4, toggle_row)
end
-- Final widget
self.dialog_frame = FrameContainer:new{
+34 -42
View File
@@ -12,7 +12,6 @@ local ScrollTextWidget = require("ui/widget/scrolltextwidget")
local Size = require("ui/size")
local TextBoxWidget = require("ui/widget/textboxwidget")
local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local dbg = require("dbg")
local util = require("util")
local _ = require("gettext")
@@ -61,12 +60,12 @@ local InputText = InputContainer:extend{
charlist = nil, -- table of individual chars from input string
charpos = nil, -- position of the cursor, where a new char would be inserted
top_line_num = nil, -- virtual_line_num of the text_widget (index of the displayed top line)
is_password_type = false, -- set to true if original text_type == "password"
is_text_editable = true, -- whether text is utf8 reversible and editing won't mess content
is_text_edited = false, -- whether text has been updated
for_measurement_only = nil, -- When the widget is a one-off used to compute text height
do_select = false, -- to start text selection
selection_start_pos = nil, -- selection start position
_password_toggle = nil,
}
-- These may be (internally) overloaded as needed, depending on Device capabilities.
@@ -390,17 +389,6 @@ function InputText:isTextEdited()
end
function InputText:init()
if Device:isTouchDevice() then
if self.text_type == "password" then
-- text_type changes from "password" to "text" when we toggle password
self.is_password_type = true
end
else
-- focus move does not work with textbox and show password checkbox
-- force show password for non-touch device
self.text_type = "text"
self.is_password_type = false
end
-- Beware other cases where implicit conversion to text may be done
-- at some point, but checkTextEditability() would say "not editable".
if self.input_type == "number" then
@@ -413,7 +401,9 @@ function InputText:init()
end
end
self.charlist = util.splitToChars(self.text)
self.is_password_type = self.text_type == "password"
self:initTextBox(self.text)
self:initPasswordToggle()
self:checkTextEditability()
if self.readonly ~= true then
self:initKeyboard()
@@ -427,8 +417,37 @@ function InputText:init()
end
end
function InputText:initPasswordToggle()
if not self.is_password_type or self.show_password_toggle == false then
self._password_toggle = nil
return
end
local toggle_width = self.width
if not toggle_width and self.parent and self.parent.getAddedWidgetAvailableWidth then
toggle_width = self.parent:getAddedWidgetAvailableWidth()
end
self._password_toggle = CheckButton:new{
text = _("Show password"),
parent = self.parent,
width = toggle_width,
checked = self.text_type ~= "password",
callback = function()
self.text_type = self._password_toggle.checked and "text" or "password"
self:setText(self:getText(), true)
end,
}
end
function InputText:getPasswordToggleWidget()
return self._password_toggle
end
function InputText:getFocusableWidgets()
return { self, self._password_toggle }
end
-- This will be called when we add or del chars, as we need to recreate
-- the text widget to have the new text splittted into possibly different
-- the text widget to have the new text split into possibly different
-- lines than before
function InputText:initTextBox(text, char_added)
if self.text_widget then
@@ -471,28 +490,6 @@ function InputText:initTextBox(text, char_added)
end
end
if self.is_password_type and self.show_password_toggle then
self._check_button = self._check_button or CheckButton:new{
text = _("Show password"),
parent = self,
width = self.width,
callback = function()
self.text_type = self._check_button.checked and "text" or "password"
self:setText(self:getText(), true)
end,
}
self._password_toggle = FrameContainer:new{
bordersize = 0,
padding = self.padding,
padding_top = 0,
padding_bottom = 0,
margin = self.margin + self.bordersize,
self._check_button,
}
else
self._password_toggle = nil
end
if not self.height then
-- If no height provided, measure the text widget height
-- we would start with, and use a ScrollTextWidget with that
@@ -573,16 +570,11 @@ function InputText:initTextBox(text, char_added)
color = self.focused and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
self.text_widget,
}
self._verticalgroup = VerticalGroup:new{
align = "left",
self._frame_textwidget,
self._password_toggle,
}
self._frame = FrameContainer:new{
bordersize = 0,
margin = 0,
padding = 0,
self._verticalgroup,
self._frame_textwidget,
}
self[1] = self._frame
self.dimen = self._frame:getSize()
+13 -11
View File
@@ -134,6 +134,7 @@ function MultiInputDialog:init()
end
self.input_fields = {}
local input_description = {}
local layout_insert_idx = 1
for i, field in ipairs(self.fields) do
local input_field_tmp = InputText:new{
text = field.text,
@@ -158,10 +159,6 @@ function MultiInputDialog:init()
enter_callback = self.enter_callback,
}
table.insert(self.input_fields, input_field_tmp)
--- @fixme: This is semi-broken when text_type is password, as we actually end up with the checkbox instead of the field,
-- and a "Press" on the checkbox will actually focus the password field and *not* check the box.
-- addWidget may have added stuff below us, so make sure we insert above that...
table.insert(self.layout, i, { input_field_tmp })
if field.description then
input_description[i] = FrameContainer:new{
padding = self.description_padding,
@@ -181,13 +178,18 @@ function MultiInputDialog:init()
input_description[i],
})
end
table.insert(VerticalGroupData, CenterContainer:new{
dimen = Geom:new{
w = self.title_bar:getSize().w,
h = input_field_tmp:getSize().h,
},
input_field_tmp,
})
local focus_widgets = input_field_tmp:getFocusableWidgets()
for _, focus_widget in ipairs(focus_widgets) do
table.insert(self.layout, layout_insert_idx, { focus_widget })
layout_insert_idx = layout_insert_idx + 1
table.insert(VerticalGroupData, CenterContainer:new{
dimen = Geom:new{
w = self.title_bar:getSize().w,
h = focus_widget:getSize().h,
},
focus_widget,
})
end
end
-- Add same vertical space after than before InputText