Move windows to uptr. Add simple text editing.
This commit is contained in:
parent
2bcc7b3d83
commit
b99708e7d3
55 changed files with 1257 additions and 994 deletions
97
src/ui_elements/widgets/TextBox.cpp
Normal file
97
src/ui_elements/widgets/TextBox.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include "TextBox.h"
|
||||
#include "TextElement.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
TextBox::TextBox()
|
||||
: Widget(),
|
||||
mContent(),
|
||||
mCaps(false)
|
||||
{
|
||||
mBackgroundColor = Color::Create(200, 200, 200);
|
||||
}
|
||||
|
||||
std::unique_ptr<TextBox> TextBox::Create()
|
||||
{
|
||||
return std::make_unique<TextBox>();
|
||||
}
|
||||
|
||||
void TextBox::SetContent(const std::string& text)
|
||||
{
|
||||
mContent = text;
|
||||
}
|
||||
|
||||
std::string TextBox::GetContent() const
|
||||
{
|
||||
return mContent;
|
||||
}
|
||||
|
||||
void TextBox::AppendContent(const std::string& text)
|
||||
{
|
||||
mContent += text;
|
||||
}
|
||||
|
||||
bool TextBox::OnMyKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
if(!event) return false;
|
||||
|
||||
const auto keyString = event->GetKeyString();
|
||||
if (keyString == "KEY_RETURN")
|
||||
{
|
||||
AppendContent("\n");
|
||||
}
|
||||
else if (keyString == "KEY_BACK")
|
||||
{
|
||||
mContent = mContent.substr(0, mContent.size()-1);
|
||||
}
|
||||
else if (keyString == "KEY_SPACE")
|
||||
{
|
||||
AppendContent(" ");
|
||||
}
|
||||
else if (keyString == "KEY_CAPS")
|
||||
{
|
||||
mCaps = !mCaps;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mCaps && !keyString.empty())
|
||||
{
|
||||
const char c = std::toupper(keyString[0]);
|
||||
AppendContent(std::string(&c));
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendContent(keyString);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextBox::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
|
||||
double offset = 0;
|
||||
if(!mContent.empty())
|
||||
{
|
||||
std::stringstream stream(mContent);
|
||||
std::string segment;
|
||||
std::vector<std::string> seglist;
|
||||
while(std::getline(stream, segment, '\n'))
|
||||
{
|
||||
seglist.push_back(segment);
|
||||
}
|
||||
for(const auto& line : seglist)
|
||||
{
|
||||
auto loc = DiscretePoint(mLocation.GetX() + mWidth/10,
|
||||
mLocation.GetY() + mHeight/10 + offset);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(TextElement::Create(line, loc));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
offset += 15;
|
||||
}
|
||||
}
|
||||
CopyMyLayers();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue