Hot Door CORE Forum
building popup menus and combo boxes - Printable Version

+- Hot Door CORE Forum (http://hotdoorcore.com/forum)
+-- Forum: All forums (http://hotdoorcore.com/forum/forumdisplay.php?fid=1)
+--- Forum: General discussion (http://hotdoorcore.com/forum/forumdisplay.php?fid=3)
+--- Thread: building popup menus and combo boxes (/showthread.php?tid=65)



building popup menus and combo boxes - Rick Johnson - 04-01-2016

Could someone be so kind as to post a snippet of simple code to construct a popup menu or popup/dropdown for a combo box? The sample projects make it clear how to create widgets in general and place them in a window or panel, but it appears that the structure of a popup menu is very different from a menu bar menu, using vectors of objects (another post refers to "hdi::core::EntryData" but all I can find in the docs is "Entry" and "EntryValue." Maybe I'm just used to menus as simple arrays of short strings and could be enlightened as to possibilities I'd not thought about before.

I wouldn't mind using a series of functions adding the items one by one, or maybe there's a simple, straightforward way to build a menu from a simple array such as:

static const char* const values[] = {"15", "18", "20", "24", "30", "30"};

Any suggestions would be very much appreciated.

--Rick


RE: building popup menus and combo boxes - garrett - 04-01-2016

Here is an example for a popup menu of isometric faces. Each entry can have a unique ID string, which I've made "FACE_*_ID". The entry title is pretty self explanatory. The entry user data is of type void* and in this case I have cast an enum value ("FaceType*") and stuffed it into the user data. When constructing the popup menu, I provided a top-left location, a width, the list of entries, and an initial ID string (from some prefs struct) to indicate which entry is pre-selected.

Code:
hdi::core::PopupMenu::EntryVector faceList;
faceList.push_back(
    hdi::core::ListEntry(
        "FACE_LEFT_ID",
        "Left",
        (void*) (intptr_t) FaceTypeLeft
    )
);
faceList.push_back(
    hdi::core::ListEntry(
        "FACE_TOP_ID",
        "Top",
        (void*) (intptr_t) FaceTypeTop
    )
);
faceList.push_back(
    hdi::core::ListEntry(
        "FACE_RIGHT_ID",
        "Right",
        (void*) (intptr_t) FaceTypeRight
    )
);
faceList.push_back(
    hdi::core::ListEntry(
        "FACE_BOTTOM_ID",
        "Bottom",
        (void*) (intptr_t) FaceTypeBottom
    )
);

hdi::core::PopupMenu facePopup(
    hdi::core::Point(6.0, 8.0),
    100.0,
    faceList,
    prefs->faceID
);



RE: building popup menus and combo boxes - Rick Johnson - 04-01-2016

Thanks, Garrett, this is very helpful! I appreciate your clarity and thoroughness. -- rj