GithubHelp home page GithubHelp logo

Comments (17)

tannewt avatar tannewt commented on June 17, 2024

@kmatch98 Any thoughts? I think you added the zero-width bitmap. Is it just setting a background color?

from adafruit_circuitpython_display_text.

FoamyGuy avatar FoamyGuy commented on June 17, 2024

I believe it is only for setting the background color. The way it works now was introduced because the original background_color functionality was working with terminalio.FONT but not working very well with custom fonts. #49 has more details.

I think it's set to 0 width initially because the label may not have any text yet at this point.

It looks like the bitmap and tilegrid get created inside of _create_background_box() with the box sizes here:

background_bitmap = displayio.Bitmap(box_width, box_height, 1)

It may be possible to get rid of the placeholder 0 sized bitmap and Tilegrid in the __init__() without causing any issues.

But I think inside of _create_background_box() it could still come up as 0 if there is no text in the label and no padding. We may need to add logic to handle the "no text" case separately to avoid making the zero size bitmap.

from adafruit_circuitpython_display_text.

kmatch98 avatar kmatch98 commented on June 17, 2024

I just issued a pull request to alleviate this to prevent the zero-sized bitmap.

I also observed some strange position changes when the text is changed after a label is created. I will create a separate issue for that.

from adafruit_circuitpython_display_text.

kmatch98 avatar kmatch98 commented on June 17, 2024

@ foamyguy I didn't add a check for zero size of the box_width and box_height before updating the background bitmap size.

Do you think that will be necessary? If so, what exception should it provide? I think I agree that handling "no text" would be a good approach, but what if you create a label with text and then set the text to blank. I feel like that shouldn't cause any error, just should display nothing. Your suggestions are welcome.

from adafruit_circuitpython_display_text.

FoamyGuy avatar FoamyGuy commented on June 17, 2024

@kmatch98 I do think it will be necessary.

If I understand correctly the I think the desire is that Bitmap object will be raising an exception when you try to create one with 0 width or height. @tannewt can you confirm if I am understanding correctly what the ultimate desired change is?

Inside of Label I think we will need to check if the size is going to be zero, and if so just skip making the Bitmap altogether. That way the code inside of label will never be creating a 0 size Bitmap which means we should never run into the the exception if/when it does get added to the Bitmap class. (Or perhaps we could use Try/Except but this is a bit of a chicken/egg problem because the exception hasn't been implemented yet I think.)

I do agree as well that we will want to make sure to handle it correctly no matter when or how the text gets set to empty so that no exceptions get raised based on the user setting text, even if they set it to empty.

from adafruit_circuitpython_display_text.

tannewt avatar tannewt commented on June 17, 2024

@FoamyGuy Yup, I intend on raising an exception if width or height is zero.

from adafruit_circuitpython_display_text.

kmatch98 avatar kmatch98 commented on June 17, 2024

Resolved in #59

from adafruit_circuitpython_display_text.

makermelissa avatar makermelissa commented on June 17, 2024

It appears this is still an issue. Likely due to my term usage on this issue. I added a 0-width/height check to tilegrid and here's the error:

  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 362, in text
    self._update_text(str(new_text))
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 283, in _update_text
    y=position_y,
  File "/home/pi/.local/lib/python3.7/site-packages/displayio/tilegrid.py", line 107, in __init__
    raise ValueError("Tile width and height must be greater than 0")
ValueError: Tile width and height must be greater than 0

from adafruit_circuitpython_display_text.

makermelissa avatar makermelissa commented on June 17, 2024

Here's the changed code in tilegrid.py:

        if not tile_width:
            tile_width = bitmap_width
        if not tile_height:
            tile_height = bitmap_height
        if tile_width < 1 or tile_height < 1:
            raise ValueError("Tile width and height must be greater than 0")

from adafruit_circuitpython_display_text.

kmatch98 avatar kmatch98 commented on June 17, 2024

@makermelissa maybe it is a different issue than before, or we solved the wrong problem with the last PR!

Can you show the code you are running to create the label? For example, are you updating a label to have no text, label.text=‘’?

from adafruit_circuitpython_display_text.

makermelissa avatar makermelissa commented on June 17, 2024

Sure, I'm basically running the code from https://learn.adafruit.com/pyportal-electioncal-us/code-pyportal-with-circuitpython with some small modifications (removed board.NeoPixel from initialization and updated code to get the current working directory in CPython) so that it runs on the Blinka PyPortal library.

from adafruit_circuitpython_display_text.

makermelissa avatar makermelissa commented on June 17, 2024

Here's the full error:

Traceback (most recent call last):
  File "electioncal.py", line 37, in <module>
    gfx = electioncal_graphics.Electioncal_Graphics(pyportal.splash, am_pm=True)
  File "/home/pi/electioncal_graphics.py", line 43, in __init__
    self.url_text.text = "Visit us at https://electioncal.us"
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 362, in text
    self._update_text(str(new_text))
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_display_text/label.py", line 283, in _update_text
    y=position_y,
  File "/home/pi/.local/lib/python3.7/site-packages/displayio/tilegrid.py", line 107, in __init__
    raise ValueError("Tile width and height must be greater than 0")
ValueError: Tile width and height must be greater than 0

from adafruit_circuitpython_display_text.

FoamyGuy avatar FoamyGuy commented on June 17, 2024

It looks like maybe this is getting caused by the glyph width here:

Perhaps the width and/or height of certain glyphs can be 0?

from adafruit_circuitpython_display_text.

kmatch98 avatar kmatch98 commented on June 17, 2024

In the font file "Arial-12.bdf", the spaces are represented with zero-width glyphs, but use an x_offset to create the space.

So, in essence a blank tileGrid is created (with zero width), and the next tileGrid is created with an x-position offset to the right by x_offset.

One option is we can decide to not create any zero-width tileGrids.

Let me propose something....

from adafruit_circuitpython_display_text.

makermelissa avatar makermelissa commented on June 17, 2024

That sounds like a workable plan. :)

from adafruit_circuitpython_display_text.

kmatch98 avatar kmatch98 commented on June 17, 2024

Ok, just issued a PR, please check it out and see if it will resolve your tileGrid error.

from adafruit_circuitpython_display_text.

makermelissa avatar makermelissa commented on June 17, 2024

Fixed by #64

from adafruit_circuitpython_display_text.

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.