CBaseWindow flipped pointers for use with CBaseContainer::Add()

This commit is contained in:
Rebekah 2022-04-12 12:29:33 -04:00
parent 6e524b1707
commit 3c7f999306
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5
8 changed files with 14 additions and 17 deletions

View File

@ -57,7 +57,7 @@ static ui::Var<int> text({ "nonya" }, "Editable Text", 1);
class TestWindow : public CBaseWindow { class TestWindow : public CBaseWindow {
public: public:
TestWindow(IWidget* parent) TestWindow(IWidget* parent)
: CBaseWindow("root_test", parent) { : CBaseWindow(parent, "root_test") {
this->always_visible = false; this->always_visible = false;
this->hover = false; this->hover = false;
SetMaxSize(1270, 1000); SetMaxSize(1270, 1000);

View File

@ -58,11 +58,7 @@ public:
inline virtual void Show() { this->visible = true; } inline virtual void Show() { this->visible = true; }
inline virtual void Hide() { this->visible = false; } inline virtual void Hide() { this->visible = false; }
inline virtual bool IsVisible() { virtual bool IsVisible();
if (GetParent())
return GetParent()->IsVisible() && this->visible;
return this->visible;
}
virtual bool IsHovered(); virtual bool IsHovered();
virtual bool IsFocused(); virtual bool IsFocused();

View File

@ -23,7 +23,7 @@
class CBaseWindow : public CBaseContainer { class CBaseWindow : public CBaseContainer {
public: public:
inline CBaseWindow(std::string name = "unnamed", IWidget* parent = nullptr) inline CBaseWindow(IWidget* parent, std::string name = "unnamed")
: CBaseContainer(name, parent) { } : CBaseContainer(name, parent) { }
inline virtual ~CBaseWindow() {}; inline virtual ~CBaseWindow() {};

View File

@ -41,7 +41,7 @@
ui::Var<bool> gui_draw_bounds({ "Gui", "Debug" }, "Draw Bounds", false); ui::Var<bool> gui_draw_bounds({ "Gui", "Debug" }, "Draw Bounds", false);
ui::Var<bool> gui_visible({ "Gui" }, "Visible", true); ui::Var<bool> gui_visible({ "Gui" }, "Visible", true);
Canvas::Canvas() Canvas::Canvas()
: CBaseWindow("root") { } : CBaseWindow(nullptr, "root") { }
// Crashes associated with no set root in globals // Crashes associated with no set root in globals
void Canvas::Setup() { void Canvas::Setup() {

View File

@ -15,7 +15,7 @@
#include "gui/widgets/titlebar.hpp" #include "gui/widgets/titlebar.hpp"
CMenuWindow::CMenuWindow(std::string name, IWidget* parent) CMenuWindow::CMenuWindow(std::string name, IWidget* parent)
: CBaseWindow(name, parent) { : CBaseWindow(parent, name) {
m_pList = new CMenuList("list", this); m_pList = new CMenuList("list", this);
AddChild(m_pList); AddChild(m_pList);
m_pActiveTab = 0; m_pActiveTab = 0;

View File

@ -78,13 +78,15 @@ std::pair<int, int> CBaseWidget::AbsolutePosition() {
return result; return result;
} }
bool CBaseWidget::IsVisible() {
return this->visible && (!this->GetParent() || GetParent()->IsVisible());
}
Canvas* CBaseWidget::GetCanvas() { Canvas* CBaseWidget::GetCanvas() {
auto* parent = GetParent();
if (parent) {
if (auto* canvas = parent->GetCanvas())
return canvas;
}
auto* ret = dynamic_cast<Canvas*>(this); auto* ret = dynamic_cast<Canvas*>(this);
if (ret)
return ret;
ret = this->GetParent()->GetCanvas();
assert(ret); assert(ret);
return ret; return ret;
} }

View File

@ -41,9 +41,8 @@ void CBaseWindow::MoveChildren() {
if (c->GetPositionMode() != FLOATING) if (c->GetPositionMode() != FLOATING)
my += (size.second + 2); my += (size.second + 2);
} }
if (GetParent()) { if (GetParent())
SetSize(mx + 4, my + 2); SetSize(mx + 4, my + 2);
}
} }
void CBaseWindow::OnFocusGain() { void CBaseWindow::OnFocusGain() {

View File

@ -26,7 +26,7 @@
#include "gui/canvas.hpp" #include "gui/canvas.hpp"
CDropdownList::CDropdownList(std::string name, CDropdown* menu, int offset) CDropdownList::CDropdownList(std::string name, CDropdown* menu, int offset)
: CBaseContainer(name, nullptr) { : CBaseContainer(name, menu) {
m_pMenu = menu; m_pMenu = menu;
Hide(); Hide();
SetZIndex(5); SetZIndex(5);