Initial popup window.

This commit is contained in:
James Grogan 2022-12-02 13:44:52 +00:00
parent f16dd7c0d9
commit 70220fc6e9
22 changed files with 253 additions and 15 deletions

View file

@ -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

View file

@ -6,6 +6,7 @@
#include <vector>
#include <cstdint>
#include <string>
#include <functional>
class PaintEvent;
class MouseEvent;
@ -30,6 +31,8 @@ class Window : public DrawingSurface
public:
using onPopupFunc = std::function<void(mt::Window* parent, std::unique_ptr<Widget> popup)>;
Window();
~Window();
@ -72,11 +75,37 @@ public:
return mTitle;
}
void addPopup(std::unique_ptr<Widget> 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<DrawingContext> mDrawingContext;
onPopupFunc mPopupFunc;
Window* mParent{nullptr};
};
}

View file

@ -2,7 +2,7 @@
Color Theme::getBackgroundPrimary()
{
return {217, 217, 217};
return {245, 245, 245};
}
Color Theme::getBannerBackground()

View file

@ -18,6 +18,11 @@ Button::Button()
mName = "Button";
}
Button::~Button()
{
}
std::unique_ptr<Button> Button::Create()
{
return std::make_unique<Button>();

View file

@ -17,6 +17,8 @@ public:
Button();
~Button();
static std::unique_ptr<Button> Create();
void setLabel(const std::string& text);

View file

@ -10,6 +10,8 @@
#include "TransformNode.h"
#include "RootNode.h"
#include "Window.h"
#include <algorithm>
#include <iterator>
#include <iostream>
@ -41,6 +43,8 @@ std::unique_ptr<Widget> Widget::Create()
void Widget::addWidget(WidgetUPtr widget)
{
widget->setParent(this);
mPendingChildNodes.push_back(widget->getRootNode());
mChildren.push_back(std::move(widget));
}
@ -99,6 +103,16 @@ void Widget::setPadding(const BoundaryOffset& padding)
void Widget::setBounds(unsigned width, unsigned height)
{
if (mSize.mMaxWidth > 0 && width > mSize.mMaxWidth)
{
width = mSize.mMaxWidth;
}
if (mSize.mMaxHeight > 0 && height > mSize.mMaxHeight)
{
height = mSize.mMaxHeight;
}
if (width != mSize.mWidth || height != mSize.mHeight)
{
mTransformDirty = true;
@ -161,6 +175,15 @@ bool Widget::needsUpdate() const
return false;
}
void Widget::setMaxWidth(unsigned maxWidth)
{
if (mSize.mMaxWidth != maxWidth)
{
mTransformDirty = true;
mSize.mMaxWidth = maxWidth;
}
}
void Widget::doPaint(const PaintEvent* event)
{
updateBackground(event);
@ -319,3 +342,51 @@ void Widget::updateBackground(const PaintEvent* event)
mBackgroundNode->setIsVisible(mVisible);
}
}
mt::Window* Widget::getTopLevelWindow() const
{
if(mWindow)
{
return mWindow;
}
std::cout << "I am " << getName() << std::endl;
auto lastParent = mParent;
auto nextParent = mParent;
while(nextParent)
{
lastParent = nextParent;
nextParent = lastParent->getParent();
std::cout << "Checking if " << lastParent->getName() << std::endl;
if (nextParent)
{
std::cout << "Next is " << nextParent->getName() << std::endl;
}
else
{
std::cout << "no next" << std::endl;
}
}
return lastParent->getTopLevelWindow();
}
Widget* Widget::getParent() const
{
return mParent;
}
mt::Window* Widget::getWindow() const
{
return mWindow;
}
void Widget::setParent(Widget* parent)
{
mParent = parent;
}
void Widget::setWindow(mt::Window* window)
{
mWindow = window;
}

View file

@ -16,6 +16,11 @@ class AbstractVisualNode;
class TransformNode;
class RectangleNode;
namespace mt
{
class Window;
}
class Widget
{
public:
@ -93,6 +98,8 @@ public:
void setSize(const BoundedSize& size);
void setMaxWidth(unsigned maxWidth);
void setMargin(unsigned margin);
void setMargin(const BoundaryOffset& margin);
@ -110,13 +117,17 @@ public:
mName = name;
}
const std::string& getName()
const std::string& getName() const
{
return mName;
}
bool needsUpdate() const;
void setWindow(mt::Window* window);
mt::Window* getTopLevelWindow() const;
protected:
virtual bool onMyKeyboardEvent(const KeyboardEvent* event);
@ -130,6 +141,14 @@ protected:
virtual bool isDirty() const;
void setParent(Widget* parent);
Widget* getParent() const;
mt::Window* getWindow() const;
DiscretePoint mLocation;
BoundedSize mSize;
BoundaryOffset mPadding;
@ -152,6 +171,8 @@ protected:
std::vector<TransformNode*> mPendingChildNodes;
FontItem mDefaultFont;
Widget* mParent{nullptr};
mt::Window* mWindow{nullptr};
};
using WidgetUPtr = std::unique_ptr<Widget>;