lc-soft / LCUI

C library for building user interfaces
https://lcui-dev.github.io
MIT License
4.12k stars 356 forks source link

Connecting Frontend to Backend #260

Closed MichealShinoda closed 2 years ago

MichealShinoda commented 2 years ago

I couldn't find any information on how to connecting frontend (button clicks) to backend. Let's say I have a button like this:

<w type="button" class="btn ml-3">Start Application</w>

How can I add click event to the xml file and program it in C? Thanks

lc-soft commented 2 years ago

Here are the steps:

  1. Add id attribute to xml element
  2. Call LCUIWidget_GetById() to get the widget
  3. Call Widget_BindEvent() to bind the click event of the widget

Examples for reference:

https://github.com/lc-soft/LCUI/blob/ea409f1339580c2f5267597a134c0a8c17d1e5e5/test/helloworld.c#L1-L33

https://github.com/lc-soft/LCUI/blob/ea409f1339580c2f5267597a134c0a8c17d1e5e5/test/helloworld.xml#L1-L11

MichealShinoda commented 2 years ago

Worked like charm!