HeapsIO / heaps

Heaps : Haxe Game Framework

Home Page:http://heaps.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating a render zone inside another render zone can lead to issues.

tfabretti opened this issue · comments

HaxeUI uses mask to make scroll boxes. It's that way that I stumbled upon an issue : a mask inside a mask can lead to an issue, the inner mask is not translated through the outer edge of the parent mask.

Here is the visual example :
image
The inner mask (for the inner scroll box) should go up and exit the parent mask (for the parent scroll box) but it doesn't.

After a fair bit of searching, I realized what caused the issue. Here is a bit of code in RenderContext.clipRenderZone :

x = Math.max( x, renderX );
y = Math.max( y, renderY );
var x2 = Math.min( x + w, renderX + renderW );
var y2 = Math.min( y + h, renderY + renderH );

The start position of the render zone is computed before getting its end position. In the case of the start position being outside the rendering zone, it's set to the bounds of the rendering zone. Then, the desired height is added to the start position. The problem is that the start position has been changed so the desired height doesn't start at the right place, extending the desired render zone.
With a Y offset example, the render zone should go from (x, renderY) to (x + w, y + h). Since y has been changed before computing y2, the result is off, giving a result from (x, renderY) to (x + w, renderY + h).

By simply changing the order to have something like this :

var x2 = Math.min( x + w, renderX + renderW );
var y2 = Math.min( y + h, renderY + renderH );
x = Math.max( x, renderX );
y = Math.max( y, renderY );

I get the expected result :
image

If it's a bug, I'm surprised it hasn't been caught before as I suspect using masks for scroll boxes is fairly standard (the thing even has scroll methods). Am I missing something there ? Or maybe no one was crazy enough to put scroll boxes inside other scroll boxes ? :D

As I don't use masks any other way, my fix may cause bugs I'm not aware of, so I opened this issue instead of directly doing a PR, in case it breaks stuff unbeknownst to me. Well, also because I don't know git and I hoped someone would do that PR for me :P

Please, let me know if I'm doing anything wrong ! <3

commented

I would make a PR even if it breaks something because it's easier for people to test the changes that way. This issue may not get much attention otherwise

Alright, I'll try, then ! Thank you !

Oups, I missclicked :D