PxMatrix icon indicating copy to clipboard operation
PxMatrix copied to clipboard

Scroll text within bounding box

Open wvthoog opened this issue 4 years ago • 9 comments

Don't know if this is possible but i want to use the scroll text function to be bound within certain dimensions. What is happening now is that on my 64x32 matrix the text scrolls from right to left over the entire display and what i want to achieve is that it's cut off at pixel 23 (calculated from the left side)

This is the current scroll text function

void scroll_horizontal(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB)
{
    uint16_t text_length = text.length();
    display.setTextWrap(false);  // we don't wrap text so it scrolls nicely
    display.setTextSize(2);
    display.setRotation(0);
    display.setTextColor(display.color565(colorR,colorG,colorB));

    // Asuming 5 pixel average character width
    for (int xpos=matrix_width; xpos>-(matrix_width+text_length*10); xpos--)
    {
      display.setTextColor(display.color565(colorR,colorG,colorB));
      display.clearDisplay();
      display.setCursor(xpos,ypos);
      display.println(text);
      delay(scroll_delay);
      yield();

      delay(scroll_delay/5);
      yield();

    }
}

Anyone got any idea if this is possible. If so, on how to achieve this.

Many thanks.

wvthoog avatar Mar 08 '21 15:03 wvthoog

Had You tried this code? Go ahead...

davemaster avatar Mar 09 '21 00:03 davemaster

@davemaster if you are referring to the above code, this works. But i need it scroll only to row 23 and not the entire display

wvthoog avatar Mar 09 '21 06:03 wvthoog

Hey, Have you found a solution to this issue? I am facing the same problem as I want to display an image together with an scroll text. Thanks

AlexR2106 avatar Apr 07 '21 07:04 AlexR2106

Unfortunately not. Trying to achieve the same thing as you are (image + scrolling text)

Maybe another library can do the trick but haven't looked into that yet.

wvthoog avatar Apr 07 '21 11:04 wvthoog

Nothing suitable found by now also on my side. I started working on some code, to get the output done in a specific area. Sadly this leads being unable to use the default print command and letters need to be drawn pixel by pixel to the matrix. I will keep you updated as soon as I have something usable.

AlexR2106 avatar Apr 07 '21 11:04 AlexR2106

I think you have two options

  • create a copy of the display.print function that only writes to some window
  • print to some buffer and only copy the window to the actual frame buffer.

For the second option you could create an inline drawPixel function that allows you to write to the buffer using buffer_draw.print("Hello",color);

class buffer_draw : public Adafruit_GFX {
public:
  uint8_t frame_buffer[frame_size]={0};
  buffer_draw() : Adafruit_GFX(64,64) {}

  // We need that one so we can call ".print"
  void drawPixel(int16_t x, int16_t y, uint16_t color)
  {
    
  }
};

buffer_draw buffer_drawer;
 

2dom avatar Apr 07 '21 21:04 2dom

As a reference check out https://github.com/2dom/PixelTimes/blob/master/PixelTimes.ino where I use it to create a buffer before the library had double buffer support

2dom avatar Apr 07 '21 21:04 2dom

Yeah I've tried to set this up myself but unfortunately my C++ skills are inferior.

Would love to see a function in the PxMatrix library that supports Scroll Text to a particular window.

Something like:

void scroll_text(uint8_t ypos, ,utin8_t maxypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB)

where maxypos is the position the scroll text cuts off to the left

wvthoog avatar Jul 25 '21 12:07 wvthoog

has anyone gotit?

KvarTechnologies avatar Feb 20 '23 10:02 KvarTechnologies