Set up stacked widget.
This commit is contained in:
parent
4e85edacc8
commit
ee51f3ee09
51 changed files with 808 additions and 195 deletions
|
@ -1,10 +1,26 @@
|
|||
list(APPEND client_LIB_INCLUDES GuiApplication.cpp TextEditorPanel.cpp)
|
||||
list(APPEND client_LIB_INCLUDES
|
||||
TopBar.cpp
|
||||
StatusBar.cpp
|
||||
GuiApplication.cpp
|
||||
TabbedPanelWidget.cpp
|
||||
text_editor/TextEditorView.cpp
|
||||
text_editor/TextEditorModel.cpp
|
||||
text_editor/TextEditorController.cpp
|
||||
text_editor/PlainTextDocument.cpp
|
||||
audio_editor/AudioEditorView.cpp
|
||||
image_editor/ImageEditorView.cpp
|
||||
web_client/WebClientView.cpp)
|
||||
|
||||
add_library(client SHARED ${client_LIB_INCLUDES})
|
||||
|
||||
target_link_libraries(client ui_elements windows core console database geometry)
|
||||
|
||||
target_include_directories(client PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/src/console"
|
||||
"${PROJECT_SOURCE_DIR}/src/ui_elements/widgets"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/text_editor"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/audio_editor"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/image_editor"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/web_client"
|
||||
"${PROJECT_SOURCE_DIR}/src/console"
|
||||
"${PROJECT_SOURCE_DIR}/src/ui_elements/widgets"
|
||||
)
|
|
@ -1,18 +1,20 @@
|
|||
#include "GuiApplication.h"
|
||||
|
||||
#include "Widget.h"
|
||||
#include "HorizontalSpacer.h"
|
||||
#include "VerticalSpacer.h"
|
||||
#include "TextBox.h"
|
||||
#include "Button.h"
|
||||
#include "Label.h"
|
||||
#include "XcbInterface.h"
|
||||
#include "XcbKeyboard.h"
|
||||
#include "Window.h"
|
||||
#include "TextElement.h"
|
||||
#include "WindowManager.h"
|
||||
#include "TextEditorPanel.h"
|
||||
#include <iostream>
|
||||
#include "TextEditorView.h"
|
||||
#include "AudioEditorView.h"
|
||||
#include "ImageEditorView.h"
|
||||
#include "WebClientView.h"
|
||||
#include "TabbedPanelWidget.h"
|
||||
#include "TopBar.h"
|
||||
#include "StatusBar.h"
|
||||
#include "HorizontalSpacer.h"
|
||||
|
||||
GuiApplication::GuiApplication()
|
||||
: AbstractDesktopApp(),
|
||||
|
@ -37,43 +39,34 @@ void GuiApplication::SetUpWidget()
|
|||
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
|
||||
mainWindow->SetSize(800, 600);
|
||||
|
||||
// Left panel
|
||||
auto textEditorButton = Button::Create();
|
||||
textEditorButton->SetLabel("Text Editor");
|
||||
textEditorButton->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
auto tabbedPanel = TabbedPanelWidget::Create();
|
||||
|
||||
auto imageEditorButton = Button::Create();
|
||||
imageEditorButton->SetLabel("Image Editor");
|
||||
imageEditorButton->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
|
||||
auto audioEditorButton = Button::Create();
|
||||
audioEditorButton->SetLabel("Audio Editor");
|
||||
audioEditorButton->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
|
||||
auto webClientButton = Button::Create();
|
||||
webClientButton->SetLabel("Web Client");
|
||||
webClientButton->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
|
||||
auto leftSpacer = HorizontalSpacer::Create();
|
||||
leftSpacer->AddWidget(std::move(textEditorButton));
|
||||
leftSpacer->AddWidget(std::move(imageEditorButton));
|
||||
leftSpacer->AddWidget(std::move(audioEditorButton));
|
||||
leftSpacer->AddWidget(std::move(webClientButton));
|
||||
leftSpacer->SetMaxHeight(200);
|
||||
|
||||
// Right panel
|
||||
auto textEditor = TextEditorPanel::Create();
|
||||
textEditor->SetOnSaveFunction([](const std::string& content)
|
||||
{
|
||||
std::cout << content << std::endl;
|
||||
});
|
||||
auto textEditor = TextEditorView::Create();
|
||||
auto path = mMainApplication->GetCommandLineArgs()->GetLaunchPath();
|
||||
path /= "out.txt";
|
||||
textEditor->GetController()->SetSavePath(path);
|
||||
textEditor->GetController()->SetLoadPath(path);
|
||||
textEditor->Initialize();
|
||||
tabbedPanel->AddPanel(std::move(textEditor), "Text Editor");
|
||||
|
||||
auto vertSpacer = VerticalSpacer::Create();
|
||||
vertSpacer->AddWidgetWithScale(std::move(leftSpacer), 1);
|
||||
vertSpacer->AddWidgetWithScale(std::move(textEditor), 4);
|
||||
auto audioEditor = AudioEditorView::Create();
|
||||
tabbedPanel->AddPanel(std::move(audioEditor), "Audio Editor");
|
||||
|
||||
mainWindow->AddWidget(std::move(vertSpacer));
|
||||
auto imageEditor = ImageEditorView::Create();
|
||||
tabbedPanel->AddPanel(std::move(imageEditor), "Image Editor");
|
||||
|
||||
auto webClient = WebClientView::Create();
|
||||
tabbedPanel->AddPanel(std::move(webClient), "Web Client");
|
||||
|
||||
auto topBar = TopBar::Create();
|
||||
auto statusBar = StatusBar::Create();
|
||||
|
||||
auto horizontalSpace = HorizontalSpacer::Create();
|
||||
horizontalSpace->AddWidgetWithScale(std::move(topBar), 1);
|
||||
horizontalSpace->AddWidgetWithScale(std::move(tabbedPanel), 20);
|
||||
horizontalSpace->AddWidgetWithScale(std::move(statusBar), 1);
|
||||
|
||||
mainWindow->AddWidget(std::move(horizontalSpace));
|
||||
}
|
||||
|
||||
void GuiApplication::Run()
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#include "StatusBar.h"
|
||||
|
||||
StatusBar::StatusBar()
|
||||
{
|
||||
SetBackgroundColor(Color::Create(200, 200, 200));
|
||||
}
|
||||
|
||||
std::unique_ptr<StatusBar> StatusBar::Create()
|
||||
{
|
||||
return std::make_unique<StatusBar>();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class StatusBar : public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
StatusBar();
|
||||
|
||||
static std::unique_ptr<StatusBar> Create();
|
||||
};
|
||||
|
||||
using StatusBarUPtr = std::unique_ptr<StatusBar>;
|
52
src/client/TabbedPanelWidget.cpp
Normal file
52
src/client/TabbedPanelWidget.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "TabbedPanelWidget.h"
|
||||
#include "StackWidget.h"
|
||||
#include "HorizontalSpacer.h"
|
||||
#include "VerticalSpacer.h"
|
||||
#include "Button.h"
|
||||
|
||||
TabbedPanelWidget::TabbedPanelWidget()
|
||||
: mNavPanel(),
|
||||
mStack()
|
||||
{
|
||||
auto stack = StackWidget::Create();
|
||||
mStack = stack.get();
|
||||
|
||||
auto nav = HorizontalSpacer::Create();
|
||||
mNavPanel = nav.get();
|
||||
nav->SetSize({0, 0, 0, 0, 200, 0});
|
||||
|
||||
auto vertSpacer = VerticalSpacer::Create();
|
||||
vertSpacer->AddWidgetWithScale(std::move(nav), 1);
|
||||
vertSpacer->AddWidgetWithScale(std::move(stack), 4);
|
||||
AddWidget(std::move(vertSpacer));
|
||||
}
|
||||
|
||||
std::unique_ptr<TabbedPanelWidget> TabbedPanelWidget::Create()
|
||||
{
|
||||
return std::make_unique<TabbedPanelWidget>();
|
||||
}
|
||||
|
||||
StackWidget* TabbedPanelWidget::GetStack() const
|
||||
{
|
||||
return mStack;
|
||||
}
|
||||
|
||||
void TabbedPanelWidget::AddPanel(WidgetUPtr panel, const std::string& label)
|
||||
{
|
||||
auto button = Button::Create();
|
||||
button->SetLabel(label);
|
||||
button->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
button->SetMargin({1, 0, 0, 1});
|
||||
auto rawPanel = panel.get();
|
||||
auto onClick = [this, rawPanel](Widget*){
|
||||
if(this && rawPanel)
|
||||
{
|
||||
this->GetStack()->ShowChild(rawPanel);
|
||||
}
|
||||
};
|
||||
button->SetOnClickFunction(onClick);
|
||||
mStack->AddWidget(std::move(panel));
|
||||
mNavPanel->AddWidget(std::move(button));
|
||||
}
|
||||
|
||||
|
22
src/client/TabbedPanelWidget.h
Normal file
22
src/client/TabbedPanelWidget.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
#include "StackWidget.h"
|
||||
|
||||
class TabbedPanelWidget : public Widget
|
||||
{
|
||||
Widget* mNavPanel;
|
||||
StackWidget* mStack;
|
||||
|
||||
public:
|
||||
|
||||
TabbedPanelWidget();
|
||||
|
||||
static std::unique_ptr<TabbedPanelWidget> Create();
|
||||
|
||||
void AddPanel(WidgetUPtr panel, const std::string& label);
|
||||
|
||||
StackWidget* GetStack() const;
|
||||
};
|
||||
|
||||
using TabbedPanelWidgetUPtr = std::unique_ptr<TabbedPanelWidget>;
|
|
@ -1,59 +0,0 @@
|
|||
#include "TextEditorPanel.h"
|
||||
#include "HorizontalSpacer.h"
|
||||
#include "VerticalSpacer.h"
|
||||
|
||||
TextEditorPanel::TextEditorPanel()
|
||||
: mSaveFunction(),
|
||||
mTextBox()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TextEditorPanel::Initialize()
|
||||
{
|
||||
auto textEditorLabel = Label::Create();
|
||||
textEditorLabel->SetLabel("Text Editor");
|
||||
textEditorLabel->SetBackgroundColor(Color::Create(81, 89, 102));
|
||||
|
||||
auto textEditorBox = TextBox::Create();
|
||||
mTextBox = textEditorBox.get();
|
||||
|
||||
auto textEditorSaveButton = Button::Create();
|
||||
textEditorSaveButton->SetLabel("Save");
|
||||
textEditorSaveButton->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
if (mSaveFunction)
|
||||
{
|
||||
auto onSave = [this]()
|
||||
{
|
||||
if(this && mSaveFunction && mTextBox)
|
||||
{
|
||||
mSaveFunction(mTextBox->GetContent());
|
||||
};
|
||||
};
|
||||
textEditorSaveButton->SetOnClickFunction(onSave);
|
||||
}
|
||||
|
||||
auto textEditorClearButton = Button::Create();
|
||||
textEditorClearButton->SetLabel("Clear");
|
||||
textEditorClearButton->SetBackgroundColor(Color::Create(156, 156, 156));
|
||||
auto buttonSpacer = VerticalSpacer::Create();
|
||||
buttonSpacer->AddWidgetWithScale(std::move(textEditorSaveButton), 1);
|
||||
buttonSpacer->AddWidgetWithScale(std::move(textEditorClearButton), 1);
|
||||
|
||||
auto hSpacer = HorizontalSpacer::Create();
|
||||
hSpacer->AddWidgetWithScale(std::move(textEditorLabel), 1);
|
||||
hSpacer->AddWidgetWithScale(std::move(textEditorBox), 8);
|
||||
hSpacer->AddWidgetWithScale(std::move(buttonSpacer), 1);
|
||||
|
||||
AddWidget(std::move(hSpacer));
|
||||
}
|
||||
|
||||
std::unique_ptr<TextEditorPanel> TextEditorPanel::Create()
|
||||
{
|
||||
return std::make_unique<TextEditorPanel>();
|
||||
}
|
||||
|
||||
void TextEditorPanel::SetOnSaveFunction(saveFunc func)
|
||||
{
|
||||
mSaveFunction = func;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
#include "Button.h"
|
||||
#include "Label.h"
|
||||
#include "TextBox.h"
|
||||
|
||||
class TextEditorPanel : public Widget
|
||||
{
|
||||
using saveFunc = void (*)(const std::string& content);
|
||||
saveFunc mSaveFunction;
|
||||
TextBox* mTextBox;
|
||||
|
||||
public:
|
||||
|
||||
TextEditorPanel();
|
||||
|
||||
static std::unique_ptr<TextEditorPanel> Create();
|
||||
|
||||
void Initialize();
|
||||
|
||||
void SetOnSaveFunction(saveFunc func);
|
||||
};
|
||||
using TextEditorPanelUPtr = std::unique_ptr<TextEditorPanel>;
|
|
@ -0,0 +1,11 @@
|
|||
#include "TopBar.h"
|
||||
|
||||
TopBar::TopBar()
|
||||
{
|
||||
SetBackgroundColor(Color::Create(50, 50, 50));
|
||||
}
|
||||
|
||||
std::unique_ptr<TopBar> TopBar::Create()
|
||||
{
|
||||
return std::make_unique<TopBar>();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class TopBar : public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
TopBar();
|
||||
|
||||
static std::unique_ptr<TopBar> Create();
|
||||
};
|
||||
|
||||
using TopBarUPtr = std::unique_ptr<TopBar>;
|
16
src/client/audio_editor/AudioEditorView.cpp
Normal file
16
src/client/audio_editor/AudioEditorView.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "AudioEditorView.h"
|
||||
#include "Label.h"
|
||||
|
||||
AudioEditorView::AudioEditorView()
|
||||
{
|
||||
auto label = Label::Create();
|
||||
label->SetLabel("Audio Editor");
|
||||
label->SetBackgroundColor(Color::Create(200, 189, 160));
|
||||
label->SetMargin(1);
|
||||
AddWidget(std::move(label));
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioEditorView> AudioEditorView::Create()
|
||||
{
|
||||
return std::make_unique<AudioEditorView>();
|
||||
}
|
14
src/client/audio_editor/AudioEditorView.h
Normal file
14
src/client/audio_editor/AudioEditorView.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class AudioEditorView : public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
AudioEditorView();
|
||||
|
||||
static std::unique_ptr<AudioEditorView> Create();
|
||||
};
|
||||
|
||||
using AudioEditorViewUPtr = std::unique_ptr<AudioEditorView>;
|
16
src/client/image_editor/ImageEditorView.cpp
Normal file
16
src/client/image_editor/ImageEditorView.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "ImageEditorView.h"
|
||||
#include "Label.h"
|
||||
|
||||
ImageEditorView::ImageEditorView()
|
||||
{
|
||||
auto label = Label::Create();
|
||||
label->SetLabel("Image Editor");
|
||||
label->SetBackgroundColor(Color::Create(200, 189, 160));
|
||||
label->SetMargin(1);
|
||||
AddWidget(std::move(label));
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageEditorView> ImageEditorView::Create()
|
||||
{
|
||||
return std::make_unique<ImageEditorView>();
|
||||
}
|
14
src/client/image_editor/ImageEditorView.h
Normal file
14
src/client/image_editor/ImageEditorView.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class ImageEditorView : public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
ImageEditorView();
|
||||
|
||||
static std::unique_ptr<ImageEditorView> Create();
|
||||
};
|
||||
|
||||
using ImageEditorViewUPtr = std::unique_ptr<ImageEditorView>;
|
27
src/client/text_editor/PlainTextDocument.cpp
Normal file
27
src/client/text_editor/PlainTextDocument.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "PlainTextDocument.h"
|
||||
|
||||
PlainTextDocument::PlainTextDocument()
|
||||
: mContent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<PlainTextDocument> PlainTextDocument::Create()
|
||||
{
|
||||
return std::make_unique<PlainTextDocument>();
|
||||
}
|
||||
|
||||
std::string PlainTextDocument::GetContent() const
|
||||
{
|
||||
return mContent;
|
||||
}
|
||||
|
||||
void PlainTextDocument::SetContent(const std::string& content)
|
||||
{
|
||||
mContent = content;
|
||||
}
|
||||
|
||||
void PlainTextDocument::Clear()
|
||||
{
|
||||
mContent = "";
|
||||
}
|
24
src/client/text_editor/PlainTextDocument.h
Normal file
24
src/client/text_editor/PlainTextDocument.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class PlainTextDocument
|
||||
{
|
||||
std::string mContent;
|
||||
|
||||
public:
|
||||
|
||||
PlainTextDocument();
|
||||
|
||||
static std::unique_ptr<PlainTextDocument> Create();
|
||||
|
||||
std::string GetContent() const;
|
||||
|
||||
void SetContent(const std::string& content);
|
||||
|
||||
void Clear();
|
||||
|
||||
};
|
||||
|
||||
using PlainTextDocumentUPtr = std::unique_ptr<PlainTextDocument>;
|
60
src/client/text_editor/TextEditorController.cpp
Normal file
60
src/client/text_editor/TextEditorController.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include "TextEditorController.h"
|
||||
#include "File.h"
|
||||
|
||||
TextEditorController::TextEditorController()
|
||||
: mModel(TextEditorModel::Create()),
|
||||
mSavePath(),
|
||||
mLoadPath()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<TextEditorController> TextEditorController::Create()
|
||||
{
|
||||
return std::make_unique<TextEditorController>();
|
||||
}
|
||||
|
||||
void TextEditorController::SetContent(const std::string& content)
|
||||
{
|
||||
mModel->GetDocument()->SetContent(content);
|
||||
}
|
||||
|
||||
std::string TextEditorController::GetContent() const
|
||||
{
|
||||
return mModel->GetDocument()->GetContent();
|
||||
}
|
||||
|
||||
void TextEditorController::OnSave()
|
||||
{
|
||||
if(mSavePath.empty()) return;
|
||||
File outfile(mSavePath);
|
||||
outfile.SetAccessMode(File::AccessMode::Write);
|
||||
outfile.Open();
|
||||
outfile.WriteText(mModel->GetDocument()->GetContent());
|
||||
outfile.Close();
|
||||
}
|
||||
|
||||
void TextEditorController::OnLoad()
|
||||
{
|
||||
if(mLoadPath.empty()) return;
|
||||
File infile(mLoadPath);
|
||||
infile.SetAccessMode(File::AccessMode::Read);
|
||||
infile.Open();
|
||||
mModel->GetDocument()->SetContent(infile.ReadText());
|
||||
infile.Close();
|
||||
}
|
||||
|
||||
void TextEditorController::SetSavePath(const std::filesystem::path& path)
|
||||
{
|
||||
mSavePath = path;
|
||||
}
|
||||
|
||||
void TextEditorController::SetLoadPath(const std::filesystem::path& path)
|
||||
{
|
||||
mLoadPath = path;
|
||||
}
|
||||
|
||||
void TextEditorController::OnClear()
|
||||
{
|
||||
mModel->GetDocument()->Clear();
|
||||
}
|
33
src/client/text_editor/TextEditorController.h
Normal file
33
src/client/text_editor/TextEditorController.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
#include "TextEditorModel.h"
|
||||
|
||||
class TextEditorController
|
||||
{
|
||||
TextEditorModelUPtr mModel;
|
||||
std::filesystem::path mSavePath;
|
||||
std::filesystem::path mLoadPath;
|
||||
|
||||
public:
|
||||
|
||||
TextEditorController();
|
||||
|
||||
static std::unique_ptr<TextEditorController> Create();
|
||||
|
||||
void OnSave();
|
||||
|
||||
void OnClear();
|
||||
|
||||
void OnLoad();
|
||||
|
||||
std::string GetContent() const;
|
||||
|
||||
void SetContent(const std::string& content);
|
||||
|
||||
void SetSavePath(const std::filesystem::path& path);
|
||||
|
||||
void SetLoadPath(const std::filesystem::path& path);
|
||||
};
|
||||
|
||||
using TextEditorControllerUPtr = std::unique_ptr<TextEditorController>;
|
17
src/client/text_editor/TextEditorModel.cpp
Normal file
17
src/client/text_editor/TextEditorModel.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "TextEditorModel.h"
|
||||
|
||||
TextEditorModel::TextEditorModel()
|
||||
: mDocument(PlainTextDocument::Create())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<TextEditorModel> TextEditorModel::Create()
|
||||
{
|
||||
return std::make_unique<TextEditorModel>();
|
||||
}
|
||||
|
||||
PlainTextDocument* TextEditorModel::GetDocument() const
|
||||
{
|
||||
return mDocument.get();
|
||||
}
|
19
src/client/text_editor/TextEditorModel.h
Normal file
19
src/client/text_editor/TextEditorModel.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include "PlainTextDocument.h"
|
||||
#include <memory>
|
||||
|
||||
class TextEditorModel
|
||||
{
|
||||
PlainTextDocumentUPtr mDocument;
|
||||
|
||||
public:
|
||||
|
||||
TextEditorModel();
|
||||
|
||||
static std::unique_ptr<TextEditorModel> Create();
|
||||
|
||||
PlainTextDocument* GetDocument() const;
|
||||
};
|
||||
|
||||
using TextEditorModelUPtr = std::unique_ptr<TextEditorModel>;
|
83
src/client/text_editor/TextEditorView.cpp
Normal file
83
src/client/text_editor/TextEditorView.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#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::Create(181, 189, 200));
|
||||
label->SetMargin(1);
|
||||
|
||||
auto textBox = TextBox::Create();
|
||||
mTextBox = textBox.get();
|
||||
|
||||
auto saveButton = Button::Create();
|
||||
saveButton->SetLabel("Save");
|
||||
saveButton->SetBackgroundColor(Color::Create(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::Create(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::Create(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>();
|
||||
}
|
25
src/client/text_editor/TextEditorView.h
Normal file
25
src/client/text_editor/TextEditorView.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
#include "Button.h"
|
||||
#include "Label.h"
|
||||
#include "TextBox.h"
|
||||
#include "TextEditorController.h"
|
||||
#include <functional>
|
||||
|
||||
class TextEditorView : public Widget
|
||||
{
|
||||
TextBox* mTextBox;
|
||||
TextEditorControllerUPtr mController;
|
||||
|
||||
public:
|
||||
|
||||
TextEditorView();
|
||||
|
||||
static std::unique_ptr<TextEditorView> Create();
|
||||
|
||||
TextEditorController* GetController();
|
||||
|
||||
void Initialize();
|
||||
};
|
||||
using TextEditorViewUPtr = std::unique_ptr<TextEditorView>;
|
16
src/client/web_client/WebClientView.cpp
Normal file
16
src/client/web_client/WebClientView.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "WebClientView.h"
|
||||
#include "Label.h"
|
||||
|
||||
WebClientView::WebClientView()
|
||||
{
|
||||
auto label = Label::Create();
|
||||
label->SetLabel("Web Client");
|
||||
label->SetBackgroundColor(Color::Create(200, 189, 160));
|
||||
label->SetMargin(1);
|
||||
AddWidget(std::move(label));
|
||||
}
|
||||
|
||||
std::unique_ptr<WebClientView> WebClientView::Create()
|
||||
{
|
||||
return std::make_unique<WebClientView>();
|
||||
}
|
14
src/client/web_client/WebClientView.h
Normal file
14
src/client/web_client/WebClientView.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class WebClientView : public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
WebClientView();
|
||||
|
||||
static std::unique_ptr<WebClientView> Create();
|
||||
};
|
||||
|
||||
using WebClientViewUPtr = std::unique_ptr<WebClientView>;
|
Loading…
Add table
Add a link
Reference in a new issue