Skip to main content

graphics_bindgen/
abi.rs

1//! The supported guest ABI: which catalog calls the executor implements, their
2//! argument types and result kinds, and how each one is adapted.
3//!
4//! Core's build script generates the executor's call table from this list, and
5//! guest bindings select the same calls, so both sides share one declaration.
6//! Call IDs come from the catalog; the list never assigns them.
7
8use crate::registry::{
9    AdapterRule, AutoObjectScalar, GraphicsRegistry, KindTable, ObjectOperation, StyleValue,
10};
11use crate::{CallCatalog, GeneratorError};
12
13/// Catalog name, argument types, result kind, and the native return type.
14pub type Declaration = (
15    &'static str,
16    &'static [&'static str],
17    &'static str,
18    Option<&'static str>,
19);
20
21/// Calls that match the LVGL C API, in the order they were first exposed.
22#[rustfmt::skip]
23pub const SUPPORTED: &[Declaration] = &[
24    ("window_create", &[], "Word", Some("*mut lv_obj_t")),
25    ("file_picker_create", &["*mut lv_obj_t", "u32", "*const core::ffi::c_char"], "Word", Some("*mut lv_obj_t")),
26    ("file_picker_reset", &["*mut lv_obj_t", "u32", "*const core::ffi::c_char"], "None", None),
27    ("file_picker_get_status", &["*mut lv_obj_t"], "U32", Some("u32")),
28    ("file_picker_get_path", &["*mut lv_obj_t", "*mut i8", "usize"], "I32", Some("i32")),
29    ("window_set_icon", &["*mut lv_obj_t", "*const core::ffi::c_char", "lv_color_t"], "None", None),
30    ("window_pop_event", &["*mut lv_obj_t", "*mut u32", "*mut WasmPointer"], "None", None),
31    ("percentage", &["i32"], "I32", Some("i32")),
32    ("object_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
33    ("object_delete", &["u32"], "None", None),
34    ("object_set_flex_flow", &["*mut lv_obj_t", "lv_flex_flow_t"], "None", None),
35    ("object_set_flex_grow", &["*mut lv_obj_t", "u8"], "None", None),
36    ("object_set_height", &["*mut lv_obj_t", "i32"], "None", None),
37    ("object_set_width", &["*mut lv_obj_t", "i32"], "None", None),
38    ("object_set_size", &["*mut lv_obj_t", "i32", "i32"], "None", None),
39    ("object_set_pos", &["*mut lv_obj_t", "i32", "i32"], "None", None),
40    ("object_get_x", &["*const lv_obj_t"], "I32", Some("i32")),
41    ("object_get_y", &["*const lv_obj_t"], "I32", Some("i32")),
42    ("object_get_width", &["*const lv_obj_t"], "I32", Some("i32")),
43    ("object_get_height", &["*const lv_obj_t"], "I32", Some("i32")),
44    ("object_align", &["*mut lv_obj_t", "lv_align_t", "i32", "i32"], "None", None),
45    ("object_update_layout", &["*const lv_obj_t"], "None", None),
46    ("object_set_flex_align", &["*mut lv_obj_t", "lv_flex_align_t", "lv_flex_align_t", "lv_flex_align_t"], "None", None),
47    ("object_set_layout", &["*mut lv_obj_t", "u32"], "None", None),
48    ("object_set_grid_dsc_array", &["*mut lv_obj_t", "*const i32", "*const i32"], "None", None),
49    ("object_set_grid_align", &["*mut lv_obj_t", "lv_grid_align_t", "lv_grid_align_t"], "None", None),
50    ("object_set_grid_cell", &["*mut lv_obj_t", "lv_grid_align_t", "i32", "i32", "lv_grid_align_t", "i32", "i32"], "None", None),
51    ("grid_fr", &["u8"], "I32", Some("i32")),
52    ("object_add_state", &["*mut lv_obj_t", "lv_state_t"], "None", None),
53    ("object_get_state", &["*const lv_obj_t"], "U32", Some("lv_state_t")),
54    ("button_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
55    ("checkbox_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
56    ("checkbox_set_text", &["*mut lv_obj_t", "*const core::ffi::c_char"], "None", None),
57    ("tabview_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
58    ("tabview_add_tab", &["*mut lv_obj_t", "*const core::ffi::c_char"], "Word", Some("*mut lv_obj_t")),
59    ("tabview_get_tab_active", &["*mut lv_obj_t"], "U32", Some("u32")),
60    ("object_add_flag", &["*mut lv_obj_t", "lv_obj_flag_t"], "None", None),
61    ("label_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
62    ("label_set_text", &["*mut lv_obj_t", "*const core::ffi::c_char"], "None", None),
63    ("buttonmatrix_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
64    ("buttonmatrix_set_map", &["*mut lv_obj_t", "*const *const core::ffi::c_char"], "None", None),
65    ("buttonmatrix_get_selected_button", &["*const lv_obj_t"], "U32", Some("u32")),
66    ("arc_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
67    ("slider_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
68    ("object_remove_state", &["*mut lv_obj_t", "lv_state_t"], "None", None),
69    ("dropdown_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
70    ("dropdown_set_options", &["*mut lv_obj_t", "*const core::ffi::c_char"], "None", None),
71    ("dropdown_set_selected", &["*mut lv_obj_t", "u32"], "None", None),
72    ("dropdown_get_selected", &["*const lv_obj_t"], "U32", Some("u32")),
73    ("dropdown_get_option_count", &["*const lv_obj_t"], "U32", Some("u32")),
74    ("dropdown_set_selected_highlight", &["*mut lv_obj_t", "bool"], "None", None),
75    ("dropdown_open", &["*mut lv_obj_t"], "None", None),
76    ("dropdown_close", &["*mut lv_obj_t"], "None", None),
77    ("roller_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
78    ("roller_set_options", &["*mut lv_obj_t", "*const core::ffi::c_char", "lv_roller_mode_t"], "None", None),
79    ("roller_set_selected", &["*mut lv_obj_t", "u32", "lv_anim_enable_t"], "None", None),
80    ("roller_get_selected", &["*const lv_obj_t"], "U32", Some("u32")),
81    ("roller_get_option_count", &["*const lv_obj_t"], "U32", Some("u32")),
82    ("roller_set_visible_row_count", &["*mut lv_obj_t", "u32"], "None", None),
83    ("calendar_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
84    ("calendar_set_month_shown", &["*mut lv_obj_t", "u32", "u32"], "None", None),
85    ("spinbox_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
86    ("spinbox_set_range", &["*mut lv_obj_t", "i32", "i32"], "None", None),
87    ("spinbox_set_value", &["*mut lv_obj_t", "i32"], "None", None),
88    ("spinbox_get_value", &["*mut lv_obj_t"], "I32", Some("i32")),
89    ("spinbox_set_step", &["*mut lv_obj_t", "u32"], "None", None),
90    ("spinbox_set_digit_format", &["*mut lv_obj_t", "u32", "u32"], "None", None),
91    ("spinbox_set_rollover", &["*mut lv_obj_t", "bool"], "None", None),
92    ("spinbox_increment", &["*mut lv_obj_t"], "None", None),
93    ("spinbox_decrement", &["*mut lv_obj_t"], "None", None),
94    ("chart_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
95    ("chart_set_type", &["*mut lv_obj_t", "lv_chart_type_t"], "None", None),
96    ("chart_set_point_count", &["*mut lv_obj_t", "u32"], "None", None),
97    ("chart_set_axis_range", &["*mut lv_obj_t", "lv_chart_axis_t", "i32", "i32"], "None", None),
98    ("line_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
99    ("line_set_points", &["*mut lv_obj_t", "*const lv_point_precise_t", "u32"], "None", None),
100    ("line_set_y_invert", &["*mut lv_obj_t", "bool"], "None", None),
101    ("tileview_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
102    ("tileview_add_tile", &["*mut lv_obj_t", "u8", "u8", "lv_dir_t"], "Word", Some("*mut lv_obj_t")),
103    ("tileview_set_tile", &["*mut lv_obj_t", "*mut lv_obj_t", "lv_anim_enable_t"], "None", None),
104    ("tileview_get_tile_active", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
105];
106
107/// Xila helpers and widgets added after the first ABI, in append order.
108#[rustfmt::skip]
109pub const EXTRA: &[Declaration] = &[
110    ("object_set_padding", &["*mut lv_obj_t", "i32"], "None", None),
111    ("indexed_canvas_create", &["*mut lv_obj_t", "u16", "u16"], "Word", Some("*mut lv_obj_t")),
112    ("indexed_canvas_set_pixels", &["*mut lv_obj_t", "*const u8", "usize", "*const u32", "usize"], "None", None),
113    ("window_pop_pointer_event", &["*mut lv_obj_t", "*mut u32", "*mut WasmPointer", "*mut i32", "*mut i32", "*mut i32", "*mut i32"], "None", None),
114    ("textarea_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
115    ("textarea_set_one_line", &["*mut lv_obj_t", "bool"], "None", None),
116    ("textarea_set_text", &["*mut lv_obj_t", "*const core::ffi::c_char"], "None", None),
117    ("textarea_set_max_length", &["*mut lv_obj_t", "u32"], "None", None),
118    ("textarea_get_text", &["*mut lv_obj_t", "*mut i8", "usize"], "I32", Some("i32")),
119    ("textarea_get_text_length", &["*mut lv_obj_t"], "I32", Some("i32")),
120    ("keyboard_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
121    ("keyboard_set_textarea", &["*mut lv_obj_t", "*mut lv_obj_t"], "None", None),
122    ("object_remove_flag", &["*mut lv_obj_t", "lv_obj_flag_t"], "None", None),
123    ("object_set_background", &["*mut lv_obj_t", "u32", "u8", "u32"], "None", None),
124    ("object_set_text_color", &["*mut lv_obj_t", "u32", "u32"], "None", None),
125    ("object_set_border", &["*mut lv_obj_t", "u32", "i32", "u32", "u32"], "None", None),
126    ("object_set_radius", &["*mut lv_obj_t", "i32", "u32"], "None", None),
127    ("object_set_text_align", &["*mut lv_obj_t", "u32", "u32"], "None", None),
128    ("object_set_font", &["*mut lv_obj_t", "u32", "u32"], "None", None),
129    ("object_set_surface", &["*mut lv_obj_t", "u32"], "None", None),
130    ("object_set_min_max_size", &["*mut lv_obj_t", "i32", "i32", "i32", "i32", "u32"], "None", None),
131    ("bar_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
132    ("switch_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
133    ("spinner_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
134    ("led_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
135    ("led_set_brightness", &["*mut lv_obj_t", "u8"], "None", None),
136    ("led_on", &["*mut lv_obj_t"], "None", None),
137    ("led_off", &["*mut lv_obj_t"], "None", None),
138    ("led_toggle", &["*mut lv_obj_t"], "None", None),
139    ("range_set_range", &["*mut lv_obj_t", "i32", "i32"], "None", None),
140    ("range_set_value", &["*mut lv_obj_t", "i32", "bool"], "None", None),
141    ("range_get_value", &["*const lv_obj_t"], "I32", Some("i32")),
142    ("range_get_start_value", &["*const lv_obj_t"], "I32", Some("i32")),
143    ("range_set_mode", &["*mut lv_obj_t", "u32"], "None", None),
144    ("range_set_orientation", &["*mut lv_obj_t", "u32"], "None", None),
145    ("spinner_set_animation", &["*mut lv_obj_t", "u32", "u32"], "None", None),
146    ("spinner_get_animation_duration", &["*const lv_obj_t"], "U32", Some("u32")),
147    ("spinner_get_arc_sweep", &["*const lv_obj_t"], "U32", Some("u32")),
148    ("dropdown_get_selected_string", &["*mut lv_obj_t", "*mut i8", "u32"], "I32", Some("i32")),
149    ("roller_get_selected_string", &["*mut lv_obj_t", "*mut i8", "u32"], "I32", Some("i32")),
150    ("dropdown_get_highlight", &["*mut lv_obj_t"], "U32", Some("u32")),
151    ("dropdown_is_open_state", &["*mut lv_obj_t"], "U32", Some("u32")),
152    ("calendar_set_today", &["*mut lv_obj_t", "u32", "u32", "u32"], "None", None),
153    ("calendar_set_highlights", &["*mut lv_obj_t", "*const u8", "usize"], "None", None),
154    ("calendar_get_shown_date", &["*mut lv_obj_t", "*mut u8"], "None", None),
155    ("chart_add_series_slot", &["*mut lv_obj_t", "u32"], "U32", Some("u32")),
156    ("chart_set_values", &["*mut lv_obj_t", "u32", "*const i32", "usize"], "None", None),
157    ("chart_get_value", &["*mut lv_obj_t", "u32", "u32"], "I32", Some("i32")),
158    ("list_add_text_button", &["*mut lv_obj_t", "*const core::ffi::c_char"], "Word", Some("*mut lv_obj_t")),
159    ("list_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
160    ("list_add_text", &["*mut lv_obj_t", "*const core::ffi::c_char"], "Word", Some("*mut lv_obj_t")),
161    ("list_set_button_text", &["*mut lv_obj_t", "*mut lv_obj_t", "*const core::ffi::c_char"], "None", None),
162    ("object_set_theme_variant", &["*mut lv_obj_t", "u32"], "None", None),
163    ("object_set_theme_error", &["*mut lv_obj_t", "bool"], "None", None),
164    ("badge_create", &["*mut lv_obj_t", "*const core::ffi::c_char", "u32"], "Word", Some("*mut lv_obj_t")),
165    ("card_create", &["*mut lv_obj_t"], "Word", Some("*mut lv_obj_t")),
166];
167
168/// Constructors with the `(parent) -> object` shape. Each registers its new
169/// object under the given kind; `window_create` has no parent.
170const CREATE: &[(&str, &str)] = &[
171    ("object_create", "Object"),
172    ("label_create", "Label"),
173    ("button_create", "Button"),
174    ("checkbox_create", "Checkbox"),
175    ("tabview_create", "TabView"),
176    ("buttonmatrix_create", "ButtonMatrix"),
177    ("arc_create", "Arc"),
178    ("slider_create", "Slider"),
179    ("dropdown_create", "Dropdown"),
180    ("roller_create", "Roller"),
181    ("calendar_create", "Calendar"),
182    ("spinbox_create", "Spinbox"),
183    ("chart_create", "Chart"),
184    ("line_create", "Line"),
185    ("tileview_create", "Tileview"),
186    ("textarea_create", "Textarea"),
187    ("keyboard_create", "Keyboard"),
188    ("bar_create", "Bar"),
189    ("switch_create", "Switch"),
190    ("spinner_create", "Spinner"),
191    ("led_create", "Led"),
192    ("list_create", "List"),
193];
194
195use ObjectOperation::{
196    Call, GetBool, GetI32, GetI32ByKind, GetU32, SetBool, SetEnum, SetEnumByKind, SetMask,
197    SetRange, SetRangeByKind, SetStyle, SetText, SetU8, SetU32, SetU32Limit,
198};
199use StyleValue::{Color, Font};
200
201/// Calls on one object: the object kind they require (`None` for any) and
202/// what they do with their words, validated as the operation says. Calls whose
203/// validation is specific to them stay in the handwritten match.
204const OBJECT: &[(&str, Option<&str>, ObjectOperation)] = &[
205    ("object_update_layout", None, Call),
206    ("object_set_flex_grow", None, SetU8),
207    ("object_set_layout", None, SetU32 { min: 0, max: 2 }),
208    (
209        "object_add_flag",
210        None,
211        SetU32 {
212            min: 0,
213            max: u32::MAX,
214        },
215    ),
216    (
217        "object_remove_flag",
218        None,
219        SetU32 {
220            min: 0,
221            max: u32::MAX,
222        },
223    ),
224    ("object_add_state", None, SetMask { mask: 0xF3FD }),
225    ("object_remove_state", None, SetMask { mask: 0xF3FD }),
226    ("object_get_state", None, GetU32),
227    ("led_on", Some("Led"), Call),
228    ("led_off", Some("Led"), Call),
229    ("led_toggle", Some("Led"), Call),
230    ("led_set_brightness", Some("Led"), SetU8),
231    ("spinbox_increment", Some("Spinbox"), Call),
232    ("spinbox_decrement", Some("Spinbox"), Call),
233    (
234        "spinbox_set_step",
235        Some("Spinbox"),
236        SetU32 {
237            min: 1,
238            max: 1_000_000,
239        },
240    ),
241    ("spinbox_set_rollover", Some("Spinbox"), SetBool),
242    ("spinbox_get_value", Some("Spinbox"), GetI32),
243    ("dropdown_open", Some("Dropdown"), Call),
244    ("dropdown_close", Some("Dropdown"), Call),
245    ("dropdown_set_selected_highlight", Some("Dropdown"), SetBool),
246    ("dropdown_get_selected", Some("Dropdown"), GetU32),
247    ("dropdown_get_option_count", Some("Dropdown"), GetU32),
248    ("dropdown_get_highlight", Some("Dropdown"), GetBool),
249    ("dropdown_is_open_state", Some("Dropdown"), GetBool),
250    ("roller_get_selected", Some("Roller"), GetU32),
251    ("roller_get_option_count", Some("Roller"), GetU32),
252    (
253        "roller_set_visible_row_count",
254        Some("Roller"),
255        SetU32 { min: 1, max: 32 },
256    ),
257    (
258        "chart_set_point_count",
259        Some("Chart"),
260        SetU32 { min: 1, max: 128 },
261    ),
262    ("line_set_y_invert", Some("Line"), SetBool),
263    ("textarea_set_one_line", Some("Textarea"), SetBool),
264    ("spinner_get_animation_duration", Some("Spinner"), GetU32),
265    ("spinner_get_arc_sweep", Some("Spinner"), GetU32),
266    ("tabview_get_tab_active", Some("TabView"), GetU32),
267    (
268        "buttonmatrix_get_selected_button",
269        Some("ButtonMatrix"),
270        GetU32,
271    ),
272    (
273        "chart_set_type",
274        Some("Chart"),
275        SetEnum {
276            max: "lv_chart_type_t_LV_CHART_TYPE_SCATTER",
277        },
278    ),
279    (
280        "label_set_text",
281        Some("Label"),
282        SetText {
283            limit: "MAX_STRING_BYTES",
284        },
285    ),
286    (
287        "checkbox_set_text",
288        Some("Checkbox"),
289        SetText {
290            limit: "MAX_STRING_BYTES",
291        },
292    ),
293    (
294        "textarea_set_text",
295        Some("Textarea"),
296        SetText {
297            limit: "MAX_TEXTAREA_BYTES",
298        },
299    ),
300    (
301        "textarea_set_max_length",
302        Some("Textarea"),
303        SetU32Limit { max: 4096 },
304    ),
305    ("spinbox_set_range", Some("Spinbox"), SetRange),
306    ("object_set_text_color", None, SetStyle(Color)),
307    (
308        "object_set_radius",
309        None,
310        SetStyle(StyleValue::I32 { min: 0, max: 1024 }),
311    ),
312    (
313        "object_set_text_align",
314        None,
315        SetStyle(StyleValue::Enum {
316            max: "lv_text_align_t_LV_TEXT_ALIGN_RIGHT",
317        }),
318    ),
319    ("object_set_font", None, SetStyle(Font)),
320    ("range_get_value", None, GetI32ByKind(RANGE_VALUE)),
321    ("range_get_start_value", None, GetI32ByKind(RANGE_START)),
322    (
323        "range_set_mode",
324        None,
325        SetEnumByKind {
326            max: 2,
327            table: RANGE_MODE,
328        },
329    ),
330    (
331        "range_set_orientation",
332        None,
333        SetEnumByKind {
334            max: 2,
335            table: RANGE_ORIENTATION,
336        },
337    ),
338    ("range_set_range", None, SetRangeByKind(RANGE_RANGE)),
339];
340
341// The widgets behind the `range_*` helpers, each with its LVGL function.
342const RANGE_VALUE: KindTable = &[
343    ("Arc", "lv_arc_get_value"),
344    ("Bar", "lv_bar_get_value"),
345    ("Slider", "lv_slider_get_value"),
346];
347const RANGE_START: KindTable = &[
348    ("Bar", "lv_bar_get_start_value"),
349    ("Slider", "lv_slider_get_left_value"),
350];
351const RANGE_MODE: KindTable = &[
352    ("Arc", "lv_arc_set_mode"),
353    ("Bar", "lv_bar_set_mode"),
354    ("Slider", "lv_slider_set_mode"),
355];
356const RANGE_ORIENTATION: KindTable = &[
357    ("Bar", "lv_bar_set_orientation"),
358    ("Slider", "lv_slider_set_orientation"),
359    ("Switch", "lv_switch_set_orientation"),
360];
361const RANGE_RANGE: KindTable = &[
362    ("Arc", "lv_arc_set_range"),
363    ("Bar", "lv_bar_set_range"),
364    ("Slider", "lv_slider_set_range"),
365];
366
367/// Xila helpers that wrap a differently named LVGL function.
368const RENAMED: &[(&str, &str)] = &[
369    (
370        "spinner_get_animation_duration",
371        "lv_spinner_get_anim_duration",
372    ),
373    (
374        "dropdown_get_highlight",
375        "lv_dropdown_get_selected_highlight",
376    ),
377    ("dropdown_is_open_state", "lv_dropdown_is_open"),
378    ("object_set_text_color", "lv_obj_set_style_text_color"),
379    ("object_set_radius", "lv_obj_set_style_radius"),
380    ("object_set_text_align", "lv_obj_set_style_text_align"),
381    ("object_set_font", "lv_obj_set_style_text_font"),
382];
383
384/// Per-call adapters. A call without a rule is dispatched by the executor's
385/// handwritten match.
386pub fn adapter_rules() -> Vec<AdapterRule> {
387    let mut rules: Vec<AdapterRule> = [
388        ("object_set_width", AutoObjectScalar::SetI32),
389        ("object_set_height", AutoObjectScalar::SetI32),
390        ("object_set_pos", AutoObjectScalar::SetPairI32),
391        ("object_set_size", AutoObjectScalar::SetPairI32),
392        ("object_get_x", AutoObjectScalar::GetI32),
393        ("object_get_y", AutoObjectScalar::GetI32),
394        ("object_get_width", AutoObjectScalar::GetI32),
395        ("object_get_height", AutoObjectScalar::GetI32),
396    ]
397    .into_iter()
398    .map(|(name, adapter)| AdapterRule::automatic(name, adapter))
399    .collect();
400    rules.extend(OBJECT.iter().map(|(name, kind, operation)| {
401        let native = RENAMED
402            .iter()
403            .find(|(call, _)| call == name)
404            .map(|(_, f)| *f);
405        AdapterRule::object(name, *kind, *operation, native)
406    }));
407    rules.extend(
408        CREATE
409            .iter()
410            .map(|(name, kind)| AdapterRule::create(name, kind)),
411    );
412    rules.extend(
413        [
414            ("object_set_grid_dsc_array", "dispatch_grid_tracks"),
415            ("calendar_set_today", "dispatch_calendar_set_today"),
416            (
417                "calendar_set_highlights",
418                "dispatch_calendar_set_highlights",
419            ),
420            (
421                "calendar_get_shown_date",
422                "dispatch_calendar_get_shown_date",
423            ),
424            ("chart_add_series_slot", "dispatch_chart_add_series"),
425            ("chart_set_values", "dispatch_chart_set_values"),
426            ("chart_get_value", "dispatch_chart_get_value"),
427            ("line_set_points", "dispatch_line_set_points"),
428            ("list_add_text", "dispatch_list_add_text"),
429            ("list_add_text_button", "dispatch_list_add_text_button"),
430            ("list_set_button_text", "dispatch_list_set_button_text"),
431            ("tileview_add_tile", "dispatch_tileview_add_tile"),
432            ("tileview_set_tile", "dispatch_tileview_set_tile"),
433            (
434                "tileview_get_tile_active",
435                "dispatch_tileview_get_tile_active",
436            ),
437            ("object_set_theme_variant", "dispatch_theme_variant"),
438            ("object_set_theme_error", "dispatch_theme_error"),
439            ("badge_create", "dispatch_badge_create"),
440            ("card_create", "dispatch_card_create"),
441        ]
442        .map(|(name, handler)| AdapterRule::custom(name, handler)),
443    );
444    rules
445}
446
447/// The declaration of a supported call, by catalog name.
448pub fn declaration(name: &str) -> Option<&'static Declaration> {
449    SUPPORTED
450        .iter()
451        .chain(EXTRA)
452        .find(|declaration| declaration.0 == name)
453}
454
455/// The catalog of every call LVGL's bindings export, with stable IDs.
456///
457/// `bindings` is the Rust source `lvgl_rust_sys` generates for the build
458/// target (its `BINDINGS` build metadata, or `_bindgen_raw_src()`).
459pub fn catalog(bindings: &str) -> Result<CallCatalog, GeneratorError> {
460    CallCatalog::parse(bindings)
461}
462
463/// Select every supported call from the catalog and check each declaration
464/// against the discovered C signature.
465pub fn registry(catalog: &CallCatalog) -> Result<GraphicsRegistry<'_>, GeneratorError> {
466    let names: Vec<_> = SUPPORTED
467        .iter()
468        .chain(EXTRA)
469        .map(|declaration| declaration.0)
470        .collect();
471    let registry = GraphicsRegistry::new(catalog, &names, &adapter_rules())?;
472    for call in registry.calls() {
473        let (_, arguments, _, output) = declaration(&call.name).expect("selected from the list");
474        // `object_delete` takes a handle: u16 in the catalog, one word on the wire.
475        if call.name == "object_delete" {
476            call.validate_signature(&["u16"], *output)
477                .or_else(|_| call.validate_signature(arguments, *output))?;
478        } else {
479            call.validate_signature(arguments, *output)?;
480        }
481    }
482    Ok(registry)
483}