Text area does't respect width/height if given float values

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
User avatar
DizzyKa
Newbie
Posts: 15
Joined: Sat Sep 24, 2016 4:49 pm
Projects: @GossamerAcademy
Contact:

Text area does't respect width/height if given float values

#1 Post by DizzyKa » Wed Feb 15, 2017 7:37 pm

Hey all,

Ran into a little gotcha today, the title says it all - The "area" property of text in a screen won't respect the width and height provided unless the numbers are integers.

Does not work ( text will not wrap ):
text "Test" area (0, 0, 100.0, 100.0)

Does work ( text wraps ):
text "Test" area (0, 0, int(100.0), int(100.0))

Might be a nice to have fix by casting the width/height into ints by default in the text display code.

User avatar
Divona
Miko-Class Veteran
Posts: 610
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Text area does't respect width/height if given float val

#2 Post by Divona » Thu Feb 16, 2017 12:18 am

"area" always take tuple of integer values, as stated in the documentation.

Is there a reason why width and height has to be in float? There is no such thing as half a pixel in image resolution.
Completed:
Image

User avatar
DizzyKa
Newbie
Posts: 15
Joined: Sat Sep 24, 2016 4:49 pm
Projects: @GossamerAcademy
Contact:

Re: Text area does't respect width/height if given float val

#3 Post by DizzyKa » Mon Feb 20, 2017 6:49 pm

Nope! No reason, just that its an invisible failure if you do end up using floats which might happen as a result of division if you're placing elements on screen programmatically rather than using exact coordinates. Its good that its in the documentation, but in absence of the documentation there's no clear indicator of whats going on and can potentially frustrate and waste time for developers. Its a small thing but I thought I'd point it out.

User avatar
Imperf3kt
Miko-Class Veteran
Posts: 876
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Text area does't respect width/height if given float val

#4 Post by Imperf3kt » Mon Feb 20, 2017 7:02 pm

Divona wrote:There is no such thing as half a pixel in image resolution.
Ren'Py doesn't use subpixels?
https://en.wikipedia.org/wiki/Sub-pixel_resolution
Image

Warning: May contain trace amounts of gratuitous plot.

User avatar
gas
Veteran
Posts: 354
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Text area does't respect width/height if given float val

#5 Post by gas » Mon Feb 20, 2017 7:32 pm

The reason of that is that you already have "programmatical" size for containers.
Dividing a number by a number is not programmatical, is fixed math. You already knows all the values.

So, wanna divide the screen 3 part? Grid or hbox.
Wanna divide 1280 by 7? You end with floats. A no no in pixel.

@Imperf3kt: subpixeling is a way of rendering objects taking into account the difference into real size and screen resolution. It doesn't allow you to move something by "half pixel". It move by one, then the blit area get calculated in relation to the item size and screen resolution ("blurring" or averaging the edges of the item and faking your eyes)
10 ? "RENPY"
20 GOTO 10

RUN

User avatar
PyTom
Ren'Py Creator
Posts: 14799
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Text area does't respect width/height if given float val

#6 Post by PyTom » Mon Feb 20, 2017 8:09 pm

Ren'Py tends to use floats to indicate "fraction of the available area". So when you give area (0, 0, 100.0, 100.0), you're really requesting 100x the space available.

Part of that was we didn't support subpixels back then. We actually do support subpixel now - Ren'Py is happy to put things on a pixel boundary. You have to cast to a special type called absolute, but pos (absolute(100.5), absolute(100.5)) will work fine.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama
https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: No registered users