83 lines
2.5 KiB
C++
83 lines
2.5 KiB
C++
#include "HorizontalSpacer.h"
|
|
#include "TextEditorView.h"
|
|
#include "VerticalSpacer.h"
|
|
#include <iostream>
|
|
|
|
TextEditorView::TextEditorView()
|
|
: mTextBox(),
|
|
mController(TextEditorController::Create())
|
|
{
|
|
|
|
}
|
|
|
|
TextEditorController* TextEditorView::GetController()
|
|
{
|
|
return mController.get();
|
|
}
|
|
|
|
void TextEditorView::Initialize()
|
|
{
|
|
auto label = Label::Create();
|
|
label->setLabel("Text Editor");
|
|
label->setBackgroundColor(Color(181, 189, 200));
|
|
label->setMargin(1);
|
|
|
|
auto textBox = TextBox::Create();
|
|
mTextBox = textBox.get();
|
|
|
|
auto saveButton = Button::Create();
|
|
saveButton->setLabel("Save");
|
|
saveButton->setBackgroundColor(Color(200, 200, 200));
|
|
saveButton->setMargin(2);
|
|
auto onSave = [this](Widget* self){
|
|
if(this && mController && mTextBox)
|
|
{
|
|
mController->SetContent(mTextBox->getContent());
|
|
mController->OnSave();
|
|
};
|
|
};
|
|
saveButton->setOnClickFunction(onSave);
|
|
|
|
auto clearButton = Button::Create();
|
|
clearButton->setLabel("Clear");
|
|
clearButton->setBackgroundColor(Color(200, 200, 200));
|
|
clearButton->setMargin(2);
|
|
auto onClear = [this](Widget* self){
|
|
if(this && mController && mTextBox)
|
|
{
|
|
mController->OnClear();
|
|
mTextBox->setContent("");
|
|
};
|
|
};
|
|
clearButton->setOnClickFunction(onClear);
|
|
|
|
auto loadButton = Button::Create();
|
|
loadButton->setLabel("Load");
|
|
loadButton->setBackgroundColor(Color(200, 200, 200));
|
|
loadButton->setMargin(2);
|
|
auto onLoad = [this](Widget* self){
|
|
if(this && mController && mTextBox)
|
|
{
|
|
mController->OnLoad();
|
|
mTextBox->setContent(mController->GetContent());
|
|
};
|
|
};
|
|
loadButton->setOnClickFunction(onLoad);
|
|
|
|
auto buttonSpacer = VerticalSpacer::Create();
|
|
buttonSpacer->AddWidgetWithScale(std::move(saveButton), 1);
|
|
buttonSpacer->AddWidgetWithScale(std::move(clearButton), 1);
|
|
buttonSpacer->AddWidgetWithScale(std::move(loadButton), 1);
|
|
|
|
auto hSpacer = HorizontalSpacer::Create();
|
|
hSpacer->addWidgetWithScale(std::move(label), 1);
|
|
hSpacer->addWidgetWithScale(std::move(textBox), 14);
|
|
hSpacer->addWidgetWithScale(std::move(buttonSpacer), 1);
|
|
|
|
addWidget(std::move(hSpacer));
|
|
}
|
|
|
|
std::unique_ptr<TextEditorView> TextEditorView::Create()
|
|
{
|
|
return std::make_unique<TextEditorView>();
|
|
}
|