Disko Forum logo Login  |  Register  |  Lost Password
<< Start < Prev 1 2 Next > End >>
Add a button to a menu

Duran
Posts: 37
graphgraph

Add a button to a menu 6 Years ago  
Dear all,

Just a simple question: how can I add a button to a menu?

I'm trying 'menu->newItem()->add(button);' with no luck.

Thanks and best Regards,
Joaquim Duran
 
  The administrator has disabled public write access.
Add a button to a menu

Matthias
Posts: 64
graphgraph

Gender: Male Disko Location: Berlin, Germany Birthdate: 1979-04-25
Re:Add a button to a menu 6 Years ago  
Hi Joaquim,

does your menu consist of items which are always buttons?
If so, you can create an xml-file describing the menu and
its widget-template that includes a button.

Then you can create new items with:

Code:

MMSWidget *item = menu->newItem();
Afterwards you can change the behaviour of the button inside this item (i.e. setting images, colors). You can find some examples at: http://wiki.morphine.tv/tiki-index.php_page=gui-examples We'll integrate more examples and the description of the GUI elements at diskohq.org as well. But for now you can take a look at the documentation of Morphine. Best regards, Matthias
 
  The administrator has disabled public write access.
Add a button to a menu

Duran
Posts: 37
graphgraph

Re:Add a button to a menu 6 Years ago  
Hello Matthias,

Thanks for your suggestions to look at xml files to create a menu. By now, I'm trying to use Disko using plain C++ (later I will try to create .xml files for Gui).

I'm trying to create a menu with two buttons: one with an arrow pointing to up and the second one with a label. I've write the following code:


MMSMenuWidget *menu = new MMSMenuWidget(window, "";
menu->setItemTemplate(new MMSButton(window, "");
window->add(menu);

MMSArrowWidget *myarrow = new MMSArrowWidget(window, "";
myarrow->setDirection(MMSDIRECTION_UP);
MMSWidget *widget = menu->newItem();

widget->add(myarrow);
widget->onClick->connect(sigc:tr_fun(button_clicked));
widget->onReturn->connect(sigc:tr_fun(button_return));

MMSLabel *mylabel2 = new MMSLabel(window, "";
mylabel2->setFont("./themes/default/","DejaVuSansMono.ttf",20);
mylabel2->setText("Arround the world";
widget = menu->newItem();
widget->add(mylabel2);
widget->onClick->connect(sigc:tr_fun(button_clicked));
widget->onReturn->connect(sigc:tr_fun(button_return));

// show the window
....


But only the arrow widget is shown but no the label text. How does the code should be wrote?

Thanks and Best Regards,
Joaquim Duran
 
  The administrator has disabled public write access.
Add a button to a menu

Stefan
Posts: 91
graph

Re:Add a button to a menu 6 Years ago  
Hi Joaquim,

I created some sample code to demonstrate how menus are working.

File Attachment:
File Name: menu.txt
File Size: 1487


Basically you cannot add just any widget you create to a menu widget. You have to create an item template and pass it to the menu. Then you can use the newItem() method to add a new entry to that menu.

I Hope that illustrates it a bit. The menu is our most sophisticated widget, so there are lots of options for the menu layout and how the selection works. This is just one simple way of using it.

kind regards
Stefan
 
  The administrator has disabled public write access.
Add a button to a menu

Duran
Posts: 37
graphgraph

Re:Add a button to a menu 6 Years ago  
Stefan,

Tanks for your example. It's very constructive.

I've modified the code that you provided to set a slot to the onClick and onReturn signals from buttons of menu.

The modified code looks like:

//create menu entries and populate the templates
MMSWidget *item = menu->newItem();

item->onClick->connect(sigc:tr_fun(button_clicked)); //ADDED
item->onReturn->connect(sigc:tr_fun(button_return)); //ADDED

MMSLabelWidget *lbl = dynamic_cast<MMSLabelWidget*>
(item->searchForWidget("mylabel");
if(lbl)
{
lbl->setFont("./themes/default/","DejaVuSansMono.ttf",16);
lbl->setText("Item1";
}

The functions button_clicked and button_return prints a simple message on the console with the address of the widget. When the options of the menu are pressed, in the log message appears that a button has been pressed and released, but not text is shown on the screen.

The text of functions is shown if a button is added to the vertical box and the same slots are set to it.

Is there any problem by setting button actions in this way?

Thanks and Best Regards,
Joaquim Duran
 
  The administrator has disabled public write access.
Add a button to a menu

Matthias
Posts: 64
graphgraph

Gender: Male Disko Location: Berlin, Germany Birthdate: 1979-04-25
Re:Add a button to a menu 6 Years ago  
Hi Joaquim,

you have to connect your onReturn() method to the top-level-menu,
not the items itself. The reason is, because the surrounding menu
will catch all Inputs and they will never get to the child-widgets
(the items).

I extended Stefans example to do this:
File Attachment:
File Name: main-c0d0abcb5f1e4be22add417ac2ab5e3b.txt
File Size: 4157


Btw. you should only use either onClick() or onReturn() in most
cases. If you're using the mouse or the keyboard to navigate
there is not a big difference. It's more important for touchscreen
based input. As an explanation, onClick() is called if you press
the button, onReturn() after releasing.

I hope this helps...

Best regards,
Matthias
 
 
Last Edit: 2009/08/31 14:06 By Matthias. Reason: attaching file failed
  The administrator has disabled public write access.
<< Start < Prev 1 2 Next > End >>
Powered by FireBoard
get the latest posts directly to your desktop