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

Cache the font of the slider / do not dispose colors #579

Merged
merged 1 commit into from
Mar 23, 2024
Merged
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 @@ -26,6 +26,7 @@ public class NebularSliderDefaultConfiguration implements NebulaSliderGraphicCon
private static final int BAR_HEIGHT = 12;
private static final int SELECTOR_HEIGHT = 32;
protected final NebulaSlider parentSlider;
private Font font;

public NebularSliderDefaultConfiguration(final NebulaSlider parentSlider) {
this.parentSlider = parentSlider;
Expand Down Expand Up @@ -68,14 +69,21 @@ public Color getArrowColor() {

@Override
public Font getTextFont() {
final FontData fontData = parentSlider.getFont().getFontData()[0];
final Font newFont = new Font(parentSlider.getDisplay(), fontData.getName(), Math.max(fontData.getHeight(), 14), SWT.BOLD);
parentSlider.addDisposeListener(e -> {
if (!newFont.isDisposed()) {
newFont.dispose();
}
});
return newFont;
if(font == null || font.isDisposed()) {
final FontData fontData = parentSlider.getFont().getFontData()[0];
Font newFont = new Font(parentSlider.getDisplay(), fontData.getName(), getFontSize(fontData), SWT.BOLD);
parentSlider.addDisposeListener(e -> {
if(!newFont.isDisposed()) {
newFont.dispose();
}
});
this.font = newFont;
}
return font;
}

protected int getFontSize(FontData fontData) {
return Math.max(fontData.getHeight(), 14);
}

@Override
Expand All @@ -99,13 +107,7 @@ public int getBarHeight() {
}

protected Color getAndDisposeColor(final int r, final int g, final int b) {
final Color color = new Color(parentSlider.getDisplay(), r, g, b);
parentSlider.addDisposeListener(e -> {
if (!color.isDisposed()) {
color.dispose();
}
});
return color;
return new Color(r, g, b);
}

@Override
Expand Down
Loading