Canvas - Rect values only Int?

Quillok

Member
Licensed User
Longtime User
Hi,
got a little problem with the Rect in Canvasdrawing.

SampleCode:

B4X:
dim a,b,c,d as float
a = 18.75
b = 22.75
c = 100
d = 120

dim HelpRect as Rect
     Helprect.initialize(a,b,c,d)

When in debugging mode and I hover with the mouse over the HelpRect, I can see that the Values are (18,22,100,120) what gives me some problems in drawing because it causes gaps.
Is the rect only able to save the values as int? Is there another solution for it or did I have do change all my float-vars into int-vars? If so I had to change most of my current code :/

Can anybody give me a solution for my problem?
 

Quillok

Member
Licensed User
Longtime User
Ok, thanks, so I have to change my code :/

I wanted to use as much of the screen as possible, I want to draw a lot of squares. At the beginning of the text I calculate the cellsize with the help of the activity.width and the cellnumbers:

B4X:
dim CellSize as float
Cellsize = activity.width / 64

In most cases there comes out a float. If I use integer, there will be space that isnt used, because 64 * 18 = 1152, but 64 * 18.75 = 1200
It is not so much, but that makes everything a little bit smaller and not every space is used... but ok, thanks for helping :)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you'll have more luck with

floor(64*18.75)

than with the

64*floor(18.75)

you were using now ;)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As the cell width can only be an integer you cannot cover the whole space.
I suppose that you don't want to have cells with different widths.
So you can introduce a LeftMargin value to center the cells on the screen.
I would suggest you the following:
B4X:
CellWidth = Floor(100%x / 64)
LeftMargin = (100%x - 64 * CellWidth) / 2
And when you fill the screen begin with LeftMargin instead of 0.

Best regards.
 
Upvote 0
Top