mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Implement string composition for CGUIEditBox
This commit is contained in:
parent
79669b5a94
commit
f4e6c2b62f
3 changed files with 29 additions and 2 deletions
|
@ -234,6 +234,10 @@ bool CGUIEditBox::OnEvent(const SEvent &event)
|
|||
inputString(*event.StringInput.Str);
|
||||
return true;
|
||||
break;
|
||||
case EET_STRING_COMPOSITION_EVENT:
|
||||
composeString(*event.StringComposition.Str);
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1262,10 +1266,10 @@ void CGUIEditBox::inputChar(wchar_t c)
|
|||
inputString(s);
|
||||
}
|
||||
|
||||
void CGUIEditBox::inputString(const core::stringw &str)
|
||||
bool CGUIEditBox::insertString(const core::stringw &str)
|
||||
{
|
||||
if (!isEnabled())
|
||||
return;
|
||||
return false;
|
||||
|
||||
core::stringw s;
|
||||
u32 len = str.size();
|
||||
|
@ -1324,6 +1328,13 @@ void CGUIEditBox::inputString(const core::stringw &str)
|
|||
}
|
||||
|
||||
BlinkStartTime = os::Timer::getTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CGUIEditBox::inputString(const core::stringw &str)
|
||||
{
|
||||
if (!insertString(str))
|
||||
return;
|
||||
setTextMarkers(0, 0);
|
||||
|
||||
breakText();
|
||||
|
@ -1331,6 +1342,17 @@ void CGUIEditBox::inputString(const core::stringw &str)
|
|||
sendGuiEvent(EGET_EDITBOX_CHANGED);
|
||||
}
|
||||
|
||||
void CGUIEditBox::composeString(const core::stringw &str)
|
||||
{
|
||||
if (!insertString(str))
|
||||
return;
|
||||
setTextMarkers(CursorPos-str.size(), CursorPos);
|
||||
|
||||
breakText();
|
||||
calculateScrollPos();
|
||||
sendGuiEvent(EGET_EDITBOX_CHANGED);
|
||||
}
|
||||
|
||||
// calculate autoscroll
|
||||
void CGUIEditBox::calculateScrollPos()
|
||||
{
|
||||
|
|
|
@ -144,10 +144,14 @@ protected:
|
|||
void setTextRect(s32 line);
|
||||
//! returns the line number that the cursor is on
|
||||
s32 getLineFromPos(s32 pos);
|
||||
//! inserts a string to the edit box; used by inputString and composeString
|
||||
bool insertString(const core::stringw &str);
|
||||
//! adds a letter to the edit box
|
||||
void inputChar(wchar_t c);
|
||||
//! adds a string to the edit box
|
||||
void inputString(const core::stringw &str);
|
||||
//! compose a string before it is added
|
||||
void composeString(const core::stringw &str);
|
||||
//! calculates the current scroll position
|
||||
void calculateScrollPos();
|
||||
//! calculated the FrameRect
|
||||
|
|
|
@ -552,6 +552,7 @@ bool CGUIEnvironment::postEventFromUser(const SEvent &event)
|
|||
}
|
||||
}
|
||||
} break;
|
||||
case EET_STRING_COMPOSITION_EVENT: [[fallthrough]];
|
||||
case EET_STRING_INPUT_EVENT:
|
||||
if (Focus && Focus->OnEvent(event))
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue