What is difference between signals and events?

I can’t understand concept of naming - when i should use SIGNAL and when EVENT.

Here is another example:

Similar events (onFocus/onFocused) use different distribution methods and different naming.

Could anyone explain principle, when i should select “signal” and when “event”? I don’t see difference between those 2 things. Probably i missed something important.

Signals are usually for objects to implement object-specific behavior. Events are for user code to respond to actions initiated on an object.

Some actions trigger both signals and events (like clicking and focusing).

Is this a kind of namespasing?

I mean, even with different api, both transports implement the same programming pattern (really the same, not just similar).

They are really similar but there are some differences:

Signals

  • Used internally
  • Specific to the object type. (label signal can’t be replaced by button signal). Describes how the object type behaves. E.g. it makes a button to behave like a button.
  • Propagated to ancestor type. That is a button calls the container signal first, which calls object signal first. It makes possible to inherit behavior of the ancestor types. Other example: the text area behaves like a page because it is derived from it (can be scrolled)
  • Not all signal has an event counterpart. E.g. LV_SIGNAL_GET_TYPE (to get the object’s and the ancestors’ type), LV_SIGNAL_CONTROL (to send controll characters such as LV_KEY_NEXT)

Events

  • Used the user
  • Not specific to the object type. The same event function works for any object type. (Except if you add type specific code.) E.g. LV_EVENT_CLICKED can be used on buttons, labels, sliders etc.
  • Can be propagated to the parent.
  • Not all signal has an event counterpart. E.g. LV_EVENT_VALUE_CHANGED.
1 Like