Another Segfault

This commit is contained in:
2024-11-21 13:40:01 -05:00
parent 1cb0c1299a
commit 146b8190b0
3 changed files with 22 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ namespace JUI
ContextMenu() : Rect() {
this->BGColor(Colors::White);
this->Margin(2_px);
this->Size({200, 200, 0, 0});
layout = new VerticalListLayout(this);
}
@@ -28,7 +29,7 @@ namespace JUI
line_item->SetContent(name);
line_item->SetTextSize(16);
line_item->SetTextColor(Colors::Black);
line_item->Size({1, 0, 0, 20});
line_item->Size({0, 20, 1, 0});
return line_item;
}
protected:

View File

@@ -37,13 +37,22 @@ JUI::Scene* CreateScene() {
topbar->SetFont(FreeSans);
auto* file = topbar->AddButton("File");
file->OnClickEvent += [&, root] (Vector2 pos, JUI::MouseButton btn)
file->OnClickEvent += [&, root, file] (Vector2 pos, JUI::MouseButton btn)
{
auto* ctx_menu = new ContextMenu(root);
ctx_menu->SetFont(FreeSans);
ctx_menu->Position(UDim2(0,20,0,0));
ctx_menu->AddItem("A");
ctx_menu->AddItem("B");
ctx_menu->Position({0,0,pos.x, pos.y});
ctx_menu->AddItem("c");
ctx_menu->MouseExit += [ctx_menu] (Vector2 _)
{
ctx_menu->Visible(false);
ctx_menu->Parent(nullptr);
// TODO: Collect
};
};
topbar->AddButton("Edit");

View File

@@ -41,7 +41,7 @@ namespace JUI {
// Remove ourselves from our parent (if we have one)
if (this->parent) {
// this->parent->ChildRemoved(this)
std::erase(newParent->children, this);
std::erase(this->parent->children, this);
}
// Update our old parent to the new one
@@ -180,6 +180,10 @@ namespace JUI {
Vector2 Widget::GetAbsolutePosition() const {
if (this->parent == nullptr)
return {0,0};
auto child_pos_scale = this->Position().GetScale();
auto child_pos_pixels = this->Position().GetPixels();
auto parent_abs_size = this->GetParent()->GetAbsoluteSize();
@@ -206,6 +210,10 @@ namespace JUI {
// TODO: implement padding shrinking abs_size
Vector2 Widget::GetAbsoluteSize() const {
if (this->GetParent() == nullptr)
return {0,0};
Vector2 child_size_scale = this->Size().GetScale();
Vector2 child_size_px = this->Size().GetPixels();