mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	[lvgl] Add content styling to tabview (#8823)
This commit is contained in:
		| @@ -247,11 +247,13 @@ FLAG_LIST = cv.ensure_list(df.LvConstant("LV_OBJ_FLAG_", *df.OBJ_FLAGS).one_of) | |||||||
| def part_schema(parts): | def part_schema(parts): | ||||||
|     """ |     """ | ||||||
|     Generate a schema for the various parts (e.g. main:, indicator:) of a widget type |     Generate a schema for the various parts (e.g. main:, indicator:) of a widget type | ||||||
|     :param parts:  The parts to include in the schema |     :param parts:  The parts to include | ||||||
|     :return: The schema |     :return: The schema | ||||||
|     """ |     """ | ||||||
|     return cv.Schema({cv.Optional(part): STATE_SCHEMA for part in parts}).extend( |     return ( | ||||||
|         STATE_SCHEMA |         cv.Schema({cv.Optional(part): STATE_SCHEMA for part in parts}) | ||||||
|  |         .extend(STATE_SCHEMA) | ||||||
|  |         .extend(FLAG_SCHEMA) | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -288,22 +290,18 @@ def base_update_schema(widget_type, parts): | |||||||
|     :param parts:  The allowable parts to specify |     :param parts:  The allowable parts to specify | ||||||
|     :return: |     :return: | ||||||
|     """ |     """ | ||||||
|     return ( |     return part_schema(parts).extend( | ||||||
|         part_schema(parts) |         { | ||||||
|         .extend( |             cv.Required(CONF_ID): cv.ensure_list( | ||||||
|             { |                 cv.maybe_simple_value( | ||||||
|                 cv.Required(CONF_ID): cv.ensure_list( |                     { | ||||||
|                     cv.maybe_simple_value( |                         cv.Required(CONF_ID): cv.use_id(widget_type), | ||||||
|                         { |                     }, | ||||||
|                             cv.Required(CONF_ID): cv.use_id(widget_type), |                     key=CONF_ID, | ||||||
|                         }, |                 ) | ||||||
|                         key=CONF_ID, |             ), | ||||||
|                     ) |             cv.Optional(CONF_STATE): SET_STATE_SCHEMA, | ||||||
|                 ), |         } | ||||||
|                 cv.Optional(CONF_STATE): SET_STATE_SCHEMA, |  | ||||||
|             } |  | ||||||
|         ) |  | ||||||
|         .extend(FLAG_SCHEMA) |  | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -321,7 +319,6 @@ def obj_schema(widget_type: WidgetType): | |||||||
|     """ |     """ | ||||||
|     return ( |     return ( | ||||||
|         part_schema(widget_type.parts) |         part_schema(widget_type.parts) | ||||||
|         .extend(FLAG_SCHEMA) |  | ||||||
|         .extend(LAYOUT_SCHEMA) |         .extend(LAYOUT_SCHEMA) | ||||||
|         .extend(ALIGN_TO_SCHEMA) |         .extend(ALIGN_TO_SCHEMA) | ||||||
|         .extend(automation_schema(widget_type.w_type)) |         .extend(automation_schema(widget_type.w_type)) | ||||||
|   | |||||||
| @@ -24,6 +24,7 @@ from .obj import obj_spec | |||||||
|  |  | ||||||
| CONF_TABVIEW = "tabview" | CONF_TABVIEW = "tabview" | ||||||
| CONF_TAB_STYLE = "tab_style" | CONF_TAB_STYLE = "tab_style" | ||||||
|  | CONF_CONTENT_STYLE = "content_style" | ||||||
|  |  | ||||||
| lv_tab_t = LvType("lv_obj_t") | lv_tab_t = LvType("lv_obj_t") | ||||||
|  |  | ||||||
| @@ -39,6 +40,7 @@ TABVIEW_SCHEMA = cv.Schema( | |||||||
|             ) |             ) | ||||||
|         ), |         ), | ||||||
|         cv.Optional(CONF_TAB_STYLE): part_schema(buttonmatrix_spec.parts), |         cv.Optional(CONF_TAB_STYLE): part_schema(buttonmatrix_spec.parts), | ||||||
|  |         cv.Optional(CONF_CONTENT_STYLE): part_schema(obj_spec.parts), | ||||||
|         cv.Optional(CONF_POSITION, default="top"): DIRECTIONS.one_of, |         cv.Optional(CONF_POSITION, default="top"): DIRECTIONS.one_of, | ||||||
|         cv.Optional(CONF_SIZE, default="10%"): size, |         cv.Optional(CONF_SIZE, default="10%"): size, | ||||||
|     } |     } | ||||||
| @@ -79,6 +81,11 @@ class TabviewType(WidgetType): | |||||||
|                 "tabview_btnmatrix", lv_obj_t, rhs=lv_expr.tabview_get_tab_btns(w.obj) |                 "tabview_btnmatrix", lv_obj_t, rhs=lv_expr.tabview_get_tab_btns(w.obj) | ||||||
|             ) as btnmatrix_obj: |             ) as btnmatrix_obj: | ||||||
|                 await set_obj_properties(Widget(btnmatrix_obj, obj_spec), button_style) |                 await set_obj_properties(Widget(btnmatrix_obj, obj_spec), button_style) | ||||||
|  |         if content_style := config.get(CONF_CONTENT_STYLE): | ||||||
|  |             with LocalVariable( | ||||||
|  |                 "tabview_content", lv_obj_t, rhs=lv_expr.tabview_get_content(w.obj) | ||||||
|  |             ) as content_obj: | ||||||
|  |                 await set_obj_properties(Widget(content_obj, obj_spec), content_style) | ||||||
|  |  | ||||||
|     def obj_creator(self, parent: MockObjClass, config: dict): |     def obj_creator(self, parent: MockObjClass, config: dict): | ||||||
|         return lv_expr.call( |         return lv_expr.call( | ||||||
|   | |||||||
| @@ -781,6 +781,13 @@ lvgl: | |||||||
|                     value: !lambda return (int)((float)rand() / RAND_MAX * 100); |                     value: !lambda return (int)((float)rand() / RAND_MAX * 100); | ||||||
|         - tabview: |         - tabview: | ||||||
|             id: tabview_id |             id: tabview_id | ||||||
|  |             tab_style: | ||||||
|  |               border_color: 0x00FF00 | ||||||
|  |               border_width: 6 | ||||||
|  |               items: | ||||||
|  |                 text_color: 0x0000FF | ||||||
|  |             content_style: | ||||||
|  |               scrollable: false | ||||||
|             width: 100% |             width: 100% | ||||||
|             height: 80% |             height: 80% | ||||||
|             position: top |             position: top | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user