From ee51f3ee092a59949251277e4787b107555f4448 Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Sat, 27 Jun 2020 10:47:30 +0100 Subject: [PATCH] Set up stacked widget. --- src/client/CMakeLists.txt | 22 ++++- src/client/GuiApplication.cpp | 71 +++++++--------- src/client/LeftNavPanel.cpp | 0 src/client/LeftNavPanel.h | 0 src/client/MainPanel.cpp | 0 src/client/MainPanel.h | 0 src/client/StatusBar.cpp | 11 +++ src/client/StatusBar.h | 14 ++++ src/client/TabbedPanelWidget.cpp | 52 ++++++++++++ src/client/TabbedPanelWidget.h | 22 +++++ src/client/TextEditorPanel.cpp | 59 ------------- src/client/TextEditorPanel.h | 24 ------ src/client/TopBar.cpp | 11 +++ src/client/TopBar.h | 14 ++++ src/client/audio_editor/AudioEditorView.cpp | 16 ++++ src/client/audio_editor/AudioEditorView.h | 14 ++++ src/client/image_editor/ImageEditorView.cpp | 16 ++++ src/client/image_editor/ImageEditorView.h | 14 ++++ src/client/text_editor/PlainTextDocument.cpp | 27 ++++++ src/client/text_editor/PlainTextDocument.h | 24 ++++++ .../text_editor/TextEditorController.cpp | 60 ++++++++++++++ src/client/text_editor/TextEditorController.h | 33 ++++++++ src/client/text_editor/TextEditorModel.cpp | 17 ++++ src/client/text_editor/TextEditorModel.h | 19 +++++ src/client/text_editor/TextEditorView.cpp | 83 +++++++++++++++++++ src/client/text_editor/TextEditorView.h | 25 ++++++ src/client/web_client/WebClientView.cpp | 16 ++++ src/client/web_client/WebClientView.h | 14 ++++ src/console/MainApplication.cpp | 5 ++ src/console/MainApplication.h | 2 + src/core/file_utilities/File.cpp | 13 +++ src/core/file_utilities/File.h | 4 + src/ui_elements/CMakeLists.txt | 1 + src/ui_elements/desktop_elements/Window.cpp | 2 +- src/ui_elements/widgets/Button.cpp | 19 +++-- src/ui_elements/widgets/Button.h | 4 +- src/ui_elements/widgets/HorizontalSpacer.cpp | 13 +-- src/ui_elements/widgets/Label.cpp | 9 +- src/ui_elements/widgets/StackWidget.cpp | 26 ++++++ src/ui_elements/widgets/StackWidget.h | 15 ++++ src/ui_elements/widgets/TextBox.cpp | 14 ++-- src/ui_elements/widgets/VerticalSpacer.cpp | 6 +- src/ui_elements/widgets/Widget.cpp | 70 +++++++++++----- src/ui_elements/widgets/Widget.h | 47 ++++++++--- .../widgets/elements/TextElement.cpp | 23 ++++- .../widgets/elements/TextElement.h | 11 ++- src/windows/managers/DesktopManager.cpp | 5 +- .../ui_interfaces/x11/XcbInterface.cpp | 22 ++++- src/windows/ui_interfaces/x11/XcbInterface.h | 2 + .../ui_interfaces/x11/XcbTextInterface.cpp | 9 +- .../ui_interfaces/x11/XcbTextInterface.h | 3 +- 51 files changed, 808 insertions(+), 195 deletions(-) delete mode 100644 src/client/LeftNavPanel.cpp delete mode 100644 src/client/LeftNavPanel.h delete mode 100644 src/client/MainPanel.cpp delete mode 100644 src/client/MainPanel.h create mode 100644 src/client/TabbedPanelWidget.cpp create mode 100644 src/client/TabbedPanelWidget.h delete mode 100644 src/client/TextEditorPanel.cpp delete mode 100644 src/client/TextEditorPanel.h create mode 100644 src/client/audio_editor/AudioEditorView.cpp create mode 100644 src/client/audio_editor/AudioEditorView.h create mode 100644 src/client/image_editor/ImageEditorView.cpp create mode 100644 src/client/image_editor/ImageEditorView.h create mode 100644 src/client/text_editor/PlainTextDocument.cpp create mode 100644 src/client/text_editor/PlainTextDocument.h create mode 100644 src/client/text_editor/TextEditorController.cpp create mode 100644 src/client/text_editor/TextEditorController.h create mode 100644 src/client/text_editor/TextEditorModel.cpp create mode 100644 src/client/text_editor/TextEditorModel.h create mode 100644 src/client/text_editor/TextEditorView.cpp create mode 100644 src/client/text_editor/TextEditorView.h create mode 100644 src/client/web_client/WebClientView.cpp create mode 100644 src/client/web_client/WebClientView.h create mode 100644 src/ui_elements/widgets/StackWidget.cpp create mode 100644 src/ui_elements/widgets/StackWidget.h diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index c0e2fab..def6d86 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -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" ) \ No newline at end of file diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp index 066ef46..bcb41f5 100644 --- a/src/client/GuiApplication.cpp +++ b/src/client/GuiApplication.cpp @@ -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 +#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() diff --git a/src/client/LeftNavPanel.cpp b/src/client/LeftNavPanel.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/client/LeftNavPanel.h b/src/client/LeftNavPanel.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/client/MainPanel.cpp b/src/client/MainPanel.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/client/MainPanel.h b/src/client/MainPanel.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/client/StatusBar.cpp b/src/client/StatusBar.cpp index e69de29..79242c6 100644 --- a/src/client/StatusBar.cpp +++ b/src/client/StatusBar.cpp @@ -0,0 +1,11 @@ +#include "StatusBar.h" + +StatusBar::StatusBar() +{ + SetBackgroundColor(Color::Create(200, 200, 200)); +} + +std::unique_ptr StatusBar::Create() +{ + return std::make_unique(); +} diff --git a/src/client/StatusBar.h b/src/client/StatusBar.h index e69de29..a7747d2 100644 --- a/src/client/StatusBar.h +++ b/src/client/StatusBar.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Widget.h" + +class StatusBar : public Widget +{ +public: + + StatusBar(); + + static std::unique_ptr Create(); +}; + +using StatusBarUPtr = std::unique_ptr; diff --git a/src/client/TabbedPanelWidget.cpp b/src/client/TabbedPanelWidget.cpp new file mode 100644 index 0000000..d51db5d --- /dev/null +++ b/src/client/TabbedPanelWidget.cpp @@ -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::Create() +{ + return std::make_unique(); +} + +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)); +} + + diff --git a/src/client/TabbedPanelWidget.h b/src/client/TabbedPanelWidget.h new file mode 100644 index 0000000..50c5ba7 --- /dev/null +++ b/src/client/TabbedPanelWidget.h @@ -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 Create(); + + void AddPanel(WidgetUPtr panel, const std::string& label); + + StackWidget* GetStack() const; +}; + +using TabbedPanelWidgetUPtr = std::unique_ptr; diff --git a/src/client/TextEditorPanel.cpp b/src/client/TextEditorPanel.cpp deleted file mode 100644 index c3cc8be..0000000 --- a/src/client/TextEditorPanel.cpp +++ /dev/null @@ -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::Create() -{ - return std::make_unique(); -} - -void TextEditorPanel::SetOnSaveFunction(saveFunc func) -{ - mSaveFunction = func; -} diff --git a/src/client/TextEditorPanel.h b/src/client/TextEditorPanel.h deleted file mode 100644 index e4c3a6d..0000000 --- a/src/client/TextEditorPanel.h +++ /dev/null @@ -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 Create(); - - void Initialize(); - - void SetOnSaveFunction(saveFunc func); -}; -using TextEditorPanelUPtr = std::unique_ptr; diff --git a/src/client/TopBar.cpp b/src/client/TopBar.cpp index e69de29..c5c8c77 100644 --- a/src/client/TopBar.cpp +++ b/src/client/TopBar.cpp @@ -0,0 +1,11 @@ +#include "TopBar.h" + +TopBar::TopBar() +{ + SetBackgroundColor(Color::Create(50, 50, 50)); +} + +std::unique_ptr TopBar::Create() +{ + return std::make_unique(); +} diff --git a/src/client/TopBar.h b/src/client/TopBar.h index e69de29..f3a9574 100644 --- a/src/client/TopBar.h +++ b/src/client/TopBar.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Widget.h" + +class TopBar : public Widget +{ +public: + + TopBar(); + + static std::unique_ptr Create(); +}; + +using TopBarUPtr = std::unique_ptr; diff --git a/src/client/audio_editor/AudioEditorView.cpp b/src/client/audio_editor/AudioEditorView.cpp new file mode 100644 index 0000000..bd637ec --- /dev/null +++ b/src/client/audio_editor/AudioEditorView.cpp @@ -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::Create() +{ + return std::make_unique(); +} diff --git a/src/client/audio_editor/AudioEditorView.h b/src/client/audio_editor/AudioEditorView.h new file mode 100644 index 0000000..d5de4ad --- /dev/null +++ b/src/client/audio_editor/AudioEditorView.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Widget.h" + +class AudioEditorView : public Widget +{ +public: + + AudioEditorView(); + + static std::unique_ptr Create(); +}; + +using AudioEditorViewUPtr = std::unique_ptr; diff --git a/src/client/image_editor/ImageEditorView.cpp b/src/client/image_editor/ImageEditorView.cpp new file mode 100644 index 0000000..c553d69 --- /dev/null +++ b/src/client/image_editor/ImageEditorView.cpp @@ -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::Create() +{ + return std::make_unique(); +} diff --git a/src/client/image_editor/ImageEditorView.h b/src/client/image_editor/ImageEditorView.h new file mode 100644 index 0000000..23c6fb2 --- /dev/null +++ b/src/client/image_editor/ImageEditorView.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Widget.h" + +class ImageEditorView : public Widget +{ +public: + + ImageEditorView(); + + static std::unique_ptr Create(); +}; + +using ImageEditorViewUPtr = std::unique_ptr; diff --git a/src/client/text_editor/PlainTextDocument.cpp b/src/client/text_editor/PlainTextDocument.cpp new file mode 100644 index 0000000..18e5782 --- /dev/null +++ b/src/client/text_editor/PlainTextDocument.cpp @@ -0,0 +1,27 @@ +#include "PlainTextDocument.h" + +PlainTextDocument::PlainTextDocument() + : mContent() +{ + +} + +std::unique_ptr PlainTextDocument::Create() +{ + return std::make_unique(); +} + +std::string PlainTextDocument::GetContent() const +{ + return mContent; +} + +void PlainTextDocument::SetContent(const std::string& content) +{ + mContent = content; +} + +void PlainTextDocument::Clear() +{ + mContent = ""; +} diff --git a/src/client/text_editor/PlainTextDocument.h b/src/client/text_editor/PlainTextDocument.h new file mode 100644 index 0000000..ae32420 --- /dev/null +++ b/src/client/text_editor/PlainTextDocument.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +class PlainTextDocument +{ + std::string mContent; + +public: + + PlainTextDocument(); + + static std::unique_ptr Create(); + + std::string GetContent() const; + + void SetContent(const std::string& content); + + void Clear(); + +}; + +using PlainTextDocumentUPtr = std::unique_ptr; diff --git a/src/client/text_editor/TextEditorController.cpp b/src/client/text_editor/TextEditorController.cpp new file mode 100644 index 0000000..d950311 --- /dev/null +++ b/src/client/text_editor/TextEditorController.cpp @@ -0,0 +1,60 @@ +#include "TextEditorController.h" +#include "File.h" + +TextEditorController::TextEditorController() + : mModel(TextEditorModel::Create()), + mSavePath(), + mLoadPath() +{ + +} + +std::unique_ptr TextEditorController::Create() +{ + return std::make_unique(); +} + +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(); +} diff --git a/src/client/text_editor/TextEditorController.h b/src/client/text_editor/TextEditorController.h new file mode 100644 index 0000000..2a62067 --- /dev/null +++ b/src/client/text_editor/TextEditorController.h @@ -0,0 +1,33 @@ +#pragma once +#include +#include +#include "TextEditorModel.h" + +class TextEditorController +{ + TextEditorModelUPtr mModel; + std::filesystem::path mSavePath; + std::filesystem::path mLoadPath; + +public: + + TextEditorController(); + + static std::unique_ptr 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; diff --git a/src/client/text_editor/TextEditorModel.cpp b/src/client/text_editor/TextEditorModel.cpp new file mode 100644 index 0000000..9e299ec --- /dev/null +++ b/src/client/text_editor/TextEditorModel.cpp @@ -0,0 +1,17 @@ +#include "TextEditorModel.h" + +TextEditorModel::TextEditorModel() + : mDocument(PlainTextDocument::Create()) +{ + +} + +std::unique_ptr TextEditorModel::Create() +{ + return std::make_unique(); +} + +PlainTextDocument* TextEditorModel::GetDocument() const +{ + return mDocument.get(); +} diff --git a/src/client/text_editor/TextEditorModel.h b/src/client/text_editor/TextEditorModel.h new file mode 100644 index 0000000..39289e5 --- /dev/null +++ b/src/client/text_editor/TextEditorModel.h @@ -0,0 +1,19 @@ +#pragma once + +#include "PlainTextDocument.h" +#include + +class TextEditorModel +{ + PlainTextDocumentUPtr mDocument; + +public: + + TextEditorModel(); + + static std::unique_ptr Create(); + + PlainTextDocument* GetDocument() const; +}; + +using TextEditorModelUPtr = std::unique_ptr; diff --git a/src/client/text_editor/TextEditorView.cpp b/src/client/text_editor/TextEditorView.cpp new file mode 100644 index 0000000..0294bab --- /dev/null +++ b/src/client/text_editor/TextEditorView.cpp @@ -0,0 +1,83 @@ +#include "HorizontalSpacer.h" +#include "TextEditorView.h" +#include "VerticalSpacer.h" +#include + +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::Create() +{ + return std::make_unique(); +} diff --git a/src/client/text_editor/TextEditorView.h b/src/client/text_editor/TextEditorView.h new file mode 100644 index 0000000..68d80ae --- /dev/null +++ b/src/client/text_editor/TextEditorView.h @@ -0,0 +1,25 @@ +#pragma once + +#include "Widget.h" +#include "Button.h" +#include "Label.h" +#include "TextBox.h" +#include "TextEditorController.h" +#include + +class TextEditorView : public Widget +{ + TextBox* mTextBox; + TextEditorControllerUPtr mController; + +public: + + TextEditorView(); + + static std::unique_ptr Create(); + + TextEditorController* GetController(); + + void Initialize(); +}; +using TextEditorViewUPtr = std::unique_ptr; diff --git a/src/client/web_client/WebClientView.cpp b/src/client/web_client/WebClientView.cpp new file mode 100644 index 0000000..f1c2f5f --- /dev/null +++ b/src/client/web_client/WebClientView.cpp @@ -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::Create() +{ + return std::make_unique(); +} diff --git a/src/client/web_client/WebClientView.h b/src/client/web_client/WebClientView.h new file mode 100644 index 0000000..32cd128 --- /dev/null +++ b/src/client/web_client/WebClientView.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Widget.h" + +class WebClientView : public Widget +{ +public: + + WebClientView(); + + static std::unique_ptr Create(); +}; + +using WebClientViewUPtr = std::unique_ptr; diff --git a/src/console/MainApplication.cpp b/src/console/MainApplication.cpp index df489b3..b2ec240 100644 --- a/src/console/MainApplication.cpp +++ b/src/console/MainApplication.cpp @@ -98,6 +98,11 @@ void MainApplication::ConvertDocument(const std::string& inputPath, const std::s converter.Convert(&input_file, &output_file); } +CommandLineArgs* MainApplication::GetCommandLineArgs() const +{ + return mCommandLineArgs.get(); +} + void MainApplication::ShutDown() { mDatabaseManager->OnShutDown(); diff --git a/src/console/MainApplication.h b/src/console/MainApplication.h index 3ab6977..7c58723 100644 --- a/src/console/MainApplication.h +++ b/src/console/MainApplication.h @@ -30,6 +30,8 @@ public: void ShutDown(); + CommandLineArgs* GetCommandLineArgs() const; + static std::shared_ptr Create(); private: diff --git a/src/core/file_utilities/File.cpp b/src/core/file_utilities/File.cpp index 940da13..fe4443e 100644 --- a/src/core/file_utilities/File.cpp +++ b/src/core/file_utilities/File.cpp @@ -1,5 +1,6 @@ #include "File.h" #include "FileLogger.h" +#include File::File(std::filesystem::path path) : mFullPath(path), @@ -62,6 +63,18 @@ FileFormat::Format File::InferFormat() const return FileFormat::InferFormat(extension); } +void File::WriteText(const std::string& text) +{ + (*mOutHandle) << text; +} + +std::string File::ReadText() +{ + std::string str((std::istreambuf_iterator(*mInHandle)), + std::istreambuf_iterator()); + return str; +} + bool File::PathExists() const { return std::filesystem::exists(mFullPath); diff --git a/src/core/file_utilities/File.h b/src/core/file_utilities/File.h index aad1223..da4c101 100644 --- a/src/core/file_utilities/File.h +++ b/src/core/file_utilities/File.h @@ -32,6 +32,10 @@ public: std::ofstream* GetOutHandle() const; + void WriteText(const std::string& text); + + std::string ReadText(); + bool PathExists() const; void SetAccessMode(AccessMode mode); diff --git a/src/ui_elements/CMakeLists.txt b/src/ui_elements/CMakeLists.txt index f3864d0..963f7f3 100644 --- a/src/ui_elements/CMakeLists.txt +++ b/src/ui_elements/CMakeLists.txt @@ -11,6 +11,7 @@ list(APPEND ui_elements_LIB_INCLUDES widgets/Label.cpp widgets/HorizontalSpacer.cpp widgets/VerticalSpacer.cpp + widgets/StackWidget.cpp widgets/TextBox.cpp widgets/elements/GeometryElement.cpp widgets/elements/RectangleElement.cpp diff --git a/src/ui_elements/desktop_elements/Window.cpp b/src/ui_elements/desktop_elements/Window.cpp index cb0f092..596f7b2 100644 --- a/src/ui_elements/desktop_elements/Window.cpp +++ b/src/ui_elements/desktop_elements/Window.cpp @@ -37,7 +37,7 @@ void Window::OnKeyboardEvent(const KeyboardEvent* event) void Window::OnPaint(const PaintEvent* event) { mLayers.clear(); - mWidget->SetSize(mWidth, mHeight); + mWidget->SetBounds(mWidth, mHeight); mWidget->OnPaintEvent(event); auto layers = mWidget->GetLayers(); diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp index 3df5c59..44afa78 100644 --- a/src/ui_elements/widgets/Button.cpp +++ b/src/ui_elements/widgets/Button.cpp @@ -4,9 +4,10 @@ Button::Button() : Widget(), mLabel(), + mCachedColor(255, 255, 255), mClickFunc() { - + mClickedColor = Color::Create(180, 180, 180); } std::unique_ptr