Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with Menu? #843

Open
blackpill0w opened this issue Apr 16, 2024 · 2 comments
Open

Problems with Menu? #843

blackpill0w opened this issue Apr 16, 2024 · 2 comments

Comments

@blackpill0w
Copy link

blackpill0w commented Apr 16, 2024

Hi,

I am trying create a Menu but the items I have are not std::string, I have, a list of struct A and I want a field of the struct (which is a string) in the menu, do I need to keep a copy of them in an std::vector<std::string> for the Menu?
I can't even use a vector of char * or std::string_view which would be way better.
Or maybe we could add something like this

Component Menu(std::vector<T> entries, /* other stuff */, std::function<std::string(T&)> convertEntriesToString);

to convert entries to string each time you render,

thanks.

@blackpill0w blackpill0w changed the title Isn't ConstStringListRef highly inflexible or am I missing something? Problems with Menu? Apr 16, 2024
@ArthurSonzogni
Copy link
Owner

This might be a bit costly to call the functor everytime we need to observe the list size.

I was thinking adding an option to ConstStringListRef to provide class implementing the required functions.

class ConstStringListRefAdapter {
  virtual int Size() = 0;
  virtual const std::string Entry(int index) = 0;
}

ConstStringListRef(ConstStringListRefAdapter* adapter);
ConstStringListRef(std::unique_ptr<ConstStringListRefAdapter> adapter);

But I am not totally convinced.

@blackpill0w
Copy link
Author

You're right the ConstStringListRefAdapter stills creates a new string each time so that would very bad for performance, what about a vector<std::string_view>? You still have the hit when you compute the size but it's better I think.
I also thought of using vector<std::string*>, I don't know how much change would be required to the existing code, so tell me what you think about the two suggestions.

ArthurSonzogni added a commit that referenced this issue Apr 28, 2024
ArthurSonzogni added a commit that referenced this issue Apr 28, 2024
ArthurSonzogni added a commit that referenced this issue Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants