ListBox EditBox TextBox

Started by 0x00, 19 October 2016, 12:52:13

0x00

ListBox
Need custom listbox item like a
tgui::ListBox::Ptr list = std::make_shared<tgui::ListBox>();

void ListBox::addItem<Widget>(std::shared_ptr<Widget> widget); //Or wiget arguments

std::shared_ptr<Widget> ListBox::getItem<Widget>(const size_t id); //Or const char *name

void ListBox::insertItem<Widget>(std::shared_ptr<Widget> widget, const size_t id); //Insert item betwen few other items

That provides editable items like a playlist item simplifies adding new buttons\text\images something else.

Music player
[TrackName]<Play><Stop><Options> //current played track
[TrackName] - <Play><Stop><Options> //hided buttons
[TrackName] - <Play><Stop><Options>
[TrackName] - <Play><Stop><Options>

Server list like a
[UserName]<KickButton><SendMessageButton><InviteButton>
[UserName]<KickButton><SendMessageButton><InviteButton>
[UserName]<KickButton><SendMessageButton><InviteButton>

EditBox
void EditBox::setCaretPos(const size_t char_pos);
size_t EditBox::getCaretPos() const;

void EditBox::setCaretLine(const size_t line_id); //move caret to line
size_t EditBox::getCaretLine() const;

size_t EditBox::getLinesCount() const; //return total lines (with \n)

TextBox
Same as EditBox

Usable for editors.
Thx for reading)


texus

ListBox
The ListBox has been requested a few times already with various requirements.
Such a multi-column listbox / table hasn't been added yet because it is very hard to create. It also has to remain simple to use while still supporting all the features that people want (some want lines between the items, some want the items to still be selectable, ...).

I hope to have it in the future but I already have little time to work on the gui so such big widget is likely to keep getting delayed until someone else writes it.


TextBox
Could you clarify why you need to be able to set and get the caret position, and more importantly how you expect to be using these functions? I don't immediately see a use case for them because how would you know at which position you need the caret?

The getLinesCount function should be straightforward to add, but other than perhaps checking it the text box is full, is there a particular reason why you need such a function?


EditBox
There are no lines in edit box and for setCaretPos and getCaretPos I have the same question as for TextBox.

0x00

Quote from: texus on 19 October 2016, 14:01:53
There are no lines in edit box and for setCaretPos and getCaretPos I have the same question as for TextBox.

Ok I understood your logic and it is true. So about (TextBox), editors (macros \ auto insert \ etc.) when I need to auto cut (replace by pattern or something else) some text I'll move text to parser (do something) and return formated text but text caret position is on the first line (char) and I'll need to scroll text to latest edited line.

texus

Ok, that is a valid use case.
For edit box a setCaretPosition apparently already exists but without a corresponding getCaretPosition function.
For TextBox I would probably add a setCaretPosition function that take sf::Vector2<std::size_t> as parameter since that is what is being used internally as well.
I just realized that there might be a problem with specifying which line of the textbox to put the caret to though. Due to word-wrap the line in text box may not correspond with the amount of newlines in the text.

texus

In case you would still be interested, TextBox now has setCaretPosition, getCaretPosition and getLinesCount functions in TGUI 0.8-dev.