diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index a760ff2..979f54a 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -4,13 +4,15 @@ list(APPEND TARGET_HEADERS TopBar.h StatusBar.h GuiApplication.h - TabbedPanelWidget.h) + TabbedPanelWidget.h + TopBarMenu.h) list(APPEND TARGET_SOURCES TopBar.cpp StatusBar.cpp GuiApplication.cpp - TabbedPanelWidget.cpp) + TabbedPanelWidget.cpp + TopBarMenu.cpp) add_library(${MODULE_NAME} SHARED ${TARGET_SOURCES} ${TARGET_HEADERS}) diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp index 0f02d7a..672d0a9 100644 --- a/src/client/GuiApplication.cpp +++ b/src/client/GuiApplication.cpp @@ -7,6 +7,7 @@ #include "FontsManager.h" #include "MainApplication.h" #include "AbstractUiInterface.h" +#include "Widget.h" #include "FileLogger.h" diff --git a/src/client/GuiApplication.h b/src/client/GuiApplication.h index bd99a3a..3b5e1cc 100644 --- a/src/client/GuiApplication.h +++ b/src/client/GuiApplication.h @@ -21,6 +21,11 @@ public: void run(); + AbstractUIInterface* getUiInterface() const override + { + return mUiInterface.get(); + } + void setUiInterfaceBackend(UiInterfaceFactory::Backend backend); protected: diff --git a/src/client/TopBar.cpp b/src/client/TopBar.cpp index ea5c081..b746951 100644 --- a/src/client/TopBar.cpp +++ b/src/client/TopBar.cpp @@ -1,10 +1,36 @@ #include "TopBar.h" #include "Color.h" +#include "Theme.h" + +#include "Button.h" +#include "TopBarMenu.h" TopBar::TopBar() { - setBackgroundColor(Color(50, 50, 50)); + setBackgroundColor(Theme::getBackgroundPrimary()); + + auto fileButton = Button::Create(); + fileButton->setLabel("File"); + fileButton->setBackgroundColor(Theme::getBackgroundPrimary()); + fileButton->setMargin(2); + fileButton->setMaxWidth(60); + + auto onClick = [this](Widget* self){ + if(this) + { + auto menu = std::make_unique(); + auto window = getTopLevelWindow(); + window->addPopup(std::move(menu)); + }; + }; + fileButton->setOnClickFunction(onClick); + addWidget(std::move(fileButton)); +} + +TopBar::~TopBar() +{ + } std::unique_ptr TopBar::Create() diff --git a/src/client/TopBar.h b/src/client/TopBar.h index f3a9574..b07227a 100644 --- a/src/client/TopBar.h +++ b/src/client/TopBar.h @@ -2,12 +2,15 @@ #include "Widget.h" +class TopBarMenu; + class TopBar : public Widget { public: - TopBar(); + ~TopBar(); + static std::unique_ptr Create(); }; diff --git a/src/client/TopBarMenu.cpp b/src/client/TopBarMenu.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/client/TopBarMenu.h b/src/client/TopBarMenu.h new file mode 100644 index 0000000..c0bd28d --- /dev/null +++ b/src/client/TopBarMenu.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Widget.h" + +#include "Window.h" + +class TopBarMenu : public Widget +{ +public: + void popupFrom(Widget* parent) + { + auto window = parent->getTopLevelWindow(); + + + } +}; diff --git a/src/ui_elements/desktop_elements/Window.cpp b/src/ui_elements/desktop_elements/Window.cpp index a5e5f60..01f8b06 100644 --- a/src/ui_elements/desktop_elements/Window.cpp +++ b/src/ui_elements/desktop_elements/Window.cpp @@ -30,6 +30,7 @@ Window::Window() mWidth = 800; mHeight = 600; mWidget->setBounds(mWidth, mHeight); + mWidget->setWindow(this); } Window::~Window() @@ -81,6 +82,7 @@ void Window::setWidget(WidgetPtr widget) } mWidget = std::move(widget); mWidget->setBounds(mWidth, mHeight); + mWidget->setWindow(this); } IPlatformWindow* Window::getPlatformWindow() const diff --git a/src/ui_elements/desktop_elements/Window.h b/src/ui_elements/desktop_elements/Window.h index 540a573..bf44a41 100644 --- a/src/ui_elements/desktop_elements/Window.h +++ b/src/ui_elements/desktop_elements/Window.h @@ -6,6 +6,7 @@ #include #include #include +#include class PaintEvent; class MouseEvent; @@ -30,6 +31,8 @@ class Window : public DrawingSurface public: + using onPopupFunc = std::function popup)>; + Window(); ~Window(); @@ -72,11 +75,37 @@ public: return mTitle; } + void addPopup(std::unique_ptr popupWidget) + { + if (mPopupFunc) + { + mPopupFunc(this, std::move(popupWidget)); + } + } + + void setPopupHandler(onPopupFunc func) + { + mPopupFunc = func; + } + + void setParent(Window* parent) + { + mParent = parent; + } + + Window* getParent() const + { + return mParent; + } + private: WidgetPtr mWidget {nullptr}; std::string mTitle; IPlatformWindowPtr mPlatformWindow {nullptr}; std::unique_ptr mDrawingContext; + + onPopupFunc mPopupFunc; + Window* mParent{nullptr}; }; } diff --git a/src/ui_elements/style/Theme.cpp b/src/ui_elements/style/Theme.cpp index 2b579f2..b28f214 100644 --- a/src/ui_elements/style/Theme.cpp +++ b/src/ui_elements/style/Theme.cpp @@ -2,7 +2,7 @@ Color Theme::getBackgroundPrimary() { - return {217, 217, 217}; + return {245, 245, 245}; } Color Theme::getBannerBackground() diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp index 267076c..e556fc9 100644 --- a/src/ui_elements/widgets/Button.cpp +++ b/src/ui_elements/widgets/Button.cpp @@ -18,6 +18,11 @@ Button::Button() mName = "Button"; } +Button::~Button() +{ + +} + std::unique_ptr