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

Correctly report the required size to paint the PGroup control #627

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public Rectangle getClientArea()
*/
public Rectangle computeTrim(int x, int y, int width, int height)
{
Rectangle area = new Rectangle(x, y, width, height);
Rectangle area = new Rectangle(x, y, Math.max(0, width), Math.max(0, height));
area.x -= margin;
area.y -= titleHeight;
area.width += (2 * margin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,16 +612,20 @@ public void setText(String text)
/**
* @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
*/
public Point computeSize(int arg0, int arg1, boolean arg2)
{
checkWidget();
if (getExpanded())
return super.computeSize(arg0, arg1, arg2);

Rectangle trim = strategy.computeTrim(0, 0, 0, 0);
trim.width = super.computeSize(arg0, arg1, arg2).x;
return new Point(trim.width, Math.max(trim.height, arg1));
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget();
if(changed) {
strategy.update();
}
Rectangle trim = strategy.computeTrim(0, 0, wHint, 0);
Point controlSize = super.computeSize(wHint, hHint, changed);
if(!getExpanded()) {
controlSize.y = Math.max(trim.height, hHint);
}
controlSize.x = Math.max(Math.max(controlSize.x, trim.width), wHint);
return controlSize;
}

/**
* Returns the expanded/collapsed state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class RectangleGroupStrategy extends AbstractGroupStrategy
private Color g2;

private int titleHeight;
private int titleWidth;

private int fontHeight;

Expand Down Expand Up @@ -577,16 +578,27 @@ public Rectangle getClientArea()
* @see org.eclipse.nebula.widgets.pgroup.AbstractGroupStrategy#computeTrim(int, int, int, int)
*/
@Override
public Rectangle computeTrim(int x, int y, int width, int height)
public Rectangle computeTrim(int x, int y, int widthHint, int heightHint)
{
Rectangle area = new Rectangle(x, y, width, height);

Rectangle area = new Rectangle(x, y, Math.max(0, widthHint), Math.max(0, heightHint));
area.x -= margin;
area.y -= titleHeight;
area.width += (2 * margin);
area.width += (2 * margin);
PGroup group = getGroup();
if(widthHint == SWT.DEFAULT) {
// This indicates the caller wants the preferred size to be computed so we should give a clue how much space the control will take up without hiding anything
area.width += titleWidth + 2 * hMargin + betweenSpacing;
AbstractRenderer toggleRenderer = group.getToggleRenderer();
if(toggleRenderer != null) {
Point p = toggleRenderer.getSize();
area.width += p.x;
}
}
area.height += titleHeight;
if (getGroup().getExpanded())
if(group.getExpanded())
{
if ((getGroup().getStyle() & SWT.SMOOTH) != 0)
if((group.getStyle() & SWT.SMOOTH) != 0)
{
area.height += 5;
}
Expand Down Expand Up @@ -762,44 +774,36 @@ public void setBorderColor(Color borderColor)
this.borderColor = borderColor;
}

@Override
public void update()
{
GC gc = new GC(getGroup());

titleHeight = 0;
@Override
public void update() {

int imageHeight = 0;
if (getGroup().getImage() != null) {
imageHeight = getGroup().getImage().getBounds().height;
PGroup group = getGroup();
GC gc = new GC(group);
try {
String text = group.getText();
Point extent = gc.stringExtent(text);
titleWidth = extent.x;
int imageHeight = 0;
if(group.getImage() != null) {
imageHeight = group.getImage().getBounds().height;
}
if((group.getImagePosition() & SWT.TOP) == 0) {
titleHeight = Math.max(gc.getFontMetrics().getHeight() + (2 * titleTextMargin), imageHeight);
titleHeight += (2 * vMargin);
} else {
titleHeight = Math.max(gc.getFontMetrics().getHeight() + (2 * titleTextMargin) + (2 * vMargin), imageHeight + 1);
}
if(group.getToggleRenderer() != null) {
int toggleHeight = group.getToggleRenderer().getSize().y;
titleHeight = Math.max(toggleHeight + (2 * vMargin), titleHeight);
}
fontHeight = gc.getFontMetrics().getHeight();
titleAreaHeight = fontHeight + (2 * titleTextMargin) + (2 * vMargin);
if(group.getToggleRenderer() != null) {
titleAreaHeight = Math.max(titleAreaHeight, group.getToggleRenderer().getSize().y + (2 * vMargin));
}
} finally {
gc.dispose();
}
if ((getGroup().getImagePosition() & SWT.TOP) == 0)
{
titleHeight = Math.max(gc.getFontMetrics().getHeight() + (2 * titleTextMargin),
imageHeight);
titleHeight += (2 * vMargin);
}
else
{
titleHeight = Math.max(gc.getFontMetrics().getHeight() + (2 * titleTextMargin)
+ (2 * vMargin), imageHeight + 1);
}
if (getGroup().getToggleRenderer() != null)
{
int toggleHeight = getGroup().getToggleRenderer().getSize().y;
titleHeight = Math.max(toggleHeight + (2 * vMargin), titleHeight);
}

fontHeight = gc.getFontMetrics().getHeight();

titleAreaHeight = fontHeight + (2 * titleTextMargin) + (2 * vMargin);
if (getGroup().getToggleRenderer() != null)
{
titleAreaHeight = Math.max(titleAreaHeight, getGroup().getToggleRenderer()
.getSize().y
+ (2 * vMargin));
}

gc.dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public Rectangle getClientArea()
*/
public Rectangle computeTrim(int x, int y, int width, int height)
{
Rectangle area = new Rectangle(x, y, width, height);
Rectangle area = new Rectangle(x, y, Math.max(0, width), Math.max(0, height));
area.y -= titleHeight;
area.height += titleHeight;
return area;
Expand Down
Loading