diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 4f900a6..c0e2fab 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -1,4 +1,4 @@ -list(APPEND client_LIB_INCLUDES GuiApplication.cpp) +list(APPEND client_LIB_INCLUDES GuiApplication.cpp TextEditorPanel.cpp) add_library(client SHARED ${client_LIB_INCLUDES}) diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp index fef6b36..066ef46 100644 --- a/src/client/GuiApplication.cpp +++ b/src/client/GuiApplication.cpp @@ -2,6 +2,7 @@ #include "Widget.h" #include "HorizontalSpacer.h" +#include "VerticalSpacer.h" #include "TextBox.h" #include "Button.h" #include "Label.h" @@ -10,6 +11,8 @@ #include "Window.h" #include "TextElement.h" #include "WindowManager.h" +#include "TextEditorPanel.h" +#include GuiApplication::GuiApplication() : AbstractDesktopApp(), @@ -29,28 +32,55 @@ void GuiApplication::SetMainApplication(MainApplicationPtr app) mMainApplication = app; } +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 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; + }); + textEditor->Initialize(); + + auto vertSpacer = VerticalSpacer::Create(); + vertSpacer->AddWidgetWithScale(std::move(leftSpacer), 1); + vertSpacer->AddWidgetWithScale(std::move(textEditor), 4); + + mainWindow->AddWidget(std::move(vertSpacer)); +} + void GuiApplication::Run() { auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow(); + SetUpWidget(); - mainWindow->SetSize(800, 600); - - auto label = Label::Create(); - label->SetLabel("Type text!!"); - label->SetBackgroundColor(Color::Create(0, 200, 200)); - - auto textBox = TextBox::Create(); - - auto button = Button::Create(); - button->SetLabel("Save"); - button->SetBackgroundColor(Color::Create(0, 0, 200)); - - auto spacer = HorizontalSpacer::Create(); - spacer->AddWidget(std::move(label)); - spacer->AddWidget(std::move(textBox)); - spacer->AddWidget(std::move(button)); - - mainWindow->AddWidget(std::move(spacer)); mDesktopManager->SetKeyboard(XcbKeyboard::Create()); bool useOpenGl = false; @@ -63,9 +93,6 @@ void GuiApplication::Run() { window_interface.CreateOpenGlDrawable(mainWindow); } - window_interface.Loop(mDesktopManager.get()); - window_interface.ShutDown(); - } diff --git a/src/client/GuiApplication.h b/src/client/GuiApplication.h index 27a659c..8373fa0 100644 --- a/src/client/GuiApplication.h +++ b/src/client/GuiApplication.h @@ -23,4 +23,6 @@ public: void SetMainApplication(MainApplicationPtr app); void Run(); + + void SetUpWidget(); }; diff --git a/src/client/LeftNavPanel.cpp b/src/client/LeftNavPanel.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/client/LeftNavPanel.h b/src/client/LeftNavPanel.h new file mode 100644 index 0000000..e69de29 diff --git a/src/client/MainPanel.cpp b/src/client/MainPanel.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/client/MainPanel.h b/src/client/MainPanel.h new file mode 100644 index 0000000..e69de29 diff --git a/src/client/StatusBar.cpp b/src/client/StatusBar.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/client/StatusBar.h b/src/client/StatusBar.h new file mode 100644 index 0000000..e69de29 diff --git a/src/client/TextEditorPanel.cpp b/src/client/TextEditorPanel.cpp new file mode 100644 index 0000000..c3cc8be --- /dev/null +++ b/src/client/TextEditorPanel.cpp @@ -0,0 +1,59 @@ +#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 new file mode 100644 index 0000000..e4c3a6d --- /dev/null +++ b/src/client/TextEditorPanel.h @@ -0,0 +1,24 @@ +#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 new file mode 100644 index 0000000..e69de29 diff --git a/src/client/TopBar.h b/src/client/TopBar.h new file mode 100644 index 0000000..e69de29 diff --git a/src/ui_elements/CMakeLists.txt b/src/ui_elements/CMakeLists.txt index 37a3cb0..f3864d0 100644 --- a/src/ui_elements/CMakeLists.txt +++ b/src/ui_elements/CMakeLists.txt @@ -10,6 +10,7 @@ list(APPEND ui_elements_LIB_INCLUDES widgets/Button.cpp widgets/Label.cpp widgets/HorizontalSpacer.cpp + widgets/VerticalSpacer.cpp widgets/TextBox.cpp widgets/elements/GeometryElement.cpp widgets/elements/RectangleElement.cpp diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp index e077008..3df5c59 100644 --- a/src/ui_elements/widgets/Button.cpp +++ b/src/ui_elements/widgets/Button.cpp @@ -3,7 +3,8 @@ Button::Button() : Widget(), - mLabel() + mLabel(), + mClickFunc() { } @@ -13,6 +14,11 @@ std::unique_ptr