Add non-public {Line,Text}Edit::_set_text()
- [Web] Fix "Enter" not triggering LineEdit submits. Co-authored-by: Marwen Azouzi <marwen.azouzi@datadoghq.com>
This commit is contained in:
committed by
Rémi Verschelde
parent
7692a3d53b
commit
263589497b
@@ -437,26 +437,27 @@ void DisplayServerAndroid::window_set_drop_files_callback(const Callable &p_call
|
||||
// Not supported on Android.
|
||||
}
|
||||
|
||||
void DisplayServerAndroid::_window_callback(const Callable &p_callable, const Variant &p_arg, bool p_deferred) const {
|
||||
template <typename... Args>
|
||||
void DisplayServerAndroid::_window_callback(const Callable &p_callable, bool p_deferred, const Args &...p_rest_args) const {
|
||||
if (p_callable.is_valid()) {
|
||||
if (p_deferred) {
|
||||
p_callable.call_deferred(p_arg);
|
||||
p_callable.call_deferred(p_rest_args...);
|
||||
} else {
|
||||
p_callable.call(p_arg);
|
||||
p_callable.call(p_rest_args...);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayServerAndroid::send_window_event(DisplayServer::WindowEvent p_event, bool p_deferred) const {
|
||||
_window_callback(window_event_callback, int(p_event), p_deferred);
|
||||
_window_callback(window_event_callback, p_deferred, int(p_event));
|
||||
}
|
||||
|
||||
void DisplayServerAndroid::send_input_event(const Ref<InputEvent> &p_event) const {
|
||||
_window_callback(input_event_callback, p_event);
|
||||
_window_callback(input_event_callback, false, p_event);
|
||||
}
|
||||
|
||||
void DisplayServerAndroid::send_input_text(const String &p_text) const {
|
||||
_window_callback(input_text_callback, p_text);
|
||||
_window_callback(input_text_callback, false, p_text, false);
|
||||
}
|
||||
|
||||
void DisplayServerAndroid::_dispatch_input_events(const Ref<InputEvent> &p_event) {
|
||||
|
||||
@@ -96,7 +96,8 @@ class DisplayServerAndroid : public DisplayServer {
|
||||
|
||||
Callable file_picker_callback;
|
||||
|
||||
void _window_callback(const Callable &p_callable, const Variant &p_arg, bool p_deferred = false) const;
|
||||
template <typename... Args>
|
||||
void _window_callback(const Callable &p_callable, bool p_deferred, const Args &...p_rest_args) const;
|
||||
|
||||
static void _dispatch_input_events(const Ref<InputEvent> &p_event);
|
||||
|
||||
|
||||
@@ -796,7 +796,7 @@ void DisplayServerWeb::_vk_input_text_callback(const String &p_text, int p_curso
|
||||
return;
|
||||
}
|
||||
// Call input_text
|
||||
ds->input_text_callback.call(p_text);
|
||||
ds->input_text_callback.call(p_text, true);
|
||||
// Insert key right to reach position.
|
||||
Input *input = Input::get_singleton();
|
||||
Ref<InputEventKey> k;
|
||||
|
||||
@@ -157,6 +157,7 @@ module.exports = [
|
||||
'GodotFS': true,
|
||||
'GodotOS': true,
|
||||
'GodotAudio': true,
|
||||
'GodotInput': true,
|
||||
'GodotRuntime': true,
|
||||
'IDHandler': true,
|
||||
'XRWebGLLayer': true,
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
const GodotDisplayVK = {
|
||||
|
||||
$GodotDisplayVK__deps: ['$GodotRuntime', '$GodotConfig', '$GodotEventListeners'],
|
||||
$GodotDisplayVK__deps: ['$GodotRuntime', '$GodotConfig', '$GodotEventListeners', '$GodotInput'],
|
||||
$GodotDisplayVK__postset: 'GodotOS.atexit(function(resolve, reject) { GodotDisplayVK.clear(); resolve(); });',
|
||||
$GodotDisplayVK: {
|
||||
textinput: null,
|
||||
@@ -61,6 +61,17 @@ const GodotDisplayVK = {
|
||||
input_cb(c_str, elem.selectionEnd);
|
||||
GodotRuntime.free(c_str);
|
||||
}, false);
|
||||
if (what === 'input') {
|
||||
// Handling the "Enter" key.
|
||||
const onKey = (pEvent, pEventName) => {
|
||||
if (pEvent.key !== 'Enter') {
|
||||
return;
|
||||
}
|
||||
GodotInput.onKeyEvent(pEventName === 'keydown', pEvent);
|
||||
};
|
||||
GodotEventListeners.add(elem, 'keydown', (pEvent) => onKey(pEvent, 'keydown'), false);
|
||||
GodotEventListeners.add(elem, 'keyup', (pEvent) => onKey(pEvent, 'keyup'), false);
|
||||
}
|
||||
GodotEventListeners.add(elem, 'blur', function (evt) {
|
||||
elem.style.display = 'none';
|
||||
elem.readonly = true;
|
||||
|
||||
@@ -482,9 +482,13 @@ mergeInto(LibraryManager.library, GodotInputDragDrop);
|
||||
const GodotInput = {
|
||||
$GodotInput__deps: ['$GodotRuntime', '$GodotConfig', '$GodotEventListeners', '$GodotInputGamepads', '$GodotInputDragDrop', '$GodotIME'],
|
||||
$GodotInput: {
|
||||
inputKeyCallback: null,
|
||||
setInputKeyData: null,
|
||||
|
||||
getModifiers: function (evt) {
|
||||
return (evt.shiftKey + 0) + ((evt.altKey + 0) << 1) + ((evt.ctrlKey + 0) << 2) + ((evt.metaKey + 0) << 3);
|
||||
},
|
||||
|
||||
computePosition: function (evt, rect) {
|
||||
const canvas = GodotConfig.canvas;
|
||||
const rw = canvas.width / rect.width;
|
||||
@@ -493,6 +497,20 @@ const GodotInput = {
|
||||
const y = (evt.clientY - rect.y) * rh;
|
||||
return [x, y];
|
||||
},
|
||||
|
||||
onKeyEvent: function (pIsPressed, pEvent) {
|
||||
if (GodotInput.inputKeyCallback == null) {
|
||||
throw new TypeError('GodotInput.onKeyEvent(): GodotInput.inputKeyCallback is null, cannot process key event.');
|
||||
}
|
||||
if (GodotInput.setInputKeyData == null) {
|
||||
throw new TypeError('GodotInput.onKeyEvent(): GodotInput.setInputKeyData is null, cannot process key event.');
|
||||
}
|
||||
|
||||
const modifiers = GodotInput.getModifiers(pEvent);
|
||||
GodotInput.setInputKeyData(pEvent.code, pEvent.key);
|
||||
GodotInput.inputKeyCallback(pIsPressed ? 1 : 0, pEvent.repeat, modifiers);
|
||||
pEvent.preventDefault();
|
||||
},
|
||||
},
|
||||
|
||||
/*
|
||||
@@ -590,17 +608,14 @@ const GodotInput = {
|
||||
*/
|
||||
godot_js_input_key_cb__proxy: 'sync',
|
||||
godot_js_input_key_cb__sig: 'viii',
|
||||
godot_js_input_key_cb: function (callback, code, key) {
|
||||
const func = GodotRuntime.get_func(callback);
|
||||
function key_cb(pressed, evt) {
|
||||
const modifiers = GodotInput.getModifiers(evt);
|
||||
GodotRuntime.stringToHeap(evt.code, code, 32);
|
||||
GodotRuntime.stringToHeap(evt.key, key, 32);
|
||||
func(pressed, evt.repeat, modifiers);
|
||||
evt.preventDefault();
|
||||
}
|
||||
GodotEventListeners.add(GodotConfig.canvas, 'keydown', key_cb.bind(null, 1), false);
|
||||
GodotEventListeners.add(GodotConfig.canvas, 'keyup', key_cb.bind(null, 0), false);
|
||||
godot_js_input_key_cb: function (pCallback, pCodePtr, pKeyPtr) {
|
||||
GodotInput.inputKeyCallback = GodotRuntime.get_func(pCallback);
|
||||
GodotInput.setInputKeyData = (pCode, pKey) => {
|
||||
GodotRuntime.stringToHeap(pCode, pCodePtr, 32);
|
||||
GodotRuntime.stringToHeap(pKey, pKeyPtr, 32);
|
||||
};
|
||||
GodotEventListeners.add(GodotConfig.canvas, 'keydown', GodotInput.onKeyEvent.bind(null, true), false);
|
||||
GodotEventListeners.add(GodotConfig.canvas, 'keyup', GodotInput.onKeyEvent.bind(null, false), false);
|
||||
},
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user