mirror of
https://github.com/esphome/esphome.git
synced 2026-10-21 13:34:12 +00:00
[display_menu_base] Stop copying the number format and switch texts (#21212)
This commit is contained in:
@@ -82,7 +82,7 @@ std::string MenuItemNumber::get_value_text() const {
|
||||
result = this->value_getter_.value()(this);
|
||||
} else {
|
||||
char data[32];
|
||||
snprintf(data, sizeof(data), this->format_.c_str(), get_number_value_());
|
||||
snprintf(data, sizeof(data), this->format_, get_number_value_());
|
||||
result = data;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,8 @@ class MenuItemNumber final : public MenuItemEditable {
|
||||
public:
|
||||
explicit MenuItemNumber() : MenuItemEditable(MENU_ITEM_NUMBER) {}
|
||||
void set_number_variable(number::Number *var) { this->number_var_ = var; }
|
||||
void set_format(const std::string &fmt) { this->format_ = fmt; }
|
||||
// Keeps the pointer; the string must outlive the item (codegen passes a literal)
|
||||
void set_format(const char *fmt) { this->format_ = fmt; }
|
||||
|
||||
bool has_value() const override { return true; }
|
||||
std::string get_value_text() const override;
|
||||
@@ -130,7 +131,7 @@ class MenuItemNumber final : public MenuItemEditable {
|
||||
float get_number_value_() const;
|
||||
|
||||
number::Number *number_var_{nullptr};
|
||||
std::string format_;
|
||||
const char *format_{""};
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -139,8 +140,9 @@ class MenuItemSwitch final : public MenuItemEditable {
|
||||
public:
|
||||
explicit MenuItemSwitch() : MenuItemEditable(MENU_ITEM_SWITCH) {}
|
||||
void set_switch_variable(switch_::Switch *var) { this->switch_var_ = var; }
|
||||
void set_on_text(const std::string &t) { this->switch_on_text_ = t; }
|
||||
void set_off_text(const std::string &t) { this->switch_off_text_ = t; }
|
||||
// Both keep the pointer; the strings must outlive the item (codegen passes literals)
|
||||
void set_on_text(const char *t) { this->switch_on_text_ = t; }
|
||||
void set_off_text(const char *t) { this->switch_off_text_ = t; }
|
||||
|
||||
bool has_value() const override { return true; }
|
||||
std::string get_value_text() const override;
|
||||
@@ -153,8 +155,8 @@ class MenuItemSwitch final : public MenuItemEditable {
|
||||
bool toggle_switch_();
|
||||
|
||||
switch_::Switch *switch_var_{nullptr};
|
||||
std::string switch_on_text_;
|
||||
std::string switch_off_text_;
|
||||
const char *switch_on_text_{""};
|
||||
const char *switch_off_text_{""};
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user