CodenameOne icon indicating copy to clipboard operation
CodenameOne copied to clipboard

Android Border.createCompoundBorder has a bug

Open javieranton-zz opened this issue 5 years ago • 2 comments

 Button b = new Button("aa");
 Border lineBorder = Border.createLineBorder(1, 0xd6d6d6);
 Border emptyBorder = Border.createEmpty();
 Border newBorder = Border.createCompoundBorder(lineBorder, emptyBorder, lineBorder, lineBorder);
 b.getAllStyles().setBorder(newBorder);

This should create 1px border on top, on the left and on the right. And it does on JavaSE and on iOS. But not on Android. On Android, it only creates a border on top and on the left.

Likewise, if the empty side is TOP, we will get empty BOTTOM and RIGHT as empty bonuses

If it is LEFT, we will also get BOTTOM and RIGHT empty sides

I can't find the implementation of where this is happening. This has been a long-standing bug but only now I am reporting it

javieranton-zz avatar Jul 18 '20 08:07 javieranton-zz

Played with this a little bit today. I can reproduce this on my Galaxy S8 running Android 9. I can "fix" my test case by changing

https://github.com/codenameone/CodenameOne/blob/master/Ports/Android/src/com/codename1/impl/android/AndroidGraphics.java#L1408

canvas.clipRect(x, y, x + width, y + height, Region.Op.INTERSECT);

to

canvas.clipRect(x-1, y-1, x + width+1, y + height+1, Region.Op.INTERSECT);

However, I'm almost sure that this will break some other things. It's hard to find consensus on Android's correct clipping behaviour, whether the rect is inclusive of edges or exclusive. In this case, it is behaving like it is exclusive, in other cases it seems inclusive.

Making this change will require a lot more testing than I have time to do right now. Will revisit this later.

shannah avatar Sep 09 '21 14:09 shannah

It's not a huge deal, I can work around this so unless you feel very confident feel free to close. But otherwise a good fix

Note: the workaround is to use parent/children component borders

javieranton-zz avatar Sep 10 '21 20:09 javieranton-zz