I would like to use this function. But it is static. Does it really need to be static?

What is the use case in which you need this function?

Note that e.g. after lv_obj_set_state(obj, LV_STATE_PRESSED) the object state will be simply LV_STATE_PRESSED. So it overwrites every other state.

I use this condition for toggle switch.
If(x = 0) {
lv_obj_clear_state(obj, LV_STATE_PRESSED)
else {
lv_obj_add_state(obj, LV_STATE_PRESSED)

Instead of above condition - I could use lv_obj_set_state(obj, x). This is useful since toggle switch has only pressed and default state.