2017-04-29 08:38:09 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2017-08-14 19:42:15 +00:00
|
|
|
local CheckButton = require("ui/widget/checkbutton")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Device = require("device")
|
2022-03-04 20:20:00 +00:00
|
|
|
local FocusManager = require("ui/widget/focusmanager")
|
2016-01-31 22:56:05 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Font = require("ui/font")
|
2018-08-01 16:33:52 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2017-04-29 08:38:09 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2018-08-01 16:33:52 +00:00
|
|
|
local Notification = require("ui/widget/notification")
|
2013-10-18 20:38:07 +00:00
|
|
|
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
local Size = require("ui/size")
|
2013-10-18 20:38:07 +00:00
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2017-08-14 19:42:15 +00:00
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2021-10-29 10:59:03 +00:00
|
|
|
local dbg = require("dbg")
|
2016-04-21 14:13:10 +00:00
|
|
|
local util = require("util")
|
2017-08-14 19:42:15 +00:00
|
|
|
local _ = require("gettext")
|
|
|
|
local Screen = Device.screen
|
2017-04-29 08:38:09 +00:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local Keyboard -- Conditional instantiation
|
|
|
|
local FocusManagerInstance -- Delayed instantiation
|
2013-07-30 15:07:33 +00:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local InputText = InputContainer:extend{
|
2014-03-13 13:52:43 +00:00
|
|
|
text = "",
|
|
|
|
hint = "demo hint",
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
input_type = nil, -- "number" or anything else
|
|
|
|
text_type = nil, -- "password" or anything else
|
2017-08-14 19:42:15 +00:00
|
|
|
show_password_toggle = true,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
cursor_at_end = true, -- starts with cursor at end of text, ready for appending
|
|
|
|
scroll = false, -- whether to allow scrolling (will be set to true if no height provided)
|
|
|
|
focused = true,
|
|
|
|
parent = nil, -- parent dialog that will be set dirty
|
2018-08-06 19:16:30 +00:00
|
|
|
edit_callback = nil, -- called with true when text modified, false on init or text re-set
|
2023-09-01 20:51:41 +00:00
|
|
|
scroll_callback = nil, -- called with (low, high) when view is scrolled (c.f., ScrollTextWidget)
|
2018-08-10 16:05:09 +00:00
|
|
|
scroll_by_pan = false, -- allow scrolling by lines with Pan (needs scroll=true)
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
width = nil,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
height = nil, -- when nil, will be set to original text height (possibly
|
|
|
|
-- less if screen would be overflowed) and made scrollable to
|
|
|
|
-- not overflow if some text is appended and add new lines
|
2014-04-23 14:19:29 +00:00
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
face = Font:getFace("smallinfofont"),
|
|
|
|
padding = Size.padding.default,
|
|
|
|
margin = Size.margin.default,
|
|
|
|
bordersize = Size.border.inputtext,
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2019-12-06 21:55:35 +00:00
|
|
|
-- See TextBoxWidget for details about these options
|
|
|
|
alignment = "left",
|
|
|
|
justified = false,
|
|
|
|
lang = nil,
|
|
|
|
para_direction_rtl = nil,
|
|
|
|
auto_para_direction = false,
|
|
|
|
alignment_strict = false,
|
|
|
|
|
2023-09-01 20:51:41 +00:00
|
|
|
readonly = nil, -- will not support a Keyboard widget if true
|
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- for internal use
|
2023-09-01 20:51:41 +00:00
|
|
|
keyboard = nil, -- Keyboard widget (either VirtualKeyboard or PhysicalKeyboard)
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
text_widget = nil, -- Text Widget for cursor movement, possibly a ScrollTextWidget
|
|
|
|
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"
|
2018-08-01 16:33:52 +00:00
|
|
|
is_text_editable = true, -- whether text is utf8 reversible and editing won't mess content
|
|
|
|
is_text_edited = false, -- whether text has been updated
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
for_measurement_only = nil, -- When the widget is a one-off used to compute text height
|
2021-05-21 19:51:30 +00:00
|
|
|
do_select = false, -- to start text selection
|
|
|
|
selection_start_pos = nil, -- selection start position
|
2013-07-30 15:07:33 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 18:16:13 +00:00
|
|
|
-- These may be (internally) overloaded as needed, depending on Device capabilities.
|
|
|
|
function InputText:initEventListener() end
|
|
|
|
function InputText:onFocus() end
|
|
|
|
function InputText:onUnfocus() end
|
|
|
|
|
2023-09-01 20:51:41 +00:00
|
|
|
-- Resync our position state with our text widget's actual state
|
|
|
|
function InputText:resyncPos()
|
|
|
|
self.charpos, self.top_line_num = self.text_widget:getCharPos()
|
|
|
|
end
|
|
|
|
|
2022-10-29 20:46:35 +00:00
|
|
|
local function initTouchEvents()
|
2019-04-08 21:05:08 +00:00
|
|
|
if Device:isTouchDevice() then
|
2018-03-30 10:46:36 +00:00
|
|
|
function InputText:initEventListener()
|
|
|
|
self.ges_events = {
|
|
|
|
TapTextBox = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
2021-06-29 09:01:12 +00:00
|
|
|
range = function() return self.dimen end
|
2018-03-30 10:46:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
HoldTextBox = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
2021-06-29 09:01:12 +00:00
|
|
|
range = function() return self.dimen end
|
2018-03-30 10:46:36 +00:00
|
|
|
}
|
|
|
|
},
|
2021-08-17 13:24:44 +00:00
|
|
|
HoldReleaseTextBox = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold_release",
|
|
|
|
range = function() return self.dimen end
|
|
|
|
}
|
|
|
|
},
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
SwipeTextBox = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
2021-06-29 09:01:12 +00:00
|
|
|
range = function() return self.dimen end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
-- These are just to stop propagation of the event to
|
|
|
|
-- parents in case there's a MovableContainer among them
|
|
|
|
-- Commented for now, as this needs work
|
|
|
|
-- HoldPanTextBox = {
|
|
|
|
-- GestureRange:new{ ges = "hold_pan", range = self.dimen }
|
|
|
|
-- },
|
|
|
|
-- PanTextBox = {
|
|
|
|
-- GestureRange:new{ ges = "pan", range = self.dimen }
|
|
|
|
-- },
|
|
|
|
-- PanReleaseTextBox = {
|
|
|
|
-- GestureRange:new{ ges = "pan_release", range = self.dimen }
|
|
|
|
-- },
|
|
|
|
-- TouchTextBox = {
|
|
|
|
-- GestureRange:new{ ges = "touch", range = self.dimen }
|
|
|
|
-- },
|
2018-03-30 10:46:36 +00:00
|
|
|
}
|
|
|
|
end
|
2016-01-31 22:56:05 +00:00
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- For MovableContainer to work fully, some of these should
|
|
|
|
-- do more check before disabling the event or not
|
|
|
|
-- Commented for now, as this needs work
|
|
|
|
-- local function _disableEvent() return true end
|
|
|
|
-- InputText.onHoldPanTextBox = _disableEvent
|
|
|
|
-- InputText.onHoldReleaseTextBox = _disableEvent
|
|
|
|
-- InputText.onPanTextBox = _disableEvent
|
|
|
|
-- InputText.onPanReleaseTextBox = _disableEvent
|
|
|
|
-- InputText.onTouchTextBox = _disableEvent
|
|
|
|
|
2018-03-30 10:46:36 +00:00
|
|
|
function InputText:onTapTextBox(arg, ges)
|
|
|
|
if self.parent.onSwitchFocus then
|
|
|
|
self.parent:onSwitchFocus(self)
|
2021-05-31 20:19:24 +00:00
|
|
|
else
|
2023-09-01 20:51:41 +00:00
|
|
|
if self.keyboard then
|
|
|
|
self.keyboard:showKeyboard()
|
2021-05-31 20:19:24 +00:00
|
|
|
end
|
2018-03-30 10:46:36 +00:00
|
|
|
end
|
2022-10-01 23:58:36 +00:00
|
|
|
-- zh keyboard with candidates shown here has _frame_textwidget.dimen = nil.
|
|
|
|
-- Check to avoid crash.
|
|
|
|
if #self.charlist > 0 and self._frame_textwidget.dimen then -- Avoid cursor moving within a hint.
|
2021-05-19 17:09:22 +00:00
|
|
|
local textwidget_offset = self.margin + self.bordersize + self.padding
|
|
|
|
local x = ges.pos.x - self._frame_textwidget.dimen.x - textwidget_offset
|
|
|
|
local y = ges.pos.y - self._frame_textwidget.dimen.y - textwidget_offset
|
|
|
|
self.text_widget:moveCursorToXY(x, y, true) -- restrict_to_view=true
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2021-05-19 17:09:22 +00:00
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
return true
|
2016-06-25 17:27:23 +00:00
|
|
|
end
|
2018-03-30 10:46:36 +00:00
|
|
|
|
|
|
|
function InputText:onHoldTextBox(arg, ges)
|
|
|
|
if self.parent.onSwitchFocus then
|
|
|
|
self.parent:onSwitchFocus(self)
|
|
|
|
end
|
2021-05-21 19:51:30 +00:00
|
|
|
-- clipboard dialog
|
2021-08-17 13:24:44 +00:00
|
|
|
self._hold_handled = nil
|
2021-05-21 19:51:30 +00:00
|
|
|
if Device:hasClipboard() then
|
|
|
|
if self.do_select then -- select mode on
|
|
|
|
if self.selection_start_pos then -- select end
|
|
|
|
local selection_end_pos = self.charpos - 1
|
|
|
|
if self.selection_start_pos > selection_end_pos then
|
|
|
|
self.selection_start_pos, selection_end_pos = selection_end_pos + 1, self.selection_start_pos - 1
|
|
|
|
end
|
|
|
|
local txt = table.concat(self.charlist, "", self.selection_start_pos, selection_end_pos)
|
|
|
|
Device.input.setClipboardText(txt)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = _("Selection copied to clipboard."),
|
|
|
|
})
|
|
|
|
self.selection_start_pos = nil
|
|
|
|
self.do_select = false
|
|
|
|
return true
|
|
|
|
else -- select start
|
|
|
|
self.selection_start_pos = self.charpos
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = _("Set cursor to end of selection, then hold."),
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2021-06-29 09:01:12 +00:00
|
|
|
local clipboard_value = Device.input.getClipboardText()
|
2023-08-04 03:57:13 +00:00
|
|
|
local is_clipboard_empty = clipboard_value == ""
|
2021-06-29 09:01:12 +00:00
|
|
|
local clipboard_dialog
|
|
|
|
clipboard_dialog = require("ui/widget/textviewer"):new{
|
2021-08-17 13:24:44 +00:00
|
|
|
title = _("Clipboard"),
|
|
|
|
text = is_clipboard_empty and _("(empty)") or clipboard_value,
|
|
|
|
fgcolor = is_clipboard_empty and Blitbuffer.COLOR_DARK_GRAY or Blitbuffer.COLOR_BLACK,
|
2021-09-25 08:51:58 +00:00
|
|
|
width = math.floor(math.min(Screen:getWidth(), Screen:getHeight()) * 0.8),
|
|
|
|
height = math.floor(math.max(Screen:getWidth(), Screen:getHeight()) * 0.4),
|
2021-06-29 09:01:12 +00:00
|
|
|
justified = false,
|
2022-09-13 21:09:49 +00:00
|
|
|
modal = true,
|
2021-05-21 19:51:30 +00:00
|
|
|
stop_events_propagation = true,
|
2021-06-29 09:01:12 +00:00
|
|
|
buttons_table = {
|
2021-05-21 19:51:30 +00:00
|
|
|
{
|
|
|
|
{
|
2021-06-29 09:01:12 +00:00
|
|
|
text = _("Copy all"),
|
2021-05-21 19:51:30 +00:00
|
|
|
callback = function()
|
2021-06-29 09:01:12 +00:00
|
|
|
UIManager:close(clipboard_dialog)
|
2021-05-21 19:51:30 +00:00
|
|
|
Device.input.setClipboardText(table.concat(self.charlist))
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = _("All text copied to clipboard."),
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:01:12 +00:00
|
|
|
text = _("Copy line"),
|
2021-05-21 19:51:30 +00:00
|
|
|
callback = function()
|
2021-06-29 09:01:12 +00:00
|
|
|
UIManager:close(clipboard_dialog)
|
2021-05-21 19:51:30 +00:00
|
|
|
local txt = table.concat(self.charlist, "", self:getStringPos({"\n", "\r"}, {"\n", "\r"}))
|
|
|
|
Device.input.setClipboardText(txt)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = _("Line copied to clipboard."),
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
2021-06-29 09:01:12 +00:00
|
|
|
text = _("Copy word"),
|
2021-05-21 19:51:30 +00:00
|
|
|
callback = function()
|
2021-06-29 09:01:12 +00:00
|
|
|
UIManager:close(clipboard_dialog)
|
2021-05-21 19:51:30 +00:00
|
|
|
local txt = table.concat(self.charlist, "", self:getStringPos({"\n", "\r", " "}, {"\n", "\r", " "}))
|
|
|
|
Device.input.setClipboardText(txt)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = _("Word copied to clipboard."),
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
|
|
|
callback = function()
|
2021-06-29 09:01:12 +00:00
|
|
|
UIManager:close(clipboard_dialog)
|
2021-05-21 19:51:30 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Select"),
|
|
|
|
callback = function()
|
2021-06-29 09:01:12 +00:00
|
|
|
UIManager:close(clipboard_dialog)
|
2021-05-21 19:51:30 +00:00
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = _("Set cursor to start of selection, then hold."),
|
|
|
|
})
|
|
|
|
self.do_select = true
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Paste"),
|
2022-01-24 11:36:20 +00:00
|
|
|
enabled = not is_clipboard_empty,
|
2021-05-21 19:51:30 +00:00
|
|
|
callback = function()
|
2022-01-24 11:36:20 +00:00
|
|
|
UIManager:close(clipboard_dialog)
|
|
|
|
self:addChars(clipboard_value)
|
2021-05-21 19:51:30 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-06-29 09:01:12 +00:00
|
|
|
UIManager:show(clipboard_dialog)
|
2018-03-30 10:46:36 +00:00
|
|
|
end
|
2021-08-17 13:24:44 +00:00
|
|
|
self._hold_handled = true
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
return true
|
2016-01-31 22:56:05 +00:00
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
|
2021-08-17 13:24:44 +00:00
|
|
|
function InputText:onHoldReleaseTextBox(arg, ges)
|
|
|
|
if self._hold_handled then
|
|
|
|
self._hold_handled = nil
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
function InputText:onSwipeTextBox(arg, ges)
|
|
|
|
-- Allow refreshing the widget (actually, the screen) with the classic
|
|
|
|
-- Diagonal Swipe, as we're only using the quick "ui" mode while editing
|
|
|
|
if ges.direction == "northeast" or ges.direction == "northwest"
|
|
|
|
or ges.direction == "southeast" or ges.direction == "southwest" then
|
|
|
|
if self.refresh_callback then self.refresh_callback() end
|
|
|
|
-- Trigger a full-screen HQ flashing refresh so
|
|
|
|
-- the keyboard can also be fully redrawn
|
|
|
|
UIManager:setDirty(nil, "full")
|
|
|
|
end
|
|
|
|
-- Let it propagate in any case (a long diagonal swipe may also be
|
|
|
|
-- used for taking a screenshot)
|
|
|
|
return false
|
|
|
|
end
|
2016-01-31 22:56:05 +00:00
|
|
|
end
|
2022-10-29 20:46:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function initDPadEvents()
|
2019-04-08 21:05:08 +00:00
|
|
|
if Device:hasDPad() then
|
2018-03-30 10:46:36 +00:00
|
|
|
function InputText:onFocus()
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
-- Event called by the focusmanager
|
2022-03-04 20:20:00 +00:00
|
|
|
if self.parent.onSwitchFocus then
|
|
|
|
self.parent:onSwitchFocus(self)
|
|
|
|
else
|
|
|
|
self:onShowKeyboard()
|
|
|
|
end
|
2018-03-30 10:46:36 +00:00
|
|
|
self:focus()
|
|
|
|
return true
|
2018-02-17 05:31:32 +00:00
|
|
|
end
|
2018-03-30 10:46:36 +00:00
|
|
|
|
|
|
|
function InputText:onUnfocus()
|
A few graphics fixes after #4541 (#4554)
* Various FocusManager related tweaks to limit its usage to devices with a DPad, and prevent initial button highlights in Dialogs on devices where it makes no sense (i.e., those without a DPad. And even on DPad devices, I'm not even sure how we'd go about making one of those pop up anyway, because no Touch ;)!).
* One mysterious fix to text-only Buttons so that the flash_ui highlight always works, and always honors `FrameContainer`'s pill shape. (Before that, an unhighlight on a text button with a callback that didn't repaint anything [say, the find first/find last buttons in the Reader's search bar when you're already on the first/last match] would do a square black highlight, and a white pill-shaped unhighlight (leaving the black corners visible)).
The workaround makes *absolutely* no sense to me (as `self[1] -> self.frame`, AFAICT), but it works, and ensures all highlights/unhighlights are pill-shaped, so at least we're not doing maths for rounded corners for nothing ;).
2019-02-07 23:56:32 +00:00
|
|
|
-- Event called by the focusmanager
|
2018-03-30 10:46:36 +00:00
|
|
|
self:unfocus()
|
|
|
|
return true
|
2018-02-17 05:31:32 +00:00
|
|
|
end
|
|
|
|
end
|
2016-01-31 22:56:05 +00:00
|
|
|
end
|
|
|
|
|
2022-10-29 20:46:35 +00:00
|
|
|
-- only use PhysicalKeyboard if the device does not support touch input
|
|
|
|
function InputText.initInputEvents()
|
|
|
|
FocusManagerInstance = nil
|
|
|
|
|
|
|
|
if Device:isTouchDevice() or Device:hasDPad() then
|
|
|
|
Keyboard = require("ui/widget/virtualkeyboard")
|
|
|
|
initTouchEvents()
|
|
|
|
initDPadEvents()
|
|
|
|
else
|
|
|
|
Keyboard = require("ui/widget/physicalkeyboard")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
InputText.initInputEvents()
|
|
|
|
|
2018-08-01 16:33:52 +00:00
|
|
|
function InputText:checkTextEditability()
|
|
|
|
-- The split of the 'text' string to a table of utf8 chars may not be
|
|
|
|
-- reversible to the same string, if 'text' comes from a binary file
|
|
|
|
-- (it looks like it does not necessarily need to be proper UTF8 to
|
|
|
|
-- be reversible, some text with latin1 chars is reversible).
|
|
|
|
-- As checking that may be costly, we do that only in init(), setText(),
|
|
|
|
-- and clear().
|
|
|
|
-- When not reversible, we prevent adding and deleting chars to not
|
|
|
|
-- corrupt the original self.text.
|
|
|
|
self.is_text_editable = true
|
|
|
|
if self.text then
|
|
|
|
-- We check that the text obtained from the UTF8 split done
|
|
|
|
-- in :initTextBox(), when concatenated back to a string, matches
|
|
|
|
-- the original text. (If this turns out too expensive, we could
|
|
|
|
-- just compare their lengths)
|
|
|
|
self.is_text_editable = table.concat(self.charlist, "") == self.text
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:isTextEditable(show_warning)
|
|
|
|
if show_warning and not self.is_text_editable then
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = _("Text may be binary content, and is not editable"),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
return self.is_text_editable
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:isTextEdited()
|
|
|
|
return self.is_text_edited
|
|
|
|
end
|
|
|
|
|
2016-01-31 22:56:05 +00:00
|
|
|
function InputText:init()
|
2022-05-06 08:44:25 +00:00
|
|
|
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
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
-- Beware other cases where implicit conversion to text may be done
|
|
|
|
-- at some point, but checkTextEditability() would say "not editable".
|
2022-07-26 10:04:40 +00:00
|
|
|
if self.input_type == "number" then
|
|
|
|
if type(self.text) == "number" then
|
|
|
|
-- checkTextEditability() fails if self.text stays not a string
|
|
|
|
self.text = tostring(self.text)
|
|
|
|
end
|
|
|
|
if type(self.hint) == "number" then
|
|
|
|
self.hint = tostring(self.hint)
|
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
end
|
2016-01-31 22:56:05 +00:00
|
|
|
self:initTextBox(self.text)
|
2018-08-01 16:33:52 +00:00
|
|
|
self:checkTextEditability()
|
2017-12-17 17:27:24 +00:00
|
|
|
if self.readonly ~= true then
|
|
|
|
self:initKeyboard()
|
|
|
|
self:initEventListener()
|
|
|
|
end
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- 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
|
|
|
|
-- lines than before
|
|
|
|
function InputText:initTextBox(text, char_added)
|
2019-12-05 07:36:01 +00:00
|
|
|
if self.text_widget then
|
2022-03-14 18:56:18 +00:00
|
|
|
self.text_widget:free(true)
|
2019-12-05 07:36:01 +00:00
|
|
|
end
|
2014-09-10 07:30:59 +00:00
|
|
|
self.text = text
|
2016-06-26 00:53:08 +00:00
|
|
|
local fgcolor
|
|
|
|
local show_charlist
|
|
|
|
local show_text = text
|
|
|
|
if show_text == "" or show_text == nil then
|
|
|
|
-- no preset value, use hint text if set
|
2016-06-25 17:27:23 +00:00
|
|
|
show_text = self.hint
|
2019-03-14 19:58:45 +00:00
|
|
|
fgcolor = Blitbuffer.COLOR_DARK_GRAY
|
2016-06-26 00:53:08 +00:00
|
|
|
self.charlist = {}
|
|
|
|
self.charpos = 1
|
|
|
|
else
|
|
|
|
fgcolor = Blitbuffer.COLOR_BLACK
|
|
|
|
if self.text_type == "password" then
|
|
|
|
show_text = self.text:gsub(
|
|
|
|
"(.-).", function() return "*" end)
|
2017-03-30 22:32:01 +00:00
|
|
|
if char_added then
|
|
|
|
show_text = show_text:gsub(
|
|
|
|
"(.)$", function() return self.text:sub(-1) end)
|
|
|
|
end
|
2016-06-26 00:53:08 +00:00
|
|
|
end
|
|
|
|
self.charlist = util.splitToChars(text)
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- keep previous cursor position if charpos not nil
|
2016-06-26 00:53:08 +00:00
|
|
|
if self.charpos == nil then
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
if self.cursor_at_end then
|
|
|
|
self.charpos = #self.charlist + 1
|
|
|
|
else
|
|
|
|
self.charpos = 1
|
|
|
|
end
|
2016-06-26 00:53:08 +00:00
|
|
|
end
|
2014-04-23 14:19:29 +00:00
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
if self.is_password_type and self.show_password_toggle then
|
2017-08-14 19:42:15 +00:00
|
|
|
self._check_button = self._check_button or CheckButton:new{
|
|
|
|
text = _("Show password"),
|
2021-08-22 07:10:35 +00:00
|
|
|
parent = self,
|
2021-12-07 11:35:44 +00:00
|
|
|
width = self.width,
|
2017-08-14 19:42:15 +00:00
|
|
|
callback = function()
|
2021-08-27 19:21:14 +00:00
|
|
|
self.text_type = self._check_button.checked and "text" or "password"
|
2018-08-01 16:33:52 +00:00
|
|
|
self:setText(self:getText(), true)
|
2017-08-14 19:42:15 +00:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
self._password_toggle = FrameContainer:new{
|
|
|
|
bordersize = 0,
|
|
|
|
padding = self.padding,
|
2022-01-20 10:36:35 +00:00
|
|
|
padding_top = 0,
|
|
|
|
padding_bottom = 0,
|
2017-08-14 19:42:15 +00:00
|
|
|
margin = self.margin,
|
|
|
|
self._check_button,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
self._password_toggle = nil
|
|
|
|
end
|
2016-06-26 00:53:08 +00:00
|
|
|
show_charlist = util.splitToChars(show_text)
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
|
|
|
|
if not self.height then
|
|
|
|
-- If no height provided, measure the text widget height
|
|
|
|
-- we would start with, and use a ScrollTextWidget with that
|
|
|
|
-- height, so widget does not overflow container if we extend
|
2018-08-01 16:33:52 +00:00
|
|
|
-- the text and increase the number of lines.
|
|
|
|
local text_width = self.width
|
|
|
|
if text_width then
|
|
|
|
-- Account for the scrollbar that will be used
|
|
|
|
local scroll_bar_width = ScrollTextWidget.scroll_bar_width + ScrollTextWidget.text_scroll_span
|
|
|
|
text_width = text_width - scroll_bar_width
|
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
local text_widget = TextBoxWidget:new{
|
|
|
|
text = show_text,
|
|
|
|
charlist = show_charlist,
|
|
|
|
face = self.face,
|
2018-08-01 16:33:52 +00:00
|
|
|
width = text_width,
|
2019-12-06 21:55:35 +00:00
|
|
|
lang = self.lang, -- these might influence height
|
|
|
|
para_direction_rtl = self.para_direction_rtl,
|
|
|
|
auto_para_direction = self.auto_para_direction,
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
for_measurement_only = true, -- flag it as a dummy, so it won't trigger any bogus repaint/refresh...
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
}
|
|
|
|
self.height = text_widget:getTextHeight()
|
|
|
|
self.scroll = true
|
2022-03-14 18:56:18 +00:00
|
|
|
text_widget:free(true)
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.scroll then
|
2016-04-21 14:13:10 +00:00
|
|
|
self.text_widget = ScrollTextWidget:new{
|
2014-04-23 14:19:29 +00:00
|
|
|
text = show_text,
|
2016-06-26 00:53:08 +00:00
|
|
|
charlist = show_charlist,
|
2016-05-15 09:18:38 +00:00
|
|
|
charpos = self.charpos,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
top_line_num = self.top_line_num,
|
2016-06-25 17:27:23 +00:00
|
|
|
editable = self.focused,
|
2014-03-13 13:52:43 +00:00
|
|
|
face = self.face,
|
|
|
|
fgcolor = fgcolor,
|
2019-12-06 21:55:35 +00:00
|
|
|
alignment = self.alignment,
|
|
|
|
justified = self.justified,
|
|
|
|
lang = self.lang,
|
|
|
|
para_direction_rtl = self.para_direction_rtl,
|
|
|
|
auto_para_direction = self.auto_para_direction,
|
|
|
|
alignment_strict = self.alignment_strict,
|
2014-03-13 13:52:43 +00:00
|
|
|
width = self.width,
|
|
|
|
height = self.height,
|
2017-04-02 06:50:24 +00:00
|
|
|
dialog = self.parent,
|
2018-08-06 19:16:30 +00:00
|
|
|
scroll_callback = self.scroll_callback,
|
2018-08-10 16:05:09 +00:00
|
|
|
scroll_by_pan = self.scroll_by_pan,
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
for_measurement_only = self.for_measurement_only,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
else
|
2016-04-21 14:13:10 +00:00
|
|
|
self.text_widget = TextBoxWidget:new{
|
2014-04-23 14:19:29 +00:00
|
|
|
text = show_text,
|
2016-06-26 00:53:08 +00:00
|
|
|
charlist = show_charlist,
|
2016-05-15 09:18:38 +00:00
|
|
|
charpos = self.charpos,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
top_line_num = self.top_line_num,
|
2016-06-25 17:27:23 +00:00
|
|
|
editable = self.focused,
|
2014-03-13 13:52:43 +00:00
|
|
|
face = self.face,
|
|
|
|
fgcolor = fgcolor,
|
2019-12-06 21:55:35 +00:00
|
|
|
alignment = self.alignment,
|
|
|
|
justified = self.justified,
|
|
|
|
lang = self.lang,
|
|
|
|
para_direction_rtl = self.para_direction_rtl,
|
|
|
|
auto_para_direction = self.auto_para_direction,
|
|
|
|
alignment_strict = self.alignment_strict,
|
2014-03-13 13:52:43 +00:00
|
|
|
width = self.width,
|
|
|
|
height = self.height,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
dialog = self.parent,
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
for_measurement_only = self.for_measurement_only,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- Get back possibly modified charpos and virtual_line_num
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
|
2017-08-14 19:42:15 +00:00
|
|
|
self._frame_textwidget = FrameContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
bordersize = self.bordersize,
|
|
|
|
padding = self.padding,
|
|
|
|
margin = self.margin,
|
2019-03-14 19:58:45 +00:00
|
|
|
color = self.focused and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
2016-04-21 14:13:10 +00:00
|
|
|
self.text_widget,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2017-08-14 19:42:15 +00:00
|
|
|
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[1] = self._frame
|
|
|
|
self.dimen = self._frame:getSize()
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @fixme self.parent is not always in the widget stack (BookStatusWidget)
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
-- Don't even try to refresh dummy widgets used for text height computations...
|
|
|
|
if not self.for_measurement_only then
|
|
|
|
UIManager:setDirty(self.parent, function()
|
|
|
|
return "ui", self.dimen
|
|
|
|
end)
|
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
if self.edit_callback then
|
|
|
|
self.edit_callback(self.is_text_edited)
|
|
|
|
end
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
2022-03-14 18:56:18 +00:00
|
|
|
dbg:guard(InputText, "initTextBox",
|
|
|
|
function(self, text, char_added)
|
|
|
|
assert(type(text) == "string",
|
|
|
|
"Wrong text type (expected string)")
|
|
|
|
end)
|
2013-07-30 15:07:33 +00:00
|
|
|
|
|
|
|
function InputText:initKeyboard()
|
2019-11-18 16:16:06 +00:00
|
|
|
local keyboard_layer = 2
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.input_type == "number" then
|
2019-11-18 16:16:06 +00:00
|
|
|
keyboard_layer = 4
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2022-10-24 08:46:39 +00:00
|
|
|
self.key_events = {}
|
2016-01-31 22:56:05 +00:00
|
|
|
self.keyboard = Keyboard:new{
|
2019-11-18 16:16:06 +00:00
|
|
|
keyboard_layer = keyboard_layer,
|
2014-03-13 13:52:43 +00:00
|
|
|
inputbox = self,
|
|
|
|
}
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
2014-04-23 14:19:29 +00:00
|
|
|
function InputText:unfocus()
|
|
|
|
self.focused = false
|
2016-06-25 17:27:23 +00:00
|
|
|
self.text_widget:unfocus()
|
2019-03-14 19:58:45 +00:00
|
|
|
self._frame_textwidget.color = Blitbuffer.COLOR_DARK_GRAY
|
2014-04-23 14:19:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:focus()
|
|
|
|
self.focused = true
|
2016-06-25 17:27:23 +00:00
|
|
|
self.text_widget:focus()
|
2018-03-30 10:46:36 +00:00
|
|
|
self._frame_textwidget.color = Blitbuffer.COLOR_BLACK
|
2014-04-23 14:19:29 +00:00
|
|
|
end
|
|
|
|
|
2020-12-30 21:26:40 +00:00
|
|
|
-- Handle real keypresses from a physical keyboard, even if the virtual keyboard
|
|
|
|
-- is shown. Mostly likely to be in the emulator, but could be Android + BT
|
|
|
|
-- keyboard, or a "coder's keyboard" Android input method.
|
|
|
|
function InputText:onKeyPress(key)
|
2022-03-04 20:20:00 +00:00
|
|
|
-- only handle key on focused status, otherwise there are more than one InputText
|
|
|
|
-- the first one always handle key pressed
|
|
|
|
if not self.focused then
|
|
|
|
return false
|
|
|
|
end
|
2022-01-23 17:40:35 +00:00
|
|
|
local handled = true
|
|
|
|
|
|
|
|
if not key["Ctrl"] and not key["Shift"] and not key["Alt"] then
|
|
|
|
if key["Backspace"] then
|
|
|
|
self:delChar()
|
|
|
|
elseif key["Del"] then
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
self:delNextChar()
|
2022-01-23 17:40:35 +00:00
|
|
|
elseif key["Left"] then
|
|
|
|
self:leftChar()
|
|
|
|
elseif key["Right"] then
|
|
|
|
self:rightChar()
|
|
|
|
elseif key["Up"] then
|
|
|
|
self:upLine()
|
|
|
|
elseif key["Down"] then
|
|
|
|
self:downLine()
|
|
|
|
elseif key["End"] then
|
|
|
|
self:goToEnd()
|
|
|
|
elseif key["Home"] then
|
|
|
|
self:goToHome()
|
|
|
|
elseif key["Press"] then
|
|
|
|
self:addChars("\n")
|
|
|
|
elseif key["Tab"] then
|
|
|
|
self:addChars(" ")
|
2022-03-04 20:20:00 +00:00
|
|
|
elseif key["Back"] then
|
|
|
|
if self.focused then
|
|
|
|
self:unfocus()
|
|
|
|
end
|
2022-01-23 17:40:35 +00:00
|
|
|
else
|
|
|
|
handled = false
|
|
|
|
end
|
2020-12-30 21:26:40 +00:00
|
|
|
elseif key["Ctrl"] and not key["Shift"] and not key["Alt"] then
|
|
|
|
if key["U"] then
|
|
|
|
self:delToStartOfLine()
|
|
|
|
elseif key["H"] then
|
|
|
|
self:delChar()
|
2022-01-23 17:40:35 +00:00
|
|
|
else
|
|
|
|
handled = false
|
2020-12-30 21:26:40 +00:00
|
|
|
end
|
|
|
|
else
|
2022-01-23 17:40:35 +00:00
|
|
|
handled = false
|
2020-12-30 21:26:40 +00:00
|
|
|
end
|
2022-03-04 20:20:00 +00:00
|
|
|
if not handled and Device:hasDPad() then
|
|
|
|
-- FocusManager may turn on alternative key maps.
|
|
|
|
-- These key map maybe single text keys.
|
|
|
|
-- It will cause unexpected focus move instead of enter text to InputText
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
if not FocusManagerInstance then
|
|
|
|
FocusManagerInstance = FocusManager:new{}
|
|
|
|
end
|
2022-03-04 20:20:00 +00:00
|
|
|
local is_alternative_key = FocusManagerInstance:isAlternativeKey(key)
|
|
|
|
if not is_alternative_key and Device:isSDL() then
|
|
|
|
-- SDL already insert char via TextInput event
|
|
|
|
-- Stop event propagate to FocusManager
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
-- if it is single text char, insert it
|
|
|
|
local key_code = key.key -- is in upper case
|
|
|
|
if not Device.isSDL() and #key_code == 1 then
|
|
|
|
if not key["Shift"] then
|
|
|
|
key_code = string.lower(key_code)
|
|
|
|
end
|
|
|
|
for modifier, flag in pairs(key.modifiers) do
|
|
|
|
if modifier ~= "Shift" and flag then -- Other modifier: not a single char insert
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:addChars(key_code)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
if is_alternative_key then
|
|
|
|
return true -- Stop event propagate to FocusManager to void focus move
|
|
|
|
end
|
|
|
|
end
|
2022-01-23 17:40:35 +00:00
|
|
|
return handled
|
2020-12-30 21:26:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Handle text coming directly as text from the Device layer (eg. soft keyboard
|
|
|
|
-- or via SDL's keyboard mapping).
|
|
|
|
function InputText:onTextInput(text)
|
2022-03-04 20:20:00 +00:00
|
|
|
-- for more than one InputText, let the focused one add chars
|
|
|
|
if self.focused then
|
|
|
|
self:addChars(text)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2020-12-30 21:26:40 +00:00
|
|
|
end
|
2022-03-14 18:56:18 +00:00
|
|
|
dbg:guard(InputText, "onTextInput",
|
|
|
|
function(self, text)
|
|
|
|
assert(type(text) == "string",
|
|
|
|
"Wrong text type (expected string)")
|
|
|
|
end)
|
2020-12-30 21:26:40 +00:00
|
|
|
|
2019-05-08 08:13:44 +00:00
|
|
|
function InputText:onShowKeyboard(ignore_first_hold_release)
|
2023-09-01 20:51:41 +00:00
|
|
|
if self.keyboard then
|
|
|
|
self.keyboard:showKeyboard(ignore_first_hold_release)
|
2023-08-13 04:38:45 +00:00
|
|
|
end
|
2018-03-30 10:46:36 +00:00
|
|
|
return true
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:onCloseKeyboard()
|
2023-09-01 20:51:41 +00:00
|
|
|
if self.keyboard then
|
|
|
|
self.keyboard:hideKeyboard()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:isKeyboardVisible()
|
|
|
|
if self.keyboard then
|
|
|
|
return self.keyboard:isVisible()
|
|
|
|
end
|
|
|
|
end
|
2023-08-01 21:53:10 +00:00
|
|
|
|
2023-09-01 20:51:41 +00:00
|
|
|
function InputText:lockKeyboard(toggle)
|
|
|
|
if self.keyboard then
|
|
|
|
return self.keyboard:lockVisibility(toggle)
|
2023-08-01 21:53:10 +00:00
|
|
|
end
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
2019-11-25 13:31:54 +00:00
|
|
|
function InputText:onCloseWidget()
|
|
|
|
if self.keyboard then
|
|
|
|
self.keyboard:free()
|
|
|
|
end
|
|
|
|
self:free()
|
|
|
|
end
|
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
function InputText:getTextHeight()
|
|
|
|
return self.text_widget:getTextHeight()
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:getLineHeight()
|
|
|
|
return self.text_widget:getLineHeight()
|
|
|
|
end
|
|
|
|
|
2013-07-30 15:07:33 +00:00
|
|
|
function InputText:getKeyboardDimen()
|
2018-08-01 16:33:52 +00:00
|
|
|
if self.readonly then
|
|
|
|
return Geom:new{w = 0, h = 0}
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.keyboard.dimen
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
2021-05-16 10:45:36 +00:00
|
|
|
-- calculate current and last (original) line numbers
|
|
|
|
function InputText:getLineNums()
|
|
|
|
local cur_line_num, last_line_num = 1, 1
|
|
|
|
for i = 1, #self.charlist do
|
|
|
|
if self.text_widget.charlist[i] == "\n" then
|
|
|
|
if i < self.charpos then
|
|
|
|
cur_line_num = cur_line_num + 1
|
|
|
|
end
|
|
|
|
last_line_num = last_line_num + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return cur_line_num, last_line_num
|
|
|
|
end
|
|
|
|
|
|
|
|
-- calculate charpos for the beginning of (original) line
|
|
|
|
function InputText:getLineCharPos(line_num)
|
|
|
|
local char_pos = 1
|
|
|
|
if line_num > 1 then
|
|
|
|
local j = 1
|
|
|
|
for i = 1, #self.charlist do
|
|
|
|
if self.charlist[i] == "\n" then
|
|
|
|
j = j + 1
|
|
|
|
if j == line_num then
|
|
|
|
char_pos = i + 1
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return char_pos
|
|
|
|
end
|
|
|
|
|
2021-05-21 19:51:30 +00:00
|
|
|
-- Get start and end positions of the substring
|
|
|
|
-- delimited with the delimiters and containing char_pos.
|
|
|
|
-- If char_pos not set, current charpos assumed.
|
|
|
|
function InputText:getStringPos(left_delimiter, right_delimiter, char_pos)
|
|
|
|
char_pos = char_pos and char_pos or self.charpos
|
|
|
|
local start_pos, end_pos = 1, #self.charlist
|
|
|
|
local done = false
|
|
|
|
if char_pos > 1 then
|
|
|
|
for i = char_pos, 2, -1 do
|
|
|
|
for j = 1, #left_delimiter do
|
|
|
|
if self.charlist[i-1] == left_delimiter[j] then
|
|
|
|
start_pos = i
|
|
|
|
done = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if done then break end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
done = false
|
|
|
|
if char_pos < #self.charlist then
|
|
|
|
for i = char_pos, #self.charlist do
|
|
|
|
for j = 1, #right_delimiter do
|
|
|
|
if self.charlist[i] == right_delimiter[j] then
|
|
|
|
end_pos = i - 1
|
|
|
|
done = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if done then break end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return start_pos, end_pos
|
|
|
|
end
|
|
|
|
|
2021-11-06 05:09:21 +00:00
|
|
|
--- Return the character at the given offset. If is_absolute is truthy then the
|
|
|
|
-- offset is the absolute position, otherwise the offset is added to the current
|
|
|
|
-- cursor position (negative offsets are allowed).
|
|
|
|
function InputText:getChar(offset, is_absolute)
|
|
|
|
local idx
|
|
|
|
if is_absolute then
|
|
|
|
idx = offset
|
|
|
|
else
|
|
|
|
idx = self.charpos + offset
|
|
|
|
end
|
|
|
|
if idx < 1 or idx > #self.charlist then return end
|
|
|
|
return self.charlist[idx]
|
|
|
|
end
|
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
function InputText:addChars(chars)
|
2018-08-06 19:16:30 +00:00
|
|
|
if not chars then
|
|
|
|
-- VirtualKeyboard:addChar(key) gave us 'nil' once (?!)
|
|
|
|
-- which would crash table.concat()
|
|
|
|
return
|
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
if self.enter_callback and chars == "\n" then
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:scheduleIn(0.3, function() self.enter_callback() end)
|
|
|
|
return
|
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
if self.readonly or not self:isTextEditable(true) then
|
2018-08-01 16:33:52 +00:00
|
|
|
return
|
|
|
|
end
|
2019-06-01 14:48:35 +00:00
|
|
|
|
2018-08-01 16:33:52 +00:00
|
|
|
self.is_text_edited = true
|
2019-06-01 14:48:35 +00:00
|
|
|
if #self.charlist == 0 then -- widget text is empty or a hint text is displayed
|
|
|
|
self.charpos = 1 -- move cursor to the first position
|
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
table.insert(self.charlist, self.charpos, chars)
|
|
|
|
self.charpos = self.charpos + #util.splitToChars(chars)
|
2017-03-30 22:32:01 +00:00
|
|
|
self:initTextBox(table.concat(self.charlist), true)
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
2021-10-29 10:59:03 +00:00
|
|
|
dbg:guard(InputText, "addChars",
|
|
|
|
function(self, chars)
|
|
|
|
assert(type(chars) == "string",
|
|
|
|
"Wrong chars value type (expected string)!")
|
|
|
|
end)
|
2013-07-30 15:07:33 +00:00
|
|
|
|
|
|
|
function InputText:delChar()
|
2018-08-06 19:16:30 +00:00
|
|
|
if self.readonly or not self:isTextEditable(true) then
|
2018-08-01 16:33:52 +00:00
|
|
|
return
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.charpos == 1 then return end
|
|
|
|
self.charpos = self.charpos - 1
|
2018-08-01 16:33:52 +00:00
|
|
|
self.is_text_edited = true
|
2014-03-13 13:52:43 +00:00
|
|
|
table.remove(self.charlist, self.charpos)
|
2014-09-10 07:30:59 +00:00
|
|
|
self:initTextBox(table.concat(self.charlist))
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
function InputText:delNextChar()
|
|
|
|
if self.readonly or not self:isTextEditable(true) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if self.charpos > #self.charlist then return end
|
|
|
|
self.is_text_edited = true
|
|
|
|
table.remove(self.charlist, self.charpos)
|
|
|
|
self:initTextBox(table.concat(self.charlist))
|
|
|
|
end
|
|
|
|
|
2018-08-01 16:33:52 +00:00
|
|
|
function InputText:delToStartOfLine()
|
2018-08-06 19:16:30 +00:00
|
|
|
if self.readonly or not self:isTextEditable(true) then
|
2018-08-01 16:33:52 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if self.charpos == 1 then return end
|
|
|
|
-- self.charlist[self.charpos] is the char after the cursor
|
|
|
|
if self.charlist[self.charpos-1] == "\n" then
|
|
|
|
-- If at start of line, just remove the \n and join the previous line
|
|
|
|
self.charpos = self.charpos - 1
|
|
|
|
table.remove(self.charlist, self.charpos)
|
|
|
|
else
|
|
|
|
-- If not, remove chars until first found \n (but keeping it)
|
|
|
|
while self.charpos > 1 and self.charlist[self.charpos-1] ~= "\n" do
|
|
|
|
self.charpos = self.charpos - 1
|
|
|
|
table.remove(self.charlist, self.charpos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.is_text_edited = true
|
|
|
|
self:initTextBox(table.concat(self.charlist))
|
|
|
|
end
|
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- For the following cursor/scroll methods, the text_widget deals
|
|
|
|
-- itself with setDirty'ing the appropriate regions
|
2017-10-10 16:04:51 +00:00
|
|
|
function InputText:leftChar()
|
|
|
|
if self.charpos == 1 then return end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
self.text_widget:moveCursorLeft()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2017-10-10 16:04:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:rightChar()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
if self.charpos > #self.charlist then return end
|
|
|
|
self.text_widget:moveCursorRight()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2017-10-10 16:04:51 +00:00
|
|
|
end
|
|
|
|
|
2021-05-22 21:25:14 +00:00
|
|
|
function InputText:goToStartOfLine()
|
|
|
|
local new_pos = select(1, self:getStringPos({"\n", "\r"}, {"\n", "\r"}))
|
|
|
|
self.text_widget:moveCursorToCharPos(new_pos)
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2021-05-22 21:25:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:goToEndOfLine()
|
|
|
|
local new_pos = select(2, self:getStringPos({"\n", "\r"}, {"\n", "\r"})) + 1
|
|
|
|
self.text_widget:moveCursorToCharPos(new_pos)
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2021-05-22 21:25:14 +00:00
|
|
|
end
|
|
|
|
|
2020-12-30 21:26:40 +00:00
|
|
|
function InputText:goToHome()
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
self.text_widget:moveCursorHome()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2020-12-30 21:26:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:goToEnd()
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
self.text_widget:moveCursorEnd()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2020-12-30 21:26:40 +00:00
|
|
|
end
|
|
|
|
|
2021-05-16 10:45:36 +00:00
|
|
|
function InputText:moveCursorToCharPos(char_pos)
|
|
|
|
self.text_widget:moveCursorToCharPos(char_pos)
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2021-05-16 10:45:36 +00:00
|
|
|
end
|
|
|
|
|
2017-10-10 16:04:51 +00:00
|
|
|
function InputText:upLine()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
self.text_widget:moveCursorUp()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2017-10-10 16:04:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:downLine()
|
2021-07-15 14:28:54 +00:00
|
|
|
if #self.charlist == 0 then return end -- Avoid cursor moving within a hint.
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
self.text_widget:moveCursorDown()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:scrollDown()
|
|
|
|
self.text_widget:scrollDown()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:scrollUp()
|
|
|
|
self.text_widget:scrollUp()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:scrollToTop()
|
|
|
|
self.text_widget:scrollToTop()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputText:scrollToBottom()
|
|
|
|
self.text_widget:scrollToBottom()
|
2023-09-01 20:51:41 +00:00
|
|
|
self:resyncPos()
|
2017-10-10 16:04:51 +00:00
|
|
|
end
|
|
|
|
|
2014-08-20 06:45:38 +00:00
|
|
|
function InputText:clear()
|
2016-06-26 14:43:40 +00:00
|
|
|
self.charpos = nil
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
self.top_line_num = 1
|
2018-08-01 16:33:52 +00:00
|
|
|
self.is_text_edited = true
|
2014-09-10 07:30:59 +00:00
|
|
|
self:initTextBox("")
|
2018-08-01 16:33:52 +00:00
|
|
|
self:checkTextEditability()
|
2014-08-20 06:45:38 +00:00
|
|
|
end
|
|
|
|
|
2013-07-30 15:07:33 +00:00
|
|
|
function InputText:getText()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.text
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
2018-08-01 16:33:52 +00:00
|
|
|
function InputText:setText(text, keep_edited_state)
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- Keep previous charpos and top_line_num
|
|
|
|
self:initTextBox(text)
|
2018-08-01 16:33:52 +00:00
|
|
|
if not keep_edited_state then
|
|
|
|
-- assume new text is set by caller, and we start fresh
|
|
|
|
self.is_text_edited = false
|
|
|
|
self:checkTextEditability()
|
|
|
|
end
|
2013-08-21 11:54:46 +00:00
|
|
|
end
|
2022-03-14 18:56:18 +00:00
|
|
|
dbg:guard(InputText, "setText",
|
|
|
|
function(self, text, keep_edited_state)
|
|
|
|
assert(type(text) == "string",
|
|
|
|
"Wrong text type (expected string)")
|
|
|
|
end)
|
2013-08-21 11:54:46 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return InputText
|