It looks like you're new here. If you want to get involved, click one of these buttons!
Hi all,
Just wondering if anyone has seen what I’m currently seeing? I’m trying to draw a fairly hefty chunk of text using the text
function (~ 3000 characters) but as soon as the length of the string I pass goes above 2010 characters nothing is drawn. The text I’m passing is just some lorum ipsum placeholder for the moment.
This is the code that works:
local txt = string.sub(text_to_draw, 1, 2010)
text(txt, 0, 0)
and this doesn’t:
local txt = string.sub(text_to_draw, 1, 2011)
text(txt, 0, 0)
Anyone have any ideas?
Comments
I think I found a routine which I used in the Final Frontier demo in that post if you want to look it up. Found it, and others, with an internet search.
@Steppers What other code do you have. A straight text line doesn’t go much past the width of the screen let alone 2010 characters. Are you wrapping the text or something like that.
@Bri_G @dave1707 Yep, it’s wrapping the text at the correct width and it renders just fine exactly where I expect it to at 2010 characters but it just seems like an odd limitation beyond that.
I can’t really split it easily and render the parts nicely as it’s currently failing in the middle of a word. I could but it’ll be a pain.
For context, it’s part of a project info panel I’m adding to WebRepo for longer descriptions so it’s unlikely we’ll actually hit this limit but it seems odd nonetheless.
This should be a little more of the actual code I’m using (which doesn’t render the text when over 2010 characters)
@Steppers I can show a chunk of code that’s 4,105 characters. I’m using a textWrapWidth of 1026 in landscape. A textWrapWidth of 1027 or 4106 characters and nothing displays.
@dave1707 Oh that’s pretty strange then. That definitely sounds broken to me.
I can get it to render just fine if I set the wrap width to 1024 so something to do with that I guess.
@Steppers I don’t know if it’s broken or not. I’m sure there’s limitations to everything. They probably thought 4,000+ characters was more than enough.
@Steppers Anytime I want to show a lot of text, I do something like this. You can scroll the text up/down. Change the variable “wide” value to fill the screen.
@dave1707 Perfect, thank you. I’m going to stick with unscrollable text for the time being but will come back and use something like that later
I think I’d like it to split between words too but I hadn’t thought about actually doing it manually.
@Steppers Splitting between words at the end of each line should be easy enough. The code I show above I just did off the top of my head. I probably have or had code that splits words on spaces at the end of each line.
Pardon the android phone formatting. See amended post below.
@Steppers @Simeon @dave1707 imho there’s definitely something wrong with the text function bc even with just three words it won’t print to screen at seemingly-random sizes. IIRC you could sometimes get the text in my text-resizing box to disappear and reappear at least twice before it reached any of the screen borders.
@Stepper - here is the function I found on the net.
Grrrrh - I hate posting from Android phones into this forum but when you're away from your iPad and Mac what can you do? Pasting here much better.
@Bri_G Amazing. Thank you! I’ll check it out when I come to adding scrolling text on the project panels.
Here’s a version that I have. The function split does all the work and creates a table of lines so the line splitting only needs to be done once. Then use the tabLine table to display the lines. Input is the string to split and the pixel width of the line. It uses pixel size and font size to determine the line size. I created a string of 27,456 characters so you can scroll the text up or down. Try changing the sizePixel and sizeFont parameters. It also works for different fonts types. All the other code is just to setup the demo so split() is all that’s needed.
Here’s an updated version of the above code. It splits a string on space boundaries to fit within scrolling box area. Pass the class the string and the x,y,w,h of the scroll area. Also, the font size, font color, and font name can be different for each scroll area. I could have added a lot more options, but this is good enough for now.
If I draw a rectangle at the side of the screen, I get half a rectangle. I suggest that text should clip at the screen edge, not just vanish altogether.
This comment in no way relates to the apparent bug I had in my class/method printer due to extremely long method names. Not at all.
But really, shouldn't it display what it can, like other display stuff?
that, i do not know
might. try it?
@RonJeffries Were you referring to my code above about the rectangle at the side of the screen. If so, I added the following changes to the above code. It now use the edges as limits.
If anyone is looking for other print/text issues, the following code prints the string of zeroes to the print window. 390768 works, but 390769 doesn’t show anything.
It prints 13,956 lines.
If you tap the Boolean for rendering text to a buffer first, it’ll do that.
Right now for me there’s no visible difference, because at least on my iPhone this project isn’t currently causing the vanishing-text problem, which I know for a fact it used to because @dave1707 pointed that out the first time I posted it.
@UberGoober If I slide the rectH parameter, the text disappears if I do the Boolean switch or not.
I didn’t catch that because it’s not just about the text extending past the screen, which is what I tested for, and which works fine at most sizes.
For some reason this is about certain specific heights. I don’t get it.
As far as I’m concerned, there’s limitations to Codea. It can’t do everything the way everyone wants. If Codea doesn’t do something, I write code to compensate, that’s life. Sure, @Simeon can adjust things, but there will always be something else.
I'm here to request what I think would be of value. If I wanted to put up with bad stuff, I'd code in C#
. Simeon gets to decide, but I believe it is part of our job as experienced users to suggest ideas of potential value.
Consistency in rendering text at any size and any location no matter what the coordinates is imho also a universal standard—it’s table stakes for any graphics renderer really.
Codea flubbing it obviously isn’t a death blow, mainly because it doesn’t come up very often, but it does come up now and then, and when it does, it’s a bad look.
@RonJeffries @UberGoober I’m not saying that Codea shouldn’t be fixed. I’m just saying that it has its limitations and we’re going to run into them as we write code. So someone can either stop writing code and wait until the problems are fixed, or they're going to have to modify their code to work around it. Once the fixes are made, they can always go back and modify the original code or leave it. Right now there are limitations as to how text is displayed on the screen. So someone can either wait or code around it until, if or when it’s fixed. The text limitation has been around for a very long time. Will it be changed soon, I don’t know. But I’ll write code to avoid it. Will my code work, yes. Will it still work when the fix is made, probably.
I'm not sure I am understanding the point here. I'm sure we all write code including whatever workarounds we need to get things to work. But it seems you were objecting to my request that text not fail at screen edge but instead display as much as fits. Were you not objecting? If not ... then I don't understand.
Thanks!
@RonJeffries We must not be talking about the same thing. You posted this right after my post of a program above.
So I made changes to my code to clip the text if the rectangle exceeded the edge of the screen. So we’re you referring to my program or something else.
i'm referring to the same thing. i can of course work around it. what i don't understand is that you seem to be taking issue with the idea that it would be more consistent and better, if it clipped.
I’m can’t quite follow the entire discussion but I’ll throw in my two cents.
In my opinion the text should absolutely just clip by default. From my own experience with it, the current behaviour just seems like a bug. A limitation yes, but one imposed by the presence of the bug itself.
I can understand it’s unlikely to be fixed and I can work around it but it’s still a bug and the limitation should not realistically exist. There’s not even a clear cut point as far as I can tell as to when the bug manifests.
@RonJeffries In the case of my code, I didn't see the text clipping as a problem. The user chooses the x,y,w,h values for splitString to create the text/rect area. If the edge of the text box ended up passed the edge of the screen and got clipped, they would alter the values to keep it on the screen. I figured that was just a user problem. But anyways I fixed it so the edge limits the size unless they’re too close to an edge. I normally don’t code for everything that can go wrong, not even for myself. If I write it and it breaks for something, I usually fix it.
PS. My other posts were about the text disappearing if it was too long to display on the screen. That’s been a problem for a long time and the only fix is to code for it.
as you were, or at least as i was. i think there may be an easy way to do this. will report back.
Here’s the explanation for the disappearing text on the screen. I thought it was based on the screen width or height, but it’s not. I knew about this a long time ago, but I just remembered how it works now. I’ll see if I can find my original post from long ago. But here’s the explanation in the meantime.
There’s a command textSize() that returns the 2 values width and height of a string. So w,h=textSize(string) will give the w,h values of a string that’s being displayed using the text command. Different fonts and fontSize will change the values of w and h. The only constant for the text command no matter what the font or fontSize is, is 1024. If the width of the text being displayed is 1024 or less, it will show on the screen. If the width is greater than 1024, it will disappear. So you can determine if a text command will or won’t show on the screen. It doesn’t matter if you’re in portrait or landscape orientation, 1024 is the limit.
PS. Here’s one link where I explain this and refer to an earlier post. Scroll to the bottom.
Here’s an example that I probably posted the first time I wrote about the text disappearing. Change the sliders for tww (textWrapWidth) and fs (fontSize) to vary the text on the screen. In the upper right corner I display the text width and text height. Anytime the width or height exceeds 1024, the text disappears.
fascinating! that's totally not what i thought was happening! well done.
however, with a screen that's much wider than 1024 pixels i wonder why?