Base Widget (lv_obj)

The Base Widget every other widget inherits from, and the generic container used to compose layouts in XML.

Overview

lv_obj is the Base Widget every other widget is built on. On its own it is a simple, stylable rectangle, but it carries the full common feature set — position and size, layouts, scrolling, styles, parts and states, flags, events and data bindings — so everything documented on this page is also available on every other widget.

In XML it doubles as the generic container you reach for when composing layouts and grouping children.

Learn more in the LVGL Open documentation.

lv_example_obj.c

Properties

Parts

Style parts of the widget with local style (e.g. style_bg_color-knob="0xff0000") or with style sheets (e.g. <style name="style_knob" selector="knob">). See Styles to learn more.

PartDescription
mainStyle the widget's main area: background, border, outline, shadow and padding properties.
scrollbarStyle the scrollbars: width (thickness), background properties, and padding on the respective side. base_dir='rtl' moves the vertical scrollbar to the left.

Properties below are the widget's XML <api>; see API for how properties, parameters and elements work.

PropertyTypeDescription
namestringObject name (for lv_obj_find_by_name or debugging)
xpx|%Set X position (px or %)
ypx|%Set Y position (px or %)
heightpx|%|contentSet height (px, % or content)
widthpx|%|contentSet width (px, % or content)
alignenum:lv_alignAlign on parent
ext_click_areaintExtra clickable area around object in px
ext_draw_sizeintExtra area around the object to redraw in px, for drawings that go beyond its edges
scroll_direnum:lv_dirDirections the object can be scrolled in
scroll_snap_xenum:lv_scroll_snapSnap children horizontally
scroll_snap_yenum:lv_scroll_snapSnap children vertically
scrollbar_modeenum:lv_scrollbar_modeSet the scrollbar mode
flex_growintSet flex grow to fill the available space in the track
flex_flowenum:lv_flex_flowSet flex flow direction (row, column, etc.)
checkedboolMark widget as checked (e.g. switch or checkbox)
focusedboolMark widget as focused
focus_keyboolMark widget as focused via key navigation
editedboolMark widget as being edited (e.g. text input)
hoveredboolMark widget as hovered by a pointer
pressedboolMark widget as pressed
scrolledboolMark widget as being scrolled
disabledboolDisable widget interaction
hiddenboolMake the object hidden. (Like it wasn't there at all)
clickableboolMake the object clickable by the input devices
click_focusableboolAdd focused state to the object when clicked
checkableboolToggle checked state when the object is clicked
scrollableboolMake the object scrollable
scroll_elasticboolAllow scrolling inside but with slower speed
scroll_momentumboolMake the object scroll further when 'thrown'
scroll_oneboolAllow scrolling only one snappable children
scroll_chain_horboolAllow propagating the horizontal scroll to a parent
scroll_chain_verboolAllow propagating the vertical scroll to a parent
scroll_chainboolSCROLL_CHAIN_HOR and SCROLL_CHAIN_VER
scroll_on_focusboolAutomatically scroll object to make it visible when focused
scroll_with_arrowboolAllow scrolling the focused object with arrow keys
snappableboolIf scroll snap is enabled on the parent it can snap to this object
press_lockboolKeep the object pressed even if the press slid from the object
event_bubbleboolPropagate the events to the parent too
event_trickleboolSend events to children first
state_trickleboolPropagate state changes to children
gesture_bubbleboolPropagate the gestures to the parent
adv_hittestboolAllow performing more accurate hit (click) test. E.g. consider rounded corners.
ignore_layoutboolMake the object not positioned by the layouts
floatingboolDo not scroll the object when the parent scrolls and ignore layout
send_draw_task_eventsboolSend LV_EVENT_DRAW_TASK_ADDED events
overflow_visibleboolDo not clip the children to the parent's ext draw size
radio_buttonboolAllow only one radio_button sibling to be checked
flex_in_new_trackboolStart a new flex track on this item

Flags

Boolean object flags — set as flag="true" / "false".

State flags

Force a widget state on or off — set as state="true" / "false".

Styling

<lv_obj-style>

Add a style to the widget

access add_set

NameKindTypeDescription
nameargstyleStyle name
selectorargselector+Target part and state, can be ORed, e.g. pressed|knob (default: 0)
enabledpropboolWhile false the style looks like it wasn't added. The style keeps its place in the style list, so its priority never changes. Can be bound, e.g. enabled="{temperature > 30}"

<lv_obj-remove_style>

Remove a style from the widget

access custom

NameKindTypeDescription
nameargstyleStyle name (NULL means all) (default: NULL)
selectorargselector+Target part and state, can be ORed, e.g. pressed|knob (default: 0)

<lv_obj-remove_style_all>

Remove all styles

access custom

No attributes — created as an empty child.

Local style properties

Any style property can be set directly on a widget as a style_<property> attribute. These are local styles — they affect only that one instance. Add a -<part> and/or -<state> selector to target a part or state:

xml
<lv_obj
  style_bg_color="0x1f2937"
  style_bg_color-pressed="0x111827"
  style_radius="8" />

lv_obj exposes the full style catalogue (style_bg_color, style_pad_all, style_text_font, …) — too many to list here. See Style Properties for the complete list, and Styles for selectors, parts, states and reusable named <style> sheets.

Events

Attach behaviour that runs on an lv_event trigger.

<lv_obj-event_cb>

Attach an event callback

access add

NameKindTypeDescription
callbackargevent_cbCallback function
triggerargtriggerAn event name, or a condition {expr}. A condition on a subject fires on every false-to-true change, one without is decided at creation (default: clicked)
user_dataargstringOptional user data as a string (default: NULL)

<lv_obj-screen_load_event>

Load another screen on event

access add

NameKindTypeDescription
triggerargtriggerAn event name, or a condition {expr}. A condition on a subject fires on every false-to-true change, one without is decided at creation (default: clicked)
screenargscreenTarget screen
anim_typeargenum:lv_screen_load_animLoad animation (default: none)
durationargintAnimation duration (ms) (default: 0)
delayargintStart delay (ms) (default: 0)

<lv_obj-screen_create_event>

Create + load a new screen on event

access add

NameKindTypeDescription
triggerargtriggerAn event name, or a condition {expr}. A condition on a subject fires on every false-to-true change, one without is decided at creation (default: clicked)
screenargscreen_create_cbScreen create callback
anim_typeargenum:lv_screen_load_animLoad animation (default: none)
durationargintAnimation duration (ms) (default: 0)
delayargintStart delay (ms) (default: 0)

<lv_obj-play_timeline_event>

Play a timeline on event

access add

NameKindTypeDescription
triggerargtriggerAn event name, or a condition {expr}. A condition on a subject fires on every false-to-true change, one without is decided at creation (default: clicked)
targetarglv_obj|selfTimeline target
timelineargtimelineTimeline to play
delayargintStart delay (ms) (default: 0)
reverseargboolPlay in reverse (default: false)

<lv_obj-subject_toggle_event>

Toggle an int subject's value on an a trigger. Prefer

access add

NameKindTypeDescription
subjectargsubjectTarget subject
triggerarglv_eventTrigger event (default: clicked)

<lv_obj-subject_set_int_event>

Set a subject (int) on event

access add

NameKindTypeDescription
subjectargsubjectTarget subject
triggerarglv_eventTrigger event (default: clicked)
valueargintValue to assign

<lv_obj-subject_set_float_event>

Set subject (float) on event

access add

NameKindTypeDescription
subjectargsubjectTarget subject
triggerarglv_eventTrigger event (default: clicked)
valueargfloatValue to assign

<lv_obj-subject_set_string_event>

Set subject (string) on event

access add

NameKindTypeDescription
subjectargsubjectTarget subject
triggerarglv_eventTrigger event (default: clicked)
valueargstringValue to assign

<lv_obj-subject_increment_event>

Increment (or decrement) an int subject's value on an event

access add · returns lv_subject_increment_dsc

NameKindTypeDescription
subjectargsubjectSubject to change
triggerarglv_eventTrigger event (default: clicked)
stepargintValue to add on trigger (can be negative to decrement) (default: 1)
rolloverpropboolfalse: stop at the min/max value; true: jump to the other end
min_valuepropintMinimum value to set
max_valuepropintMaximum value to set

Data bindings

Drive widget state, flags or styles from an observer subject.

<lv_obj-bind_style>

Bind a style to a subject value. For a condition use <style enabled="{...}"> instead

access custom

NameKindTypeDescription
nameargstyleStyle name
selectorargselector+Selector (part+state) (default: 0)
subjectargsubjectSubject to monitor (with ref_value)
ref_valueargintValue that activates the style

<lv_obj-bind_style_prop>

Bind a style to a subject value

access custom

NameKindTypeDescription
propargstyle_propName of a style property
selectorargselector+Selector (part and/or state) (default: 0)
subjectargsubjectSubject to bind

Bound properties

PropertyTypeDescription
bind_checkedsubjectBind widget’s checked state to a subject

<lv_obj-bind_flag_if_*>

Set or clear an object flag from a subject. One element per comparison — operators: eq, not_eq, gt, ge, lt, le (e.g. <lv_obj-bind_flag_if_eq>).

NameTypeDescription
subjectsubjectSubject to monitor
flagenum:lv_obj_flagFlag to set/clear
ref_valueintReference value

<lv_obj-bind_state_if_*>

Apply a widget state from a subject. One element per comparison — operators: eq, not_eq, gt, ge, lt, le (e.g. <lv_obj-bind_state_if_eq>).

NameTypeDescription
subjectsubjectSubject to monitor
stateenum:lv_stateState to apply
ref_valueintReference value to compare the subject against

Last updated on

On this page