Add table widget

Started by Kvaz1r, 12 September 2019, 17:22:44

Kvaz1r

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

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.

Kvaz1r

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.

Kvaz1r

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:

    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

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.

Kvaz1r

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

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.

Kvaz1r

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

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?

Kvaz1r

Yes, you're right, it's my mistake.

texus

I made setItemColor virtual now.

Kvaz1r