mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 15:10:51 +00:00
[lvgl] Update function and type names (#15109)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -31,7 +31,7 @@ GRADIENT_SCHEMA = cv.ensure_list(
|
||||
cv.Required(CONF_DIRECTION): cv.one_of(
|
||||
"HOR", "HORIZONTAL", "VER", "VERTICAL", upper=True
|
||||
),
|
||||
cv.Optional(CONF_DITHER, default="NONE"): LV_DITHER.one_of,
|
||||
cv.Optional(CONF_DITHER): LV_DITHER.one_of,
|
||||
cv.Required(CONF_STOPS): cv.All(
|
||||
[
|
||||
cv.Schema(
|
||||
|
||||
@@ -43,14 +43,14 @@
|
||||
on_boot:
|
||||
lvgl.widget.refresh: hello_world_title_
|
||||
hidden: !lambda |-
|
||||
return lv_obj_get_width(lv_scr_act()) < 400;
|
||||
return lv_obj_get_width(lv_screen_active()) < 400;
|
||||
- checkbox:
|
||||
text: Checkbox
|
||||
id: hello_world_checkbox_
|
||||
on_boot:
|
||||
lvgl.widget.refresh: hello_world_checkbox_
|
||||
hidden: !lambda |-
|
||||
return lv_obj_get_width(lv_scr_act()) < 240;
|
||||
return lv_obj_get_width(lv_screen_active()) < 240;
|
||||
on_click:
|
||||
lvgl.label.update:
|
||||
id: hello_world_label_
|
||||
@@ -94,7 +94,7 @@
|
||||
outline_width: 0
|
||||
border_width: 0
|
||||
hidden: !lambda |-
|
||||
return lv_obj_get_width(lv_scr_act()) < 300 && lv_obj_get_height(lv_scr_act()) < 400;
|
||||
return lv_obj_get_width(lv_screen_active()) < 300 && lv_obj_get_height(lv_screen_active()) < 400;
|
||||
widgets:
|
||||
- label:
|
||||
text_font: montserrat_14
|
||||
|
||||
@@ -172,18 +172,18 @@ void LvglComponent::add_page(LvPageType *page) {
|
||||
page->setup(this->pages_.size() - 1);
|
||||
}
|
||||
|
||||
void LvglComponent::show_page(size_t index, lv_scr_load_anim_t anim, uint32_t time) {
|
||||
void LvglComponent::show_page(size_t index, lv_screen_load_anim_t anim, uint32_t time) {
|
||||
if (index >= this->pages_.size())
|
||||
return;
|
||||
this->current_page_ = index;
|
||||
if (anim == LV_SCREEN_LOAD_ANIM_NONE) {
|
||||
lv_scr_load(this->pages_[this->current_page_]->obj);
|
||||
lv_screen_load(this->pages_[this->current_page_]->obj);
|
||||
} else {
|
||||
lv_scr_load_anim(this->pages_[this->current_page_]->obj, anim, time, 0, false);
|
||||
lv_screen_load_anim(this->pages_[this->current_page_]->obj, anim, time, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
void LvglComponent::show_next_page(lv_scr_load_anim_t anim, uint32_t time) {
|
||||
void LvglComponent::show_next_page(lv_screen_load_anim_t anim, uint32_t time) {
|
||||
if (this->pages_.empty() || (this->current_page_ == this->pages_.size() - 1 && !this->page_wrap_))
|
||||
return;
|
||||
size_t start = this->current_page_;
|
||||
@@ -195,7 +195,7 @@ void LvglComponent::show_next_page(lv_scr_load_anim_t anim, uint32_t time) {
|
||||
this->show_page(this->current_page_, anim, time);
|
||||
}
|
||||
|
||||
void LvglComponent::show_prev_page(lv_scr_load_anim_t anim, uint32_t time) {
|
||||
void LvglComponent::show_prev_page(lv_screen_load_anim_t anim, uint32_t time) {
|
||||
if (this->pages_.empty() || (this->current_page_ == 0 && !this->page_wrap_))
|
||||
return;
|
||||
size_t start = this->current_page_;
|
||||
|
||||
@@ -163,7 +163,7 @@ class LvglComponent : public PollingComponent {
|
||||
static void render_end_cb(lv_event_t *event);
|
||||
static void render_start_cb(lv_event_t *event);
|
||||
void dump_config() override;
|
||||
lv_disp_t *get_disp() { return this->disp_; }
|
||||
lv_display_t *get_disp() { return this->disp_; }
|
||||
lv_obj_t *get_screen_active() { return lv_display_get_screen_active(this->disp_); }
|
||||
// Pause or resume the display.
|
||||
// @param paused If true, pause the display. If false, resume the display.
|
||||
@@ -189,9 +189,9 @@ class LvglComponent : public PollingComponent {
|
||||
lv_event_code_t event3);
|
||||
|
||||
void add_page(LvPageType *page);
|
||||
void show_page(size_t index, lv_scr_load_anim_t anim, uint32_t time);
|
||||
void show_next_page(lv_scr_load_anim_t anim, uint32_t time);
|
||||
void show_prev_page(lv_scr_load_anim_t anim, uint32_t time);
|
||||
void show_page(size_t index, lv_screen_load_anim_t anim, uint32_t time);
|
||||
void show_next_page(lv_screen_load_anim_t anim, uint32_t time);
|
||||
void show_prev_page(lv_screen_load_anim_t anim, uint32_t time);
|
||||
void set_page_wrap(bool wrap) { this->page_wrap_ = wrap; }
|
||||
void set_big_endian(bool big_endian) { this->big_endian_ = big_endian; }
|
||||
size_t get_current_page() const;
|
||||
|
||||
@@ -250,9 +250,17 @@ STYLE_REMAP = {
|
||||
}
|
||||
|
||||
|
||||
def remap_property(prop):
|
||||
def remap_property(prop, record=True):
|
||||
"""
|
||||
Remap an old style property to new style property.
|
||||
Optionally record the use of the deprecated property.
|
||||
:param prop: Name of the style property to remap.
|
||||
:param record: Whether to record the use of the deprecated property.
|
||||
:return: The remapped property name, or ``prop`` if no remapping exists.
|
||||
"""
|
||||
if prop in STYLE_REMAP:
|
||||
get_remapped_uses().add(prop)
|
||||
if record:
|
||||
get_remapped_uses().add(prop)
|
||||
return STYLE_REMAP[prop]
|
||||
return prop
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ async def generate_triggers():
|
||||
dir = DIRECTIONS.mapper(dir)
|
||||
w.clear_flag("LV_OBJ_FLAG_SCROLLABLE")
|
||||
selected = literal(
|
||||
f"lv_indev_get_gesture_dir(lv_indev_get_act()) == {dir}"
|
||||
f"lv_indev_get_gesture_dir(lv_indev_active()) == {dir}"
|
||||
)
|
||||
await add_trigger(
|
||||
conf, w, literal("LV_EVENT_GESTURE"), is_selected=selected
|
||||
|
||||
@@ -59,7 +59,6 @@ lv_style_t = cg.global_ns.struct("lv_style_t")
|
||||
lv_pseudo_button_t = lvgl_ns.class_("LvPseudoButton")
|
||||
lv_obj_base_t = cg.global_ns.class_("lv_obj_t", lv_pseudo_button_t)
|
||||
lv_obj_t_ptr = lv_obj_base_t.operator("ptr")
|
||||
lv_disp_t = cg.global_ns.struct("lv_disp_t")
|
||||
lv_color_t = cg.global_ns.struct("lv_color_t")
|
||||
lv_opa_t = cg.global_ns.struct("lv_opa_t")
|
||||
lv_group_t = cg.global_ns.struct("lv_group_t")
|
||||
@@ -67,7 +66,7 @@ LVTouchListener = lvgl_ns.class_("LVTouchListener")
|
||||
LVEncoderListener = lvgl_ns.class_("LVEncoderListener")
|
||||
lv_obj_t = LvType("lv_obj_t")
|
||||
lv_page_t = LvType("LvPageType", parents=(LvCompound,))
|
||||
lv_img_t = LvType("lv_img_t")
|
||||
lv_image_t = LvType("lv_image_t")
|
||||
lv_gradient_t = LvType("lv_grad_dsc_t")
|
||||
lv_event_t = LvType("lv_event_t")
|
||||
|
||||
|
||||
@@ -369,7 +369,9 @@ def _scale_map(config):
|
||||
|
||||
|
||||
def _get_prop_validator(prop):
|
||||
return STYLE_PROPS.get(f"transform_{remap_property(prop)}") or STYLE_PROPS.get(prop)
|
||||
return STYLE_PROPS.get(
|
||||
f"transform_{remap_property(prop, False)}"
|
||||
) or STYLE_PROPS.get(prop)
|
||||
|
||||
|
||||
def _prop_validator(prop):
|
||||
|
||||
@@ -17,7 +17,7 @@ from ..defines import (
|
||||
CONF_ZOOM,
|
||||
)
|
||||
from ..lv_validation import lv_angle, lv_bool, lv_image, scale, size
|
||||
from ..types import lv_img_t
|
||||
from ..types import lv_image_t
|
||||
from . import Widget, WidgetType
|
||||
from .label import CONF_LABEL
|
||||
|
||||
@@ -55,7 +55,7 @@ class ImgType(WidgetType):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
CONF_IMAGE,
|
||||
lv_img_t,
|
||||
lv_image_t,
|
||||
(CONF_MAIN,),
|
||||
IMG_SCHEMA,
|
||||
IMG_MODIFY_SCHEMA,
|
||||
|
||||
@@ -73,7 +73,7 @@ from ..types import (
|
||||
LvType,
|
||||
ObjUpdateAction,
|
||||
lv_event_t,
|
||||
lv_img_t,
|
||||
lv_image_t,
|
||||
lv_obj_t,
|
||||
)
|
||||
from . import Widget, WidgetType, get_widgets, widget_to_code
|
||||
@@ -205,7 +205,7 @@ INDICATOR_SCHEMA = cv.Schema(
|
||||
INDICATOR_IMG_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(lv_meter_indicator_image_t),
|
||||
cv.GenerateID(CONF_IMAGE_ID): cv.declare_id(lv_img_t),
|
||||
cv.GenerateID(CONF_IMAGE_ID): cv.declare_id(lv_image_t),
|
||||
}
|
||||
),
|
||||
requires_component("image"),
|
||||
|
||||
@@ -29,7 +29,7 @@ lv_tile_t = LvType("lv_tileview_tile_t")
|
||||
lv_tileview_t = LvType(
|
||||
"lv_tileview_t",
|
||||
largs=[(lv_obj_t_ptr, "tile")],
|
||||
lvalue=lambda w: w.get_property("tile_act"),
|
||||
lvalue=lambda w: w.get_property("tile_active"),
|
||||
has_on_value=True,
|
||||
)
|
||||
|
||||
@@ -85,7 +85,7 @@ class TileviewType(WidgetType):
|
||||
await add_widgets(tile, tile_conf)
|
||||
if tiles:
|
||||
# Set the first tile as active
|
||||
lv_obj.set_tile_id(
|
||||
lv.tileview_set_tile_by_index(
|
||||
w.obj, tiles[0][CONF_COLUMN], tiles[0][CONF_ROW], literal("LV_ANIM_OFF")
|
||||
)
|
||||
|
||||
@@ -122,11 +122,11 @@ async def tileview_select(config, action_id, template_arg, args):
|
||||
async def do_select(w: Widget):
|
||||
if tile := config.get(CONF_TILE_ID):
|
||||
tile = await cg.get_variable(tile)
|
||||
lv_obj.set_tile(w.obj, tile, literal(config[CONF_ANIMATED]))
|
||||
lv.tileview_set_tile(w.obj, tile, literal(config[CONF_ANIMATED]))
|
||||
else:
|
||||
row = await lv_int.process(config[CONF_ROW])
|
||||
column = await lv_int.process(config[CONF_COLUMN])
|
||||
lv_obj.set_tile_id(
|
||||
lv.tileview_set_tile_by_index(
|
||||
widgets[0].obj, column, row, literal(config[CONF_ANIMATED])
|
||||
)
|
||||
lv.event_send(w.obj, LV_EVENT.VALUE_CHANGED, cg.nullptr)
|
||||
|
||||
@@ -43,9 +43,6 @@ lvgl:
|
||||
start_value: 0
|
||||
end_value: 180
|
||||
bg_color: light_blue
|
||||
disp_bg_color: color_id
|
||||
disp_bg_image: cat_image
|
||||
disp_bg_opa: cover
|
||||
bottom_layer:
|
||||
widgets:
|
||||
- obj:
|
||||
@@ -58,7 +55,6 @@ lvgl:
|
||||
gradients:
|
||||
- id: color_bar
|
||||
direction: hor
|
||||
# dither: err_diff
|
||||
stops:
|
||||
- color: 0xFF0000
|
||||
position: 0
|
||||
@@ -143,12 +139,11 @@ lvgl:
|
||||
body:
|
||||
text: This is a sample messagebox
|
||||
bg_color: 0x808080
|
||||
button_style:
|
||||
bg_color: 0xff00
|
||||
border_width: 4
|
||||
buttons:
|
||||
- id: msgbox_button
|
||||
text: Button
|
||||
bg_color: 0x00ff00
|
||||
border_width: 4
|
||||
- id: msgbox_apply
|
||||
text: "Close"
|
||||
on_click:
|
||||
@@ -160,8 +155,8 @@ lvgl:
|
||||
bg_opa: !lambda return 0.5;
|
||||
- lvgl.image.update:
|
||||
id: lv_image
|
||||
zoom: !lambda return 512;
|
||||
angle: !lambda return 100;
|
||||
scale: !lambda return 512;
|
||||
rotation: !lambda return 100;
|
||||
pivot_x: !lambda return 20;
|
||||
pivot_y: !lambda return 20;
|
||||
offset_x: !lambda return 20;
|
||||
@@ -287,8 +282,8 @@ lvgl:
|
||||
then:
|
||||
- lvgl.animimg.stop: anim_img
|
||||
- lvgl.update:
|
||||
disp_bg_color: 0xffff00
|
||||
disp_bg_image: none
|
||||
bottom_layer:
|
||||
bg_color: 0xffff00
|
||||
- lvgl.widget.show: message_box
|
||||
- label:
|
||||
text: "Hello shiny day"
|
||||
@@ -361,8 +356,6 @@ lvgl:
|
||||
pad_right: 10px
|
||||
pad_top: 10px
|
||||
shadow_color: light_blue
|
||||
shadow_ofs_x: 5
|
||||
shadow_ofs_y: 5
|
||||
shadow_opa: cover
|
||||
shadow_spread: 5
|
||||
shadow_width: 10
|
||||
@@ -373,12 +366,10 @@ lvgl:
|
||||
text_letter_space: 4
|
||||
text_line_space: 4
|
||||
text_opa: cover
|
||||
transform_angle: 180
|
||||
transform_rotation: 90
|
||||
transform_height: 100
|
||||
transform_pivot_x: 50%
|
||||
transform_pivot_y: 50%
|
||||
transform_zoom: 0.5
|
||||
transform_scale: 2.0
|
||||
transform_scale_x: 1.5
|
||||
transform_scale_y: 0.8
|
||||
@@ -470,11 +461,11 @@ lvgl:
|
||||
id: button_button
|
||||
width: 20%
|
||||
height: 10%
|
||||
transform_angle: !lambda return(180*100);
|
||||
transform_rotation: !lambda return(180*100);
|
||||
arc_width: !lambda return 4;
|
||||
border_width: !lambda return 6;
|
||||
shadow_ofs_x: !lambda return 6;
|
||||
shadow_ofs_y: !lambda return 6;
|
||||
shadow_offset_x: !lambda return 6;
|
||||
shadow_offset_y: !lambda return 6;
|
||||
shadow_spread: !lambda return 6;
|
||||
shadow_width: !lambda return 6;
|
||||
pressed:
|
||||
@@ -646,8 +637,8 @@ lvgl:
|
||||
border_opa: 80%
|
||||
shadow_color: black
|
||||
shadow_width: 10
|
||||
shadow_ofs_x: 5
|
||||
shadow_ofs_y: 5
|
||||
shadow_offset_x: 5
|
||||
shadow_offset_y: 5
|
||||
shadow_spread: 4
|
||||
shadow_opa: cover
|
||||
outline_color: red
|
||||
|
||||
Reference in New Issue
Block a user