Partial fix, UtilityBar submenu works, but the buttons within the Submenu still segfault.
This commit is contained in:
@@ -111,7 +111,8 @@ namespace JUI {
|
||||
protected:
|
||||
VerticalListLayout* layout;
|
||||
JGL::Font font;
|
||||
bool close_on_hover_loss = true;;
|
||||
bool close_on_hover_loss = true;
|
||||
float aggregate_height = 0;
|
||||
|
||||
private:
|
||||
|
||||
|
@@ -27,18 +27,15 @@ namespace JUI
|
||||
explicit UtilityBar(Widget* parent);
|
||||
|
||||
/// Adds a new 'Submenu', which consists of a labeled button, which opens a contextual-submenu
|
||||
std::pair<TextButton*, ContextMenu*> AddSubmenu(const std::string& name);
|
||||
ContextMenu* AddSubmenu(const std::string& name);
|
||||
|
||||
|
||||
TextButton* AddButton(const std::string& name);
|
||||
|
||||
void SetFont(const JGL::Font& use_my_font)
|
||||
{
|
||||
font = use_my_font;
|
||||
}
|
||||
protected:
|
||||
HorizontalListLayout* layout;
|
||||
JGL::Font font;
|
||||
//std::vector<TextButton*> buttons;
|
||||
//std::vector<ContextMenu*> submenus;
|
||||
HorizontalListLayout* layout = nullptr;
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
3
main.cpp
3
main.cpp
@@ -70,7 +70,8 @@ JUI::Scene* CreateScene() {
|
||||
|
||||
auto* topbar = new UtilityBar(root);
|
||||
topbar->ZIndex(3);
|
||||
auto [demo_btn, demos] = topbar->AddSubmenu("Demos");
|
||||
|
||||
auto* demos = topbar->AddSubmenu("Demos");
|
||||
|
||||
demos->AddButton("9-Slice Widget Demo",
|
||||
[&] mutable { nineslice_demo_window->Toggle(); });
|
||||
|
@@ -4,21 +4,20 @@ namespace JUI {
|
||||
ContextMenu::ContextMenu(): Rect() {
|
||||
Name("ContextMenu");
|
||||
this->BGColor(Colors::White);
|
||||
this->Margin(2_px);
|
||||
//this->Margin(2_px);
|
||||
this->Size({200, 200, 0, 0});
|
||||
layout = new VerticalListLayout(this);
|
||||
|
||||
MouseExit += [this] (Vector2 _)
|
||||
{
|
||||
this->Visible(false);
|
||||
this->Parent(nullptr);
|
||||
//this->Parent(nullptr);
|
||||
// TODO: Collect
|
||||
};
|
||||
}
|
||||
|
||||
ContextMenu::ContextMenu(Widget *parent): ContextMenu() {
|
||||
this->Parent(parent);
|
||||
|
||||
}
|
||||
|
||||
void ContextMenu::SetFont(const JGL::Font &use_my_font) {
|
||||
@@ -32,6 +31,10 @@ namespace JUI {
|
||||
line_item->SetTextSize(16);
|
||||
line_item->SetTextColor(Colors::Black);
|
||||
line_item->Size({0, 20, 1, 0});
|
||||
|
||||
// TODO: Temp Hack: Implement Auto-size.
|
||||
aggregate_height += 20;
|
||||
this->size.Y.Pixels = aggregate_height;
|
||||
return line_item;
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace JUI {
|
||||
UtilityBar::UtilityBar(): Rect() {
|
||||
// TODO: Make a note that all JGL::Font members on widgets need to be initialized to JGL::Fonts::Jupiteroid inside the constructor.
|
||||
font = JGL::Fonts::Jupiteroid;
|
||||
//font = JGL::Fonts::Jupiteroid;
|
||||
|
||||
this->Size({0, 20, 1, 0});
|
||||
this->Position({0,0,0,0});
|
||||
@@ -22,19 +22,25 @@ namespace JUI {
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
std::pair<TextButton *, ContextMenu *> UtilityBar::AddSubmenu(const std::string &name) {
|
||||
auto btn = AddButton(name);
|
||||
ContextMenu * UtilityBar::AddSubmenu(const std::string &name) {
|
||||
auto* btn = AddButton(name);
|
||||
|
||||
//buttons.push_back(btn);
|
||||
|
||||
auto* submenu = new JUI::ContextMenu(this);
|
||||
submenu->AnchorPoint({1, 0});
|
||||
submenu->Position({0_percent, 0_percent});
|
||||
//submenu->AnchorPoint({0, 1});
|
||||
// TODO: Fix AnchorPoint behavior!!
|
||||
submenu->Position({0_percent, 100_percent});
|
||||
submenu->Visible(true);
|
||||
|
||||
//submenus.push_back(submenu);
|
||||
|
||||
btn->OnClickEvent += [this, &submenu] (auto a, auto b) {
|
||||
btn->OnClickEvent += [submenu] (auto a, auto b) mutable {
|
||||
submenu->Visible(true);
|
||||
};
|
||||
|
||||
//conn.Invoke({}, MouseButton::Left);
|
||||
|
||||
// TODO: We seem to have duplicate events
|
||||
// Hoverable::OnExitEvent
|
||||
// RectBase::MouseExit
|
||||
@@ -43,19 +49,23 @@ namespace JUI {
|
||||
//};
|
||||
|
||||
|
||||
return {btn, submenu};
|
||||
return submenu;
|
||||
}
|
||||
|
||||
TextButton * UtilityBar::AddButton(const std::string &name) {
|
||||
auto str_width = font.MeasureString(name, 14);
|
||||
// TODO: Refactor this to actually be able to use a set-font later.
|
||||
auto str_width = Fonts::Jupiteroid.MeasureString(name, 14);
|
||||
|
||||
auto* btn = new TextButton(layout);
|
||||
btn->SetFont(font);
|
||||
btn->SetFont(Fonts::Jupiteroid);
|
||||
btn->SetTextSize(14);
|
||||
btn->SetTextColor(Colors::Black);
|
||||
btn->Size({static_cast<int>(str_width.x)+16, 0, 0, 1});
|
||||
btn->BorderWidth(0.f);
|
||||
btn->SetContent(name);
|
||||
|
||||
//buttons.push_back(btn);
|
||||
|
||||
return btn;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user