Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible one pixel off in debug rects #4

Closed
mikaelgrev opened this issue Jan 9, 2012 · 4 comments
Closed

Possible one pixel off in debug rects #4

mikaelgrev opened this issue Jan 9, 2012 · 4 comments

Comments

@mikaelgrev
Copy link

I think that maybe

private void drawLayoutCell(Canvas canvas)
{
canvas.drawRect(0.0F, 1.0F, getWidth(), getHeight(), cellPaint);
}

should be

private void drawLayoutCell(Canvas canvas)
{
canvas.drawRect(0.0F, 1.0F, getWidth() - 1, getHeight() - 1, cellPaint);
}

At least Swing draws the right and bottom edge of a rectangle to the right/bottom of the last pixel and one want the right and bottom edge to be inside the layout I think. If for instance you have a layout the covers the full screen the original method will at least draws the right/bottom edge outside the screen (verified on my Galaxy S2).

Cheers,
Mikael

@saynomoo
Copy link
Owner

You mean this line: https://github.com/saynomoo/mig4android/blob/master/mig4android/src/main/java/com/saynomoo/mig4android/MigLayout.java#L151 ?

If I change that, the miglayout cell right line is one pixel too left and the bottom line is one pixel too up. This is at least how it works with samsung galaxy nexus and the emulator.

Did you mean the debug rects of the components inside the layout? Those rectangles are drawn with the method drawChildCell.

Can you provide a layout which would easily demonstrate the problem you are experiencing?

@mikaelgrev
Copy link
Author

It was probably the wrong line.

The problem is this. If you have layout that is using the whole screen, then the right and bottom line is not visible since they are drawn one pixel outside the screen.

The right and bottom line should actually be on the last pixel of the layout, now they are painted to the right and bottom of the layout.

For instance, in the Swing version this is the code:

public final void paintDebugCell(int x, int y, int width, int height)
{
Component c = (Component) getComponent();
if (c.isShowing() == false)
return;

Graphics2D g = (Graphics2D) c.getGraphics();
if (g == null)
    return;

g.setStroke(new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f, new float[] {2f, 3f}, 0));
g.setPaint(DB_CELL_OUTLINE);
g.drawRect(x, y, width - 1, height - 1);

}

@mikaelgrev
Copy link
Author

Actually, you can see this in your examples as well. The right edge is missing on my two Samsung devices.

saynomoo pushed a commit that referenced this issue Jan 24, 2012
@saynomoo
Copy link
Owner

Since I changed the minSdkVersion to 4, the off by one errors started to show. Since it's now "required" anyway to use minSdkVersion 4, I changed the debug rects accoringly. Fixed in commit ccb8347

saynomoo pushed a commit that referenced this issue Jan 24, 2012
Fixes:
Issue #4 Possible one pixel off in debug rects
Issue #6 ViewWrapper.getDisplayMetrics() doesn't change on orientation changes
Issue #7 px values are not treated as physical pixels
Issue #8 Not growing ListView with e.g. "wmin 0" or "pad 0 0 0 -10"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants