mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[lvgl] Bugfix for tileview (#9938)
This commit is contained in:
		| @@ -15,7 +15,7 @@ from ..defines import ( | |||||||
|     TILE_DIRECTIONS, |     TILE_DIRECTIONS, | ||||||
|     literal, |     literal, | ||||||
| ) | ) | ||||||
| from ..lv_validation import animated, lv_int | from ..lv_validation import animated, lv_int, lv_pct | ||||||
| from ..lvcode import lv, lv_assign, lv_expr, lv_obj, lv_Pvariable | from ..lvcode import lv, lv_assign, lv_expr, lv_obj, lv_Pvariable | ||||||
| from ..schemas import container_schema | from ..schemas import container_schema | ||||||
| from ..types import LV_EVENT, LvType, ObjUpdateAction, lv_obj_t, lv_obj_t_ptr | from ..types import LV_EVENT, LvType, ObjUpdateAction, lv_obj_t, lv_obj_t_ptr | ||||||
| @@ -41,8 +41,8 @@ TILEVIEW_SCHEMA = cv.Schema( | |||||||
|             container_schema( |             container_schema( | ||||||
|                 obj_spec, |                 obj_spec, | ||||||
|                 { |                 { | ||||||
|                     cv.Required(CONF_ROW): lv_int, |                     cv.Required(CONF_ROW): cv.positive_int, | ||||||
|                     cv.Required(CONF_COLUMN): lv_int, |                     cv.Required(CONF_COLUMN): cv.positive_int, | ||||||
|                     cv.GenerateID(): cv.declare_id(lv_tile_t), |                     cv.GenerateID(): cv.declare_id(lv_tile_t), | ||||||
|                     cv.Optional(CONF_DIR, default="ALL"): TILE_DIRECTIONS.several_of, |                     cv.Optional(CONF_DIR, default="ALL"): TILE_DIRECTIONS.several_of, | ||||||
|                 }, |                 }, | ||||||
| @@ -63,21 +63,29 @@ class TileviewType(WidgetType): | |||||||
|         ) |         ) | ||||||
|  |  | ||||||
|     async def to_code(self, w: Widget, config: dict): |     async def to_code(self, w: Widget, config: dict): | ||||||
|         for tile_conf in config.get(CONF_TILES, ()): |         tiles = config[CONF_TILES] | ||||||
|  |         for tile_conf in tiles: | ||||||
|             w_id = tile_conf[CONF_ID] |             w_id = tile_conf[CONF_ID] | ||||||
|             tile_obj = lv_Pvariable(lv_obj_t, w_id) |             tile_obj = lv_Pvariable(lv_obj_t, w_id) | ||||||
|             tile = Widget.create(w_id, tile_obj, tile_spec, tile_conf) |             tile = Widget.create(w_id, tile_obj, tile_spec, tile_conf) | ||||||
|             dirs = tile_conf[CONF_DIR] |             dirs = tile_conf[CONF_DIR] | ||||||
|             if isinstance(dirs, list): |             if isinstance(dirs, list): | ||||||
|                 dirs = "|".join(dirs) |                 dirs = "|".join(dirs) | ||||||
|  |             row_pos = tile_conf[CONF_ROW] | ||||||
|  |             col_pos = tile_conf[CONF_COLUMN] | ||||||
|             lv_assign( |             lv_assign( | ||||||
|                 tile_obj, |                 tile_obj, | ||||||
|                 lv_expr.tileview_add_tile( |                 lv_expr.tileview_add_tile(w.obj, col_pos, row_pos, literal(dirs)), | ||||||
|                     w.obj, tile_conf[CONF_COLUMN], tile_conf[CONF_ROW], literal(dirs) |  | ||||||
|                 ), |  | ||||||
|             ) |             ) | ||||||
|  |             # Bugfix for LVGL 8.x | ||||||
|  |             lv_obj.set_pos(tile_obj, lv_pct(col_pos * 100), lv_pct(row_pos * 100)) | ||||||
|             await set_obj_properties(tile, tile_conf) |             await set_obj_properties(tile, tile_conf) | ||||||
|             await add_widgets(tile, tile_conf) |             await add_widgets(tile, tile_conf) | ||||||
|  |         if tiles: | ||||||
|  |             # Set the first tile as active | ||||||
|  |             lv_obj.set_tile_id( | ||||||
|  |                 w.obj, tiles[0][CONF_COLUMN], tiles[0][CONF_ROW], literal("LV_ANIM_OFF") | ||||||
|  |             ) | ||||||
|  |  | ||||||
|  |  | ||||||
| tileview_spec = TileviewType() | tileview_spec = TileviewType() | ||||||
|   | |||||||
| @@ -738,7 +738,7 @@ lvgl: | |||||||
|                     id: bar_id |                     id: bar_id | ||||||
|                     value: !lambda return (int)((float)rand() / RAND_MAX * 100); |                     value: !lambda return (int)((float)rand() / RAND_MAX * 100); | ||||||
|                     start_value: !lambda return (int)((float)rand() / RAND_MAX * 100); |                     start_value: !lambda return (int)((float)rand() / RAND_MAX * 100); | ||||||
|                     mode: symmetrical |                     mode: range | ||||||
|                 - logger.log: |                 - logger.log: | ||||||
|                     format: "bar value %f" |                     format: "bar value %f" | ||||||
|                     args: [x] |                     args: [x] | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user