mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	fix
This commit is contained in:
		| @@ -55,11 +55,7 @@ class LVGLSelect : public select::Select, public Component { | |||||||
|   } |   } | ||||||
|   void set_options_() { |   void set_options_() { | ||||||
|     // Copy options from lvgl widget to select traits |     // Copy options from lvgl widget to select traits | ||||||
|     const auto &widget_options = this->widget_->get_options(); |     this->traits.copy_options(this->widget_->get_options()); | ||||||
|     this->traits.options_.init(widget_options.size()); |  | ||||||
|     for (const auto &option : widget_options) { |  | ||||||
|       this->traits.options_.push_back(option); |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   LvSelectable *widget_; |   LvSelectable *widget_; | ||||||
|   | |||||||
| @@ -11,6 +11,8 @@ class SelectTraits { | |||||||
|  public: |  public: | ||||||
|   void set_options(std::initializer_list<std::string> options); |   void set_options(std::initializer_list<std::string> options); | ||||||
|   const FixedVector<std::string> &get_options() const; |   const FixedVector<std::string> &get_options() const; | ||||||
|  |   /// Copy options from another SelectTraits (for copy_select, lvgl) | ||||||
|  |   void copy_options(const FixedVector<std::string> &other) { this->options_.copy_from(other); } | ||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
|   FixedVector<std::string> options_; |   FixedVector<std::string> options_; | ||||||
|   | |||||||
| @@ -215,6 +215,7 @@ template<typename T> class FixedVector { | |||||||
|   ~FixedVector() { cleanup_(); } |   ~FixedVector() { cleanup_(); } | ||||||
|  |  | ||||||
|   // Disable copy operations (avoid accidental expensive copies) |   // Disable copy operations (avoid accidental expensive copies) | ||||||
|  |   // Use copy_from() for explicit copying when needed (e.g., copy_select) | ||||||
|   FixedVector(const FixedVector &) = delete; |   FixedVector(const FixedVector &) = delete; | ||||||
|   FixedVector &operator=(const FixedVector &) = delete; |   FixedVector &operator=(const FixedVector &) = delete; | ||||||
|  |  | ||||||
| @@ -246,6 +247,19 @@ template<typename T> class FixedVector { | |||||||
|     return *this; |     return *this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /// Explicitly copy another FixedVector | ||||||
|  |   /// This method exists instead of operator= to make copying intentional and visible. | ||||||
|  |   /// Copying is expensive on embedded systems, so we require explicit opt-in. | ||||||
|  |   /// Use cases: copy_select (copying source options), lvgl (copying widget options) | ||||||
|  |   void copy_from(const FixedVector &other) { | ||||||
|  |     cleanup_(); | ||||||
|  |     reset_(); | ||||||
|  |     init(other.size()); | ||||||
|  |     for (const auto &item : other) { | ||||||
|  |       push_back(item); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   // Allocate capacity - can be called multiple times to reinit |   // Allocate capacity - can be called multiple times to reinit | ||||||
|   void init(size_t n) { |   void init(size_t n) { | ||||||
|     cleanup_(); |     cleanup_(); | ||||||
| @@ -304,6 +318,11 @@ template<typename T> class FixedVector { | |||||||
|     return data_[size_ - 1]; |     return data_[size_ - 1]; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /// Access first element (no bounds checking - matches std::vector behavior) | ||||||
|  |   /// Caller must ensure vector is not empty (size() > 0) | ||||||
|  |   T &front() { return data_[0]; } | ||||||
|  |   const T &front() const { return data_[0]; } | ||||||
|  |  | ||||||
|   /// Access last element (no bounds checking - matches std::vector behavior) |   /// Access last element (no bounds checking - matches std::vector behavior) | ||||||
|   /// Caller must ensure vector is not empty (size() > 0) |   /// Caller must ensure vector is not empty (size() > 0) | ||||||
|   T &back() { return data_[size_ - 1]; } |   T &back() { return data_[size_ - 1]; } | ||||||
| @@ -317,6 +336,12 @@ template<typename T> class FixedVector { | |||||||
|   T &operator[](size_t i) { return data_[i]; } |   T &operator[](size_t i) { return data_[i]; } | ||||||
|   const T &operator[](size_t i) const { return data_[i]; } |   const T &operator[](size_t i) const { return data_[i]; } | ||||||
|  |  | ||||||
|  |   /// Access element with bounds checking (matches std::vector behavior) | ||||||
|  |   /// Returns reference to element at index i | ||||||
|  |   /// Behavior for out of bounds access matches std::vector::at() (undefined on embedded) | ||||||
|  |   T &at(size_t i) { return data_[i]; } | ||||||
|  |   const T &at(size_t i) const { return data_[i]; } | ||||||
|  |  | ||||||
|   // Iterator support for range-based for loops |   // Iterator support for range-based for loops | ||||||
|   T *begin() { return data_; } |   T *begin() { return data_; } | ||||||
|   T *end() { return data_ + size_; } |   T *end() { return data_ + size_; } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user