Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LVGL add lv.draw_label_dsc and lv_bar.get_indic_area #20936

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

s-hadinger
Copy link
Collaborator

Description:

Add missing definition to make the example https://docs.lvgl.io/master/examples.html#custom-drawer-to-show-the-current-value work.

Here is the code:

#https://docs.lvgl.io/master/examples.html#custom-drawer-to-show-the-current-value
#- start LVGL and init environment -#
lv.start()

hres = lv.get_hor_res()       # should be 320
vres = lv.get_ver_res()       # should be 240

scr = lv.scr_act()            # default screan object
f20 = lv.montserrat_font(20)  # load embedded Montserrat 20

bar = lv.bar(scr)
bar.set_size(200,20)
bar.center()

def bar_event(obj, event)
  import introspect
  print(f"{obj=} {event=} {event.get_code()=} {event.get_layer()=}")
  var label_dsc = lv.draw_label_dsc()
  lv.draw_label_dsc_init(label_dsc)
  label_dsc.font = f20._p

  var buf = str(obj.get_value())
  var txt_size = lv.point()
  lv.text_get_size(txt_size, buf, f20, label_dsc.letter_space, label_dsc.line_space, lv.COORD_MAX, label_dsc.flag)

  var txt_area = lv.area()
  txt_area.x1 = 0
  txt_area.x2 = txt_size.x - 1
  txt_area.y1 = 0
  txt_area.y2 = txt_size.y - 1

  label_dsc.text = introspect.toptr(buf)
  label_dsc.text_local = true

  var indic_area = obj.get_indic_area()
  if (lv.area_get_width(indic_area) > txt_size.x + 20)
    lv.area_align(indic_area, txt_area, lv.ALIGN_RIGHT_MID, -10, 0)
    label_dsc.color = lv.COLOR_WHITE
  else
    lv.area_align(indic_area, txt_area, lv.ALIGN_OUT_RIGHT_MID, 10, 0)
    label_dsc.color = lv.COLOR_WHITE
  end

  var layer = event.get_layer()
  lv.draw_label(layer, label_dsc, txt_area)

end

bar.add_event_cb(bar_event, lv.EVENT_DRAW_MAIN_END, 0)

bar.set_value(20, lv.ANIM_OFF)

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.6
  • The code change is tested and works with Tasmota core ESP32 V.2.0.14
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@s-hadinger s-hadinger merged commit f488ef9 into arendst:development Mar 12, 2024
64 checks passed
@s-hadinger s-hadinger deleted the lvgl_draw_label_dsc branch March 12, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant