Add table widget

  • 11 Replies
  • 65 Views
Add table widget
« on: 12 September 2019, 17:22:44 »
ListView is very good control but it doesn't provide opportunity to change anything but text for cells or even rows.

So it would be great to have control where every cell (or at least rows) can change color(of text/background/borders). It's very common situation where one should separate data in table (like top 5 of something). 

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: Add table widget
« Reply #1 on: 12 September 2019, 18:54:48 »
I'm not going to be adding it anywhere soon.
The ListView was created to satisfy most requests for list views and tables. It took me a long time to finally write it and it is now the most complex widget in the gui, so I'm not looking forward on writing another similar widget right now. I guess it could be implemented in the ListView itself even though it doesn't really belong there, but as with most feature requests that are being made recently, I won't be doing it soon.

Re: Add table widget
« Reply #2 on: 12 September 2019, 22:38:13 »
Well if provide only additional properties for items and not for cells I think it would good fit concept of listview. I can try to implement it myself, it doesn't seems really hard.

Re: Add table widget
« Reply #3 on: 14 September 2019, 18:48:03 »
Unfortunately there isn't good way to provide additional properties even only for items. So I see 2 options:
1. Separate Item as Widget.
2. Create another control - table (or datagrid) widget, where every cell will separate widget. 
Of course there is also simple and dirty way, to expand Item with at least member for text color and use inner value instead of common property and after that replace protected function for changing color by public one:

Code: [Select]
    void ListView::setItemColor(std::size_t index, const Color& color, bool isForceUpdate)
    {
        for (auto& text : m_items[index].texts)
        {
            if (isForceUpdate)
                m_items[index].m_textColor = color;

            text.setColor(m_items[index].m_textColor);
        }
    }

@texus, how to do that better?

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: Add table widget
« Reply #4 on: 14 September 2019, 19:03:32 »
Making every row or cell a widget is going to be a huge performance issue. There is a reason why I now have a Text class to display texts instead of using the Label widget everywhere like it used to be.

The "simple and dirty way" is probably what I would end up doing if I needed it, but I don't really feel like this is a good addition. The functionality is very niche and it complicates the code more than I would like.

Maybe you should just inherit from ListView and make the modifications in your inherited class. If changes are needed to ListView to make it easier to implement your custom widget on top of it then I'm willing to look into that, but getting the code you want into the TGUI ListView class is probably not going to happen.

Re: Add table widget
« Reply #5 on: 14 September 2019, 19:41:43 »
Yes, I already started doing so but core problem is extend inner Item class. I'm not sure if it will be possible made the changes just extending functionality in inherit class. 

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: Add table widget
« Reply #6 on: 14 September 2019, 19:51:27 »
You could store the colors in a separate list instead of trying to reuse the existing items list, but you would still have to replace all functions that add, remove or changes any of the items.
I'm not sure what the best way to add the functionality would be either.

Re: Add table widget
« Reply #7 on: 16 September 2019, 11:52:25 »
Right. So now it's only requires set "colour" functions setItemColor/updateSelectedAndhoveredItemColors/updateItemColors as virtual so it could be reused in inherited class. Is it possible?

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: Add table widget
« Reply #8 on: 16 September 2019, 19:13:15 »
Isn't making just setItemColor virtual enough, as the other will just call that function? Or do you have something that needs to be changed in these functions as well?

Re: Add table widget
« Reply #9 on: 16 September 2019, 19:48:11 »
Yes, you're right, it's my mistake.

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: Add table widget
« Reply #10 on: 16 September 2019, 19:49:19 »
I made setItemColor virtual now.

Re: Add table widget
« Reply #11 on: 16 September 2019, 19:54:03 »
great, thank you