[select][lvgl] Fix FixedVector size() returning 0 when using operator[] after init() (#11721)

This commit is contained in:
J. Nick Koston
2025-11-04 19:49:27 -06:00
committed by GitHub
parent 1446e7174a
commit 32975c9d8b
3 changed files with 6 additions and 4 deletions

View File

@@ -59,8 +59,8 @@ class LVGLSelect : public select::Select, public Component {
const auto &opts = this->widget_->get_options();
FixedVector<const char *> opt_ptrs;
opt_ptrs.init(opts.size());
for (size_t i = 0; i < opts.size(); i++) {
opt_ptrs[i] = opts[i].c_str();
for (const auto &opt : opts) {
opt_ptrs.push_back(opt.c_str());
}
this->traits.set_options(opt_ptrs);
}

View File

@@ -7,8 +7,8 @@ void SelectTraits::set_options(const std::initializer_list<const char *> &option
void SelectTraits::set_options(const FixedVector<const char *> &options) {
this->options_.init(options.size());
for (size_t i = 0; i < options.size(); i++) {
this->options_[i] = options[i];
for (const auto &opt : options) {
this->options_.push_back(opt);
}
}

View File

@@ -248,6 +248,8 @@ template<typename T> class FixedVector {
}
// Allocate capacity - can be called multiple times to reinit
// IMPORTANT: After calling init(), you MUST use push_back() to add elements.
// Direct assignment via operator[] does NOT update the size counter.
void init(size_t n) {
cleanup_();
reset_();