Skip to content

Commit

Permalink
More changes related to button heights
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Jul 17, 2021
1 parent 1906c95 commit 049ee01
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Expand Up @@ -29,13 +29,18 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TypedListener;

import ummisco.gama.dev.utils.DEBUG;
import ummisco.gama.ui.resources.GamaColors;
import ummisco.gama.ui.resources.GamaColors.GamaUIColor;
import ummisco.gama.ui.resources.GamaIcons;
import ummisco.gama.ui.utils.WorkbenchHelper;

public class FlatButton extends Canvas implements PaintListener, Listener {

static {
DEBUG.ON();
}

public static FlatButton create(final Composite comp, final int style) {
return new FlatButton(comp, style);
}
Expand Down Expand Up @@ -63,13 +68,13 @@ public static FlatButton menu(final Composite comp, final GamaUIColor color, fin
.setImage(GamaIcons.create("small.dropdown").image());
}

private static int FIXED_HEIGHT = 20;

private int height = FIXED_HEIGHT;
private Image image;
private String text;
private RGB colorCode;
private static final int innerMarginWidth = 5;
private static int DEFAULT_HEIGHT =
WorkbenchHelper.getDisplay().getSystemFont().getFontData()[0].getHeight() + innerMarginWidth;
private int height = DEFAULT_HEIGHT;
private static final int imagePadding = 5;
private boolean enabled = true;
private boolean hovered = false;
Expand Down Expand Up @@ -235,6 +240,11 @@ public Point computeSize(final int wHint, final int hHint, final boolean changed
} else {
width = computeMinWidth();
}
if (hHint != SWT.DEFAULT) {
height = hHint;
} else {
height = computeMinHeight();
}
return new Point(width, height);
}

Expand All @@ -259,6 +269,24 @@ public int computeMinWidth() {
return width;
}

public int computeMinHeight() {
int height = 0;
final Image image = getImage();
if (image != null) {
final Rectangle bounds = image.getBounds();
height = bounds.height + imagePadding;
}
if (text != null) {
final GC gc = new GC(this);
// gc.setFont(getFont());
final Point extent = gc.textExtent(text + "...");
gc.dispose();
height = Math.max(height, extent.y + innerMarginWidth);
}
DEBUG.OUT("Computing min height for button " + text + " = " + height);
return height;
}

public String newText() {
if (text == null) return null;
final int parentWidth = getParent().getBounds().width;
Expand Down Expand Up @@ -359,9 +387,9 @@ public FlatButton light() {
}

public FlatButton small() {
if (height == 20) return this;
height = 20;
redraw();
// if (height == 20) return this;
// height = 20;
// redraw();
return this;
}

Expand Down
Expand Up @@ -147,7 +147,7 @@ public static Composite createToolbarComposite(final Composite composite) {
layout.verticalSpacing = 0;
layout.horizontalSpacing = 0;
layout.marginWidth = 0;
final int margin = 2; // REDUCED_VIEW_TOOLBAR_HEIGHT.getValue() ? -1 : 0;
final int margin = 1; // REDUCED_VIEW_TOOLBAR_HEIGHT.getValue() ? -1 : 0;
layout.marginTop = margin;
layout.marginBottom = margin;
layout.marginHeight = margin;
Expand Down

0 comments on commit 049ee01

Please sign in to comment.