ImpulseAdventure / GUIslice-Builder

Cross-platform drag & drop GUI builder for GUIslice
Other
163 stars 35 forks source link

Imeage visibility toggle? #238

Closed tbillion closed 1 year ago

tbillion commented 1 year ago

i am not sure if this is already a function that is not documented or if it is not part of the code at all but:

the use case i have entered is an icon based status bar, greyed out icon for not enabled or a color icon for enabled. I figure this is something a lot of people could use, but i cannot figure how to either have two images and hide the one that isn't right or to swap the image in an image location in the app.

the solution could be as simple as enable disable the image view, or a more comprehensive control that would allow the dynamic changing of its image.

i did search this out as far as discussions and documentation but i didn't fin a concise answer.

i asked chatgpt about this and the answer it generated was this, however i am unable to test it currently based on the issue with SD.h :

Yes, in the GuiSlice library for Arduino, you can change the image content of an image. Here's how you can do it:

First, make sure you have loaded the image into GuiSlice using the LoadImage function. You can load images in BMP, GIF, JPEG, and PNG formats.

Once you have loaded the image, you can display it on the screen using the DrawImage function. This function takes the image ID and the coordinates of the top-left corner of the image on the screen as arguments.

To change the image content, you need to modify the bitmap data stored in memory. You can do this using the SetImageBitmap function. This function takes the image ID and a pointer to the new bitmap data as arguments.

After you have modified the bitmap data, you can redraw the image on the screen using the DrawImage function again.

Here's some sample code that demonstrates how to change the image content of an image in GuiSlice:

scss

#include <GuiSlice.h>

// Load the image
int imageId = LoadImage("myimage.png");

void setup() {
  // Initialize GuiSlice
  InitGUIslice();

  // Draw the initial image
  DrawImage(imageId, 0, 0);
}

void loop() {
  // Modify the bitmap data
  uint8_t newBitmapData[] = { /* new bitmap data goes here */ };
  SetImageBitmap(imageId, newBitmapData);

  // Redraw the image
  DrawImage(imageId, 0, 0);

  // Wait for a moment before modifying the image again
  delay(1000);
}

In this example, the SetImageBitmap function is called with the new bitmap data, and then the DrawImage function is called again to redraw the image on the screen. The delay function is used to wait for a moment before modifying the image again

.

Thanks!

Pconti31 commented 1 year ago

@tbillion The first issue is with ChatGPT. The technology must always return an answer even if its doesn't know what the answer should be. Sometimes I have even found that if it does know the answer and gives it correctly, a second request a few minutes alter will give an incorrect answer. Much research is being done on this problem but no solution has proven workable... In other words it will (like in your case) simply make crap up. If you tried the code you would notice the various draw functions do not exist.

There are a couple of ways to do what you want but I think the easiest is to simply define two images on top of each other. Than edit your project c file after the InitGUIslice() code make one image visible and the other hidden. Just make sure and define two different ElemeRefs to your two images. From my faq.pdf

How can I Hide a UI Element until some external event occurs? You just make it visible or not.

  gslc_tsElemRef*  m_pElemName = _address of your ui element_
  gslc_ElemSetVisible(&m_gui,m_pElemName,true|false);

Paul--

Pconti31 commented 1 year ago

@tbillion Since no response has come from you I'm going to assume your question has been answered.