This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sfan5
reviewed
Mar 31, 2021
4de18ef
to
d7127df
Compare
I also made the corresponding changes to Minetest. Should I post them now or should I wait for this PR to be merged? |
Posting them early is useful so they can be looked at or tested. |
diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp
index a4e91fe78..dc688395b 100644
--- a/src/gui/guiChatConsole.cpp
+++ b/src/gui/guiChatConsole.cpp
@@ -619,6 +619,11 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
m_chat_backend->scroll(rows);
}
}
+ else if(event.EventType == EET_STRING_INPUT_EVENT)
+ {
+ prompt.input(std::wstring(event.StringInput.Str->c_str()));
+ return true;
+ }
return Parent ? Parent->OnEvent(event) : false;
}
diff --git a/src/gui/guiChatConsole.h b/src/gui/guiChatConsole.h
index 896342ab0..1152f2b2d 100644
--- a/src/gui/guiChatConsole.h
+++ b/src/gui/guiChatConsole.h
@@ -72,6 +72,8 @@ class GUIChatConsole : public gui::IGUIElement
virtual void setVisible(bool visible);
+ virtual bool acceptsIME() { return true; }
+
private:
void reformatConsole();
void recalculateConsolePosition();
diff --git a/src/gui/guiEditBox.cpp b/src/gui/guiEditBox.cpp
index cd5a0868d..86cd2001e 100644
--- a/src/gui/guiEditBox.cpp
+++ b/src/gui/guiEditBox.cpp
@@ -216,6 +216,10 @@ bool GUIEditBox::OnEvent(const SEvent &event)
if (processMouse(event))
return true;
break;
+ case EET_STRING_INPUT_EVENT:
+ inputString(event.StringInput.Str);
+ return true;
+ break;
default:
break;
}
@@ -708,6 +712,46 @@ void GUIEditBox::inputChar(wchar_t c)
calculateScrollPos();
}
+void GUIEditBox::inputString(core::stringw *str)
+{
+ if (!isEnabled() || !m_writable)
+ return;
+
+ if (str) {
+ u32 len = str->size();
+ if (Text.size()+len <= m_max || m_max == 0) {
+ core::stringw s;
+ if (m_mark_begin != m_mark_end) {
+ // clang-format off
+ // replace marked test
+ s32 real_begin = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
+ s32 real_end = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
+
+ s = Text.subString(0, real_begin);
+ s.append(*str);
+ s.append(Text.subString(real_end, Text.size() - real_end));
+ Text = s;
+ m_cursor_pos = real_begin + len;
+ // clang-format on
+ } else {
+ // append string
+ s = Text.subString(0, m_cursor_pos);
+ s.append(*str);
+ s.append(Text.subString(m_cursor_pos,
+ Text.size() - m_cursor_pos));
+ Text = s;
+ m_cursor_pos += len;
+ }
+
+ m_blink_start_time = porting::getTimeMs();
+ setTextMarkers(0, 0);
+ }
+ }
+ breakText();
+ sendGuiEvent(EGET_EDITBOX_CHANGED);
+ calculateScrollPos();
+}
+
bool GUIEditBox::processMouse(const SEvent &event)
{
switch (event.MouseInput.Event) {
diff --git a/src/gui/guiEditBox.h b/src/gui/guiEditBox.h
index c616d75d1..da5628b6b 100644
--- a/src/gui/guiEditBox.h
+++ b/src/gui/guiEditBox.h
@@ -138,6 +138,8 @@ class GUIEditBox : public IGUIEditBox
virtual void deserializeAttributes(
io::IAttributes *in, io::SAttributeReadWriteOptions *options);
+ virtual bool acceptsIME() { return isEnabled() && m_writable; };
+
protected:
virtual void breakText() = 0;
@@ -156,6 +158,7 @@ class GUIEditBox : public IGUIEditBox
virtual s32 getCursorPos(s32 x, s32 y) = 0;
bool processKey(const SEvent &event);
+ virtual void inputString(core::stringw *str);
virtual void inputChar(wchar_t c);
//! returns the line number that the cursor is on
|
sfan5
reviewed
Apr 2, 2021
Works great aside from the code comments, good job 👍. |
Here is the fixup patch to keep diff --git a/src/gui/guiEditBox.cpp b/src/gui/guiEditBox.cpp
index 86cd2001e..260589f02 100644
--- a/src/gui/guiEditBox.cpp
+++ b/src/gui/guiEditBox.cpp
@@ -217,7 +217,7 @@ bool GUIEditBox::OnEvent(const SEvent &event)
return true;
break;
case EET_STRING_INPUT_EVENT:
- inputString(event.StringInput.Str);
+ inputString(*event.StringInput.Str);
return true;
break;
default:
@@ -674,79 +674,44 @@ bool GUIEditBox::onKeyDelete(const SEvent &event, s32 &mark_begin, s32 &mark_end
void GUIEditBox::inputChar(wchar_t c)
{
- if (!isEnabled() || !m_writable)
- return;
-
- if (c != 0) {
- if (Text.size() < m_max || m_max == 0) {
- core::stringw s;
-
- if (m_mark_begin != m_mark_end) {
- // clang-format off
- // replace marked text
- s32 real_begin = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
- s32 real_end = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
-
- s = Text.subString(0, real_begin);
- s.append(c);
- s.append(Text.subString(real_end, Text.size() - real_end));
- Text = s;
- m_cursor_pos = real_begin + 1;
- // clang-format on
- } else {
- // add new character
- s = Text.subString(0, m_cursor_pos);
- s.append(c);
- s.append(Text.subString(m_cursor_pos,
- Text.size() - m_cursor_pos));
- Text = s;
- ++m_cursor_pos;
- }
-
- m_blink_start_time = porting::getTimeMs();
- setTextMarkers(0, 0);
- }
- }
- breakText();
- sendGuiEvent(EGET_EDITBOX_CHANGED);
- calculateScrollPos();
+ core::stringw s(&c, 1);
+ inputString(s);
}
-void GUIEditBox::inputString(core::stringw *str)
+void GUIEditBox::inputString(const core::stringw &str)
{
if (!isEnabled() || !m_writable)
return;
- if (str) {
- u32 len = str->size();
- if (Text.size()+len <= m_max || m_max == 0) {
- core::stringw s;
- if (m_mark_begin != m_mark_end) {
- // clang-format off
- // replace marked test
- s32 real_begin = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
- s32 real_end = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
-
- s = Text.subString(0, real_begin);
- s.append(*str);
- s.append(Text.subString(real_end, Text.size() - real_end));
- Text = s;
- m_cursor_pos = real_begin + len;
- // clang-format on
- } else {
- // append string
- s = Text.subString(0, m_cursor_pos);
- s.append(*str);
- s.append(Text.subString(m_cursor_pos,
- Text.size() - m_cursor_pos));
- Text = s;
- m_cursor_pos += len;
- }
-
- m_blink_start_time = porting::getTimeMs();
- setTextMarkers(0, 0);
+ u32 len = str.size();
+ if (Text.size()+len <= m_max || m_max == 0) {
+ core::stringw s;
+ if (m_mark_begin != m_mark_end) {
+ // clang-format off
+ // replace marked test
+ s32 real_begin = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
+ s32 real_end = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
+
+ s = Text.subString(0, real_begin);
+ s.append(str);
+ s.append(Text.subString(real_end, Text.size() - real_end));
+ Text = s;
+ m_cursor_pos = real_begin + len;
+ // clang-format on
+ } else {
+ // append string
+ s = Text.subString(0, m_cursor_pos);
+ s.append(str);
+ s.append(Text.subString(m_cursor_pos,
+ Text.size() - m_cursor_pos));
+ Text = s;
+ m_cursor_pos += len;
}
+
+ m_blink_start_time = porting::getTimeMs();
+ setTextMarkers(0, 0);
}
+
breakText();
sendGuiEvent(EGET_EDITBOX_CHANGED);
calculateScrollPos();
diff --git a/src/gui/guiEditBox.h b/src/gui/guiEditBox.h
index da5628b6b..2a5c911bc 100644
--- a/src/gui/guiEditBox.h
+++ b/src/gui/guiEditBox.h
@@ -158,7 +158,7 @@ class GUIEditBox : public IGUIEditBox
virtual s32 getCursorPos(s32 x, s32 y) = 0;
bool processKey(const SEvent &event);
- virtual void inputString(core::stringw *str);
+ virtual void inputString(const core::stringw &str);
virtual void inputChar(wchar_t c);
//! returns the line number that the cursor is on
|
sfan5
reviewed
Apr 2, 2021
Thanks, I've squashed your commits and merged them. |
SmallJoker
pushed a commit
to minetest/minetest
that referenced
this pull request
Apr 5, 2021
Make edit boxes respond to string input events (introduced in minetest/irrlicht#23) that are usually triggered by entering text with an IME.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR uses
XSetLocaleModifiers
to add support for IMEs.To-Do
This pull request is ready for review.
IME support only appears to work with certain locales (e.g. zh_CN) (this was tested with an older version of MT)Breaking changes
EET_STRING_INPUT_EVENT
event:event.StringInput
event.StringInput.Str
contains a reference to thecore::stringw
that contains the entered stringIGUIElement
now has abool acceptsIME()
method that returns whether the element accepts input from the IME:true
: keyboard input events are filtered by the IME before being passed to the elementfalse
(default): keyboard input events are not filtered by the IMEReferences