mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 23:21:54 +00:00 
			
		
		
		
	[nextion] Add set_component_visibility() method for dynamic visibility control (#11530)
				
					
				
			Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
		| @@ -540,6 +540,23 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe | |||||||
|    */ |    */ | ||||||
|   void goto_page(uint8_t page); |   void goto_page(uint8_t page); | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Set the visibility of a component. | ||||||
|  |    * | ||||||
|  |    * @param component The component name. | ||||||
|  |    * @param show True to show the component, false to hide it. | ||||||
|  |    * | ||||||
|  |    * @see show_component() | ||||||
|  |    * @see hide_component() | ||||||
|  |    * | ||||||
|  |    * Example: | ||||||
|  |    * ```cpp | ||||||
|  |    * it.set_component_visibility("textview", true);   // Equivalent to show_component("textview") | ||||||
|  |    * it.set_component_visibility("textview", false);  // Equivalent to hide_component("textview") | ||||||
|  |    * ``` | ||||||
|  |    */ | ||||||
|  |   void set_component_visibility(const char *component, bool show) override; | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * Hide a component. |    * Hide a component. | ||||||
|    * @param component The component name. |    * @param component The component name. | ||||||
|   | |||||||
| @@ -45,6 +45,7 @@ class NextionBase { | |||||||
|   virtual void set_component_pressed_font_color(const char *component, Color color) = 0; |   virtual void set_component_pressed_font_color(const char *component, Color color) = 0; | ||||||
|   virtual void set_component_font(const char *component, uint8_t font_id) = 0; |   virtual void set_component_font(const char *component, uint8_t font_id) = 0; | ||||||
|  |  | ||||||
|  |   virtual void set_component_visibility(const char *component, bool show) = 0; | ||||||
|   virtual void show_component(const char *component) = 0; |   virtual void show_component(const char *component) = 0; | ||||||
|   virtual void hide_component(const char *component) = 0; |   virtual void hide_component(const char *component) = 0; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -201,13 +201,13 @@ void Nextion::set_component_font(const char *component, uint8_t font_id) { | |||||||
|   this->add_no_result_to_queue_with_printf_("set_component_font", "%s.font=%" PRIu8, component, font_id); |   this->add_no_result_to_queue_with_printf_("set_component_font", "%s.font=%" PRIu8, component, font_id); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Nextion::hide_component(const char *component) { | void Nextion::set_component_visibility(const char *component, bool show) { | ||||||
|   this->add_no_result_to_queue_with_printf_("hide_component", "vis %s,0", component); |   this->add_no_result_to_queue_with_printf_("set_component_visibility", "vis %s,%d", component, show ? 1 : 0); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Nextion::show_component(const char *component) { | void Nextion::hide_component(const char *component) { this->set_component_visibility(component, false); } | ||||||
|   this->add_no_result_to_queue_with_printf_("show_component", "vis %s,1", component); |  | ||||||
| } | void Nextion::show_component(const char *component) { this->set_component_visibility(component, true); } | ||||||
|  |  | ||||||
| void Nextion::enable_component_touch(const char *component) { | void Nextion::enable_component_touch(const char *component) { | ||||||
|   this->add_no_result_to_queue_with_printf_("enable_component_touch", "tsw %s,1", component); |   this->add_no_result_to_queue_with_printf_("enable_component_touch", "tsw %s,1", component); | ||||||
|   | |||||||
| @@ -81,13 +81,11 @@ void NextionComponent::update_component_settings(bool force_update) { | |||||||
|  |  | ||||||
|     this->component_flags_.visible_needs_update = false; |     this->component_flags_.visible_needs_update = false; | ||||||
|  |  | ||||||
|     if (this->component_flags_.visible) { |     this->nextion_->set_component_visibility(name_to_send.c_str(), this->component_flags_.visible); | ||||||
|       this->nextion_->show_component(name_to_send.c_str()); |     if (!this->component_flags_.visible) { | ||||||
|       this->send_state_to_nextion(); |  | ||||||
|     } else { |  | ||||||
|       this->nextion_->hide_component(name_to_send.c_str()); |  | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |     this->send_state_to_nextion(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (this->component_flags_.bco_needs_update || (force_update && this->component_flags_.bco2_is_set)) { |   if (this->component_flags_.bco_needs_update || (force_update && this->component_flags_.bco2_is_set)) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user