creating a custom listbox

Started by
1 comment, last by Rainweaver 15 years, 3 months ago
I have made a fairly complex GUI system for my game engine and it works pretty good. But I'm having a problem with one control type, the listbox. I wanted the listbox to be very customizable, so what I did was to make it accept objects based on IListBoxItem. It has only two pure virtual functions, CreateControl() and Compare(). Compare() is for sorting items. In CreateControl() you create the item control you want and return a pointer to it. So if you wanted a listbox with buttons as items you would subclass IListBoxItem and in the CreateControl() you would create a button control and return it. This works fine, but I'm having problems selecting items. You see, I also want to be able to select and item. The idea is that if you click on the item area the item's background color will change. But if the item area is covered by a button the mouse-click would only go to the button object. I want the item to be selected even though you clicked on a child control inside it. I know it must be hard to help me with this as you have no idea how my GUI system works. But I'm really stuck here and would appreciate any ideas you might have. A mouse down message is sent to the topmost control under the cursor. The control receives the message inside its MessageHandler() and if it doesn't process the message it sends it to the GUI DefaultMessageHandler(). The GUI ystem is somewhat based on how Windows works. Any and all ideas will be much appreciated
Advertisement
I had several complex ideas of how to solve this problem, but they never really worked. In the end I set textboxes to be "input transparent" as default. This way, if someone either clicks on an empty space inside an item or it's label (textbox), the listbox gets the input and selects the item. If one would create a checkbox inside an item, the checkbox would get the input and the item won't be selected.

This is still not a satisfying solution. I would like the item to be selected even if the checkbox is clicked. But this is better than nothing.
Hello,

"A mouse down message is sent to the topmost control under the cursor. The control receives the message inside its MessageHandler() and if it doesn't process the message it sends it to the GUI DefaultMessageHandler()."

I think you should change this behaviour. If the control under the cursor isn't interested in a click message, it should either fall through the control behind it or be dispatched to another listener.

Hope this helps a bit.

Edit: And since you're planning to wrap different controls in a IListItem object, you should find a way to override the events they listen to.
Rainweaver Framework (working title)

IronLua (looking for a DLR expert)



This topic is closed to new replies.

Advertisement