Jump to content

Menubar widget [Release]


GorzenDev
 Share

Recommended Posts

I have been working on a menubar widget and it came out pretty nicely.
I thought i would release it either for people to have an example of what would be possible with the widget's flexibility
or just for people to use it.

For now it only works in C++ since it makes use of CallFunction().

MenubarElement.lua

!! Make sure when you create the widget you create it last so it will render on top !!

It allows horizontal rules and submenus.

widgetPreview.JPG.5b1f9f7a397148c8283e439bca317384.JPG

widgetPreview1.JPG.52f8841669caf71c1dcb5ce152082e9e.JPG


How to use: (C++)

Create the widget and fill the menu 

float scale = gui->GetScale();

mnuBarItem = Widget::Create("Name", 2 * scale, 2 * scale, 60 * scale, 26 * scale, gui->GetBase(), "Scripts/GUI/MenubarElement.lua");
mnuBarItem->SetObject("backgroundcolor", new Vec4(0.7, 0.7, 0.7, 1.0));
mnuBarItem->AddItem("Temp0");
mnuBarItem->AddItem("Temp1");
mnuBarItem->AddItem("@-");//create a horizontal rule(menu seperator)
mnuBarItem->AddItem("&Submenu");//this will hold the submenu created next
//create a submenu from the last added item in the list
mnuBarItem->CallFunction("C_CreateSubMenuFromLastItem");
mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_A");
mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_B");
mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_C");
//
mnuAccount->AddItem("Temp2");


Catching widget events

ProcessEvent(Event event)
{
	if (event.id == Event::WidgetAction)
	{
    	if (event.source == mnuBarItem)
        {
            if (event.data == 0)
            {
                //
            }
            else if (event.data == 1)
            {
                //
            }
	    //(event.data == 2) horizontal rule
	    //
            else if (event.data == 3)//submenu
            {
            	int item = event.position.x;//submenu itemidx
                if (item == 0)
              	{
                	//
            	}
              	else if (item == 1)
              	{
                	//
              	}
              	else if (item == 2)
              	{
                	//
              	}
            }
            else if (event.data == 4)
            {
              //
            }
        }
    }
}


Also it needs a call to update somewhere in your loop.
Which is just used to update some delay timing.

mnuBarItem->CallFunction("C_Update");

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...