Coder Social home page Coder Social logo

Comments (7)

scls19fr avatar scls19fr commented on August 22, 2024 3

A more object oriented approach could be to add

class NexObject 
{
public: /* methods */
...

    bool setVisible(bool flag);
}

to NexObject.h

and

bool NexObject::setVisible(bool flag)
{
    const char *name = getObjName();
    if (!name)
    {
        return false;
    }
    String cmd = String("vis ");
    cmd += name;
    cmd += ",";
    if (flag) {
        cmd += "1";
    } else {
        cmd += "0";
    }
    sendCommand(cmd.c_str());
    return recvRetCommandFinished();
}

to NexObject.cpp

PS : be aware that it's untested... so you probably need some fixes.

from iteadlib_arduino_nextion.

sky022 avatar sky022 commented on August 22, 2024 2

Code from @scls19fr worked well for me, with some fixes:

  • few missing semi-colons
  • need to add include statement for NexHardware.h at NexObject.cpp beginning
    #include "NexHardware.h"

from iteadlib_arduino_nextion.

bdelapen avatar bdelapen commented on August 22, 2024

I'm in the same situation, needing to hide a button based on a specific status at run time. I got here first and thought that I wished there was an answer. I have been tinkering a little with this and have not found a direct way of either hiding/disabling the button or just moving it off the screen (this can be done at design time but not at run time as far as I have been able to test).

Here is what I plan on doing. I am using buttons with "crop images". I have created a 3rd version of the button image with a grayed out button (though you could create one without any button at all). You can programatically change the button image so I plan on setting the button state (both picc and picc2) to the 3rd image and when re-enabling the button setting them back to the original. You have to keep track of what the status of the button is within your arduino code as the button will still send events when the images are in the "disabled" mode so you will have to ignore button clicks in your code.

I will report back when I have tested this approach in arduino, so far I have only tested it in the debug window of the Nextion editor.

from iteadlib_arduino_nextion.

bdelapen avatar bdelapen commented on August 22, 2024

After some more tinkering I found that it is actually pretty straight forward to hide an element:

  Serial1.print("vis b3,0");
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);

in this case b3 = element to hide or show, 0 to hide, 1 to show.

Remember that Nextion is very particular about whitespace, leave no whitespace except between the vis instruction and the element name (you can also use element ID).

from iteadlib_arduino_nextion.

BMac099 avatar BMac099 commented on August 22, 2024

Can you tell me how I would use the above code ? I tried "objectName.setVisible(true);" and objectName::setVisible(true); and objectName.setVisible() = true; with no luck . Thank you.

from iteadlib_arduino_nextion.

sky022 avatar sky022 commented on August 22, 2024

I'm using pointer objects to some text fields and radiobuttons, and it works well for me
text_field->setVisible(true);

from iteadlib_arduino_nextion.

BMac099 avatar BMac099 commented on August 22, 2024

from iteadlib_arduino_nextion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.