Disabled state for objects


I’ve been working with the library, and there’s a thing that I have been missing from previous graphical libraries I have used.

In case I hava switch (or button) enabled, it would be good to have a state which was ON_DISABLED, because sometimes you want to reflect that the switch is on, but it is not available for change.

It could be a state, or maybe better a property (false or true), like the “toggle” property in a button, which caused all standard STATES (PRESSED, RELEASED, TOGGLE_PR, etc…) to appear as disabled.

To do this, styles should be added to the themes to sum to the actual ones. The drawback is that the number of styles stored in each object would be the double of the current ones, increasing memory usage.

Maybe I could program it with the switches and buttons, but having it merged with the original code would be the best in order to upgrade between versions.


We have a new style/theme system in 7.0 which includes states. You can see the information about it here.

Thank you.

I suppose this version is still under development. When is it supposed to be released? Is it safe to us it by now?


I believe it’s stable enough to start working with now. We’ve pretty much stopped adding new features at this point.

I have looked a bit the new options and seem great!

Any possibility to test it with CodeBlocks ? I’ve seen that by now the examples are done for eclipse, but I don’t know if I have to modify it a lot to make it usable in CodeBlocks


I have downloaded, installed and compiled with CodeBlocks the latest version of the lvgl code, and the examples of the eclipse v7 version, and it works, but not perfectly. The images and text render correctly, but the lines, arcs, etc… don’t. Also, the render time of the parts where there are lines or arcs involved seems very slow.

Are there any changes that have to be made to the lv_drivers section in order to work with the new version? I have used the same drivers used with the version 6.0, and they seem to work, but not perfectly


I hadn’t gotten around to updating the CodeBlocks project yet. I’ll take a look at it.

Apart from the codeblocks problems, and focusing in the DISABLE buttons original question, I have seen that in the new version 7.0 there are new combinable states for the objects, which goes in the way I was asking.

But digging more in the code I have seen that the buttons, still have the 5 previous states:

enum {
_LV_BTN_STATE_LAST, /* Number of states*/

So there’s still no possibility to set the button to disabled, and include all the other states (checked, unchecked, released, etc…) in the disabled state. I don’t know if it’s still under development.

I have tried to set the DISABLED state to the object, both buttons and switches, and nothing different happens. I feel that though the internal states allow to combine the disabled state with enabled (checked) or disabled (released), the object state does not reflect this, and remains as before. I don’t know if it is planned to do or not, but I think the disabled state with on/off states applied to some of the objects makes sense.

Thanks for your support



The button states doesn’t cover all the possible object states, just the most common ones. However, adding a “plain” disabled state is really confusing here. Probably it should be removed.

You can use lv_obj_add/clear_state(btn, LV_STATE_DISABLED).


when you have a simple button, the disabled state makes sense, but when the button is checkable, then you need the check-pressed-disabled and the check-released-disabled.

The same applies to a switch: you need the disabled-off and the disabled-on

That’s why I was proposing a disabled property for the buttons and switches (like the checkable property), or a way to add the disabled state to the button or switch, similar to the new states that have been added to the object. Right now, when the button changes it’s state, clears the disabled state of the object in almost all the transitions.


Ah, got it. That’s true, the disabled state should be preserved when you use lv_btn_set_state.

What about something like this?

void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state)

    switch(state) {
            lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED);
        case LV_BTN_STATE_PRESSED:
            lv_obj_clear_state(btn, LV_STATE_CHECKED);
            lv_obj_add_state(btn, LV_STATE_PRESSED);
            lv_obj_add_state(btn, LV_STATE_CHECKED);
            lv_obj_clear_state(btn, LV_STATE_PRESSED);
            lv_obj_add_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED);
            lv_obj_add_state(btn, LV_STATE_DISABLED);
        case LV_BTN_STATE_ACTIVE:
            lv_obj_clear_state(btn, LV_STATE_DISABLED);

That’s perfect to me!

As far as I have seen, the switch object would need this, also, and maybe other objects. I have not fully tested all the objects, I am focused now in understanding the whole system behaviour.

What I’m not sure is how all these added states will deal with the styles system, in order to reflect correctly all the different states. I know in v7 the styles are more versatile that in the v6 version, so I expect with a little work it will be ok.

I have not been able to test correctly those states v7, because still have some problems compiling the v7 in CodeBlocks, and the drawing and styles don’t apply correctly on my system. I will be doing more tests in the future, while I am still at v6.1

Thank you


There’s some preliminary documentation here which does a pretty good job of explaining the built-in states. In 7.0, lv_btn_set_state is basically just a wrapper around the built-in states, and the style system can already reflect changes made to those.


I’ve had a look at it an seems great. I’ll dig a bit more when I have time to port my app to v7.

Thank you!


I’ve just added it to dev-7.0



1 Like

@abueno I’ve just added a dev-7.0 branch to the CodeBlocks project. If you clone/checkout that (making sure to update submodules) you should be able to compile without any issues.

Thank you. I’ll give it a try and inform about any issues.