EdgeTX / edgetx

EdgeTX is the cutting edge open source firmware for your R/C radio
https://edgetx.org
GNU General Public License v2.0
1.5k stars 318 forks source link

List special functions / global functions alphabetically #3591

Open phileville opened 1 year ago

phileville commented 1 year ago

Is there an existing issue for this feature request?

Is your feature request related to a problem?

When configuring a special function, when you are looknig for the function from the drop-down list, the list is in some random order. It would be much more easier to find the correct function if the list was in alphabetical order.

Describe the solution you'd like

I would like the function list to display in alphabetical order.

Describe alternatives you've considered

No response

Additional context

No response

Eldenroot commented 1 year ago

+1

pfeerick commented 1 year ago

Agreed. And ideally for both colorlcd and B&W. The current list is most likely in the order the functions were added.

philmoz commented 1 year ago

Will std::sort handle the UTF-8 translation strings correctly for all languages?

pfeerick commented 1 month ago

ChatGPT suggest yes (std::sort can be used to sort a mix of ASCII and UTF-8), but extra work is needed to manage it properly... i.e. If you don't use a custom locale comparator, it will sort ASCII then UTF-8, as well as uppercase before lowercase.

https://godbolt.org/z/cWhE6bnhd

Code

```c++ #include #include #include #include // Custom comparator using std::locale struct LocaleComparator { std::locale locale; LocaleComparator(const std::locale& loc) : locale(loc) {} bool operator()(const std::string& lhs, const std::string& rhs) const { return std::use_facet>(locale).compare( lhs.data(), lhs.data() + lhs.size(), rhs.data(), rhs.data() + rhs.size()) < 0; } }; int main() { // Define the locale, e.g., "en_US.UTF-8" for US English with UTF-8 encoding std::locale locale("en_US.UTF-8"); // Example list with mixed ASCII and UTF-8 strings std::vector list = {"apple", "Banana", "élan", "Éclair", "apple"}; // Sort the list using the custom comparator std::sort(list.begin(), list.end(), LocaleComparator(locale)); // Print the sorted list for (const auto& str : list) { std::cout << str << std::endl; } return 0; } ```