Textedit improvements
This commit is contained in:
parent
95f79b45dc
commit
0a91fff82a
|
@ -25,6 +25,7 @@ local function navigateCommand(step)
|
|||
if currentHistoryIndex > 0 then
|
||||
local command = commandHistory[numCommands - currentHistoryIndex + 1]
|
||||
commandTextEdit:setText(command)
|
||||
commandTextEdit:setCursorPos(-1)
|
||||
else
|
||||
commandTextEdit:clearText()
|
||||
end
|
||||
|
@ -52,6 +53,7 @@ local function completeCommand()
|
|||
-- complete command with one match
|
||||
if #possibleCommands == 1 then
|
||||
commandTextEdit:setText(possibleCommands[1])
|
||||
commandTextEdit:setCursorPos(-1)
|
||||
-- show command matches
|
||||
elseif #possibleCommands > 0 then
|
||||
print('>> ' .. commandBegin)
|
||||
|
@ -75,6 +77,7 @@ local function completeCommand()
|
|||
end
|
||||
end
|
||||
commandTextEdit:setText(commandBegin)
|
||||
commandTextEdit:setCursorPos(-1)
|
||||
|
||||
for i,v in ipairs(possibleCommands) do
|
||||
print(v)
|
||||
|
|
|
@ -39,6 +39,8 @@ UIWindow
|
|||
anchors.right: parent.right
|
||||
margin-left: 5
|
||||
font: terminus-14px-bold
|
||||
selection-color: black
|
||||
selection-background-color: white
|
||||
|
||||
ResizeBorder
|
||||
id: bottomResizeBorder
|
||||
|
|
|
@ -7,6 +7,7 @@ ConsoleLabel < UITextEdit
|
|||
text-auto-resize: true
|
||||
selection-color: #111416
|
||||
selection-background-color: #999999
|
||||
change-cursor-image: false
|
||||
|
||||
ConsolePhantomLabel < UILabel
|
||||
font: verdana-11px-antialised
|
||||
|
|
|
@ -219,7 +219,7 @@ void MapView::draw(const Rect& rect)
|
|||
continue;
|
||||
|
||||
PointF jumpOffset = creature->getJumpOffset() * scaleFactor;
|
||||
Point creatureOffset = Point(16 - creature->getDisplacementX(), -3 - creature->getDisplacementY());
|
||||
Point creatureOffset = Point(16 - creature->getDisplacementX(), - creature->getDisplacementY() - 2);
|
||||
Position pos = creature->getPosition();
|
||||
Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset;
|
||||
p += (creature->getDrawOffset() + creatureOffset) * scaleFactor - Point(stdext::round(jumpOffset.x), stdext::round(jumpOffset.y));
|
||||
|
|
|
@ -652,6 +652,7 @@ void Application::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<UITextEdit>("setCursorPos", &UITextEdit::setCursorPos);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("setSelection", &UITextEdit::setSelection);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("setCursorVisible", &UITextEdit::setCursorVisible);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("setChangeCursorImage", &UITextEdit::setChangeCursorImage);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("setTextHidden", &UITextEdit::setTextHidden);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("setValidCharacters", &UITextEdit::setValidCharacters);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("setShiftNavigation", &UITextEdit::setShiftNavigation);
|
||||
|
@ -690,6 +691,7 @@ void Application::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<UITextEdit>("isEditable", &UITextEdit::isEditable);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("isSelectable", &UITextEdit::isSelectable);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("isCursorVisible", &UITextEdit::isCursorVisible);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("isChangingCursorImage", &UITextEdit::isChangingCursorImage);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("isTextHidden", &UITextEdit::isTextHidden);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("isShiftNavigation", &UITextEdit::isShiftNavigation);
|
||||
g_lua.bindClassMemberFunction<UITextEdit>("isMultiline", &UITextEdit::isMultiline);
|
||||
|
|
|
@ -41,6 +41,7 @@ UITextEdit::UITextEdit()
|
|||
m_maxLength = 0;
|
||||
m_editable = true;
|
||||
m_selectable = true;
|
||||
m_changeCursorImage = true;
|
||||
m_selectionReference = 0;
|
||||
m_selectionStart = 0;
|
||||
m_selectionEnd = 0;
|
||||
|
@ -349,6 +350,9 @@ void UITextEdit::setSelection(int start, int end)
|
|||
if(start > end)
|
||||
std::swap(start, end);
|
||||
|
||||
if(end == -1)
|
||||
end = m_text.length();
|
||||
|
||||
m_selectionStart = std::min(std::max(start, 0), (int)m_text.length());
|
||||
m_selectionEnd = std::min(std::max(end, 0), (int)m_text.length());
|
||||
}
|
||||
|
@ -584,11 +588,13 @@ void UITextEdit::updateText()
|
|||
|
||||
void UITextEdit::onHoverChange(bool hovered)
|
||||
{
|
||||
if(m_changeCursorImage) {
|
||||
if(hovered)
|
||||
g_mouse.setTextCursor();
|
||||
else
|
||||
g_mouse.restoreCursor();
|
||||
}
|
||||
}
|
||||
|
||||
void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||
{
|
||||
|
@ -620,6 +626,8 @@ void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s
|
|||
}
|
||||
else if(node->tag() == "cursor-visible")
|
||||
setCursorVisible(node->value<bool>());
|
||||
else if(node->tag() == "change-cursor-image")
|
||||
setChangeCursorImage(node->value<bool>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -735,6 +743,18 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
|
|||
setSelection(m_selectionReference, m_cursorPos);
|
||||
}
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyHome) { // move cursor to first character
|
||||
if(m_cursorPos != 0) {
|
||||
setSelection(m_cursorPos, 0);
|
||||
setCursorPos(0);
|
||||
return true;
|
||||
}
|
||||
} else if(keyCode == Fw::KeyEnd) { // move cursor to last character
|
||||
if(m_cursorPos != (int)m_text.length()) {
|
||||
setSelection(m_cursorPos, m_text.length());
|
||||
setCursorPos(m_text.length());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
void setCursorPos(int pos);
|
||||
void setSelection(int start, int end);
|
||||
void setCursorVisible(bool enable) { m_cursorVisible = enable; }
|
||||
void setChangeCursorImage(bool enable) { m_changeCursorImage = enable; }
|
||||
void setTextHidden(bool hidden);
|
||||
void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
|
||||
void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
|
||||
|
@ -81,6 +82,7 @@ public:
|
|||
Color getSelectionBackgroundColor() { return m_selectionBackgroundColor; }
|
||||
bool hasSelection() { return m_selectionEnd - m_selectionStart > 0; }
|
||||
bool isCursorVisible() { return m_cursorVisible; }
|
||||
bool isChangingCursorImage() { return m_changeCursorImage; }
|
||||
bool isTextHidden() { return m_textHidden; }
|
||||
bool isShiftNavigation() { return m_shiftNavigation; }
|
||||
bool isMultiline() { return m_multiline; }
|
||||
|
@ -118,6 +120,7 @@ private:
|
|||
bool m_cursorInRange;
|
||||
bool m_cursorVisible;
|
||||
bool m_editable;
|
||||
bool m_changeCursorImage;
|
||||
std::string m_validCharacters;
|
||||
uint m_maxLength;
|
||||
bool m_updatesEnabled;
|
||||
|
|
Loading…
Reference in New Issue