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
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.)
radio_buttonboolAllow only one radio_button sibling to be checked

Flags

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

FlagDescription
hiddenMake the object hidden. (Like it wasn't there at all)
clickableMake the object clickable by the input devices
click_focusableAdd focused state to the object when clicked
checkableToggle checked state when the object is clicked
scrollableMake the object scrollable
scroll_elasticAllow scrolling inside but with slower speed
scroll_momentumMake the object scroll further when 'thrown'
scroll_oneAllow scrolling only one snappable children
scroll_chain_horAllow propagating the horizontal scroll to a parent
scroll_chain_verAllow propagating the vertical scroll to a parent
scroll_chainSCROLL_CHAIN_HOR and SCROLL_CHAIN_VER
scroll_on_focusAutomatically scroll object to make it visible when focused
scroll_with_arrowAllow scrolling the focused object with arrow keys
snappableIf scroll snap is enabled on the parent it can snap to this object
press_lockKeep the object pressed even if the press slid from the object
event_bubblePropagate the events to the parent too
event_trickleSend events to children first
state_tricklePropagate state changes to children
gesture_bubblePropagate the gestures to the parent
adv_hittestAllow performing more accurate hit (click) test. E.g. consider rounded corners.
ignore_layoutMake the object not positioned by the layouts
floatingDo not scroll the object when the parent scrolls and ignore layout
send_draw_task_eventsSend LV_EVENT_DRAW_TASK_ADDED events
overflow_visibleDo not clip the children to the parent's ext draw size
flex_in_new_trackStart a new flex track on this item

State flags

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

StateDescription
checkedMark widget as checked (e.g. switch or checkbox)
focusedMark widget as focused
focus_keyMark widget as focused via key navigation
editedMark widget as being edited (e.g. text input)
hoveredMark widget as hovered by a pointer
pressedMark widget as pressed
scrolledMark widget as being scrolled
disabledDisable widget interaction

Styling

<lv_obj-style>

Add a style to the widget

access add

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

<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
triggerarglv_eventEvent to trigger callback (default: clicked)
user_dataargstringOptional user data as a string (default: NULL)

<lv_obj-screen_load_event>

Load another screen on event

access add

NameKindTypeDescription
triggerarglv_eventTrigger event (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
triggerarglv_eventTrigger event (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
triggerarglv_eventTrigger event (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

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

access custom

NameKindTypeDescription
nameargstyleStyle name
selectorargselector+Selector (part+state) (default: 0)
subjectargsubjectSubject to monitor
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