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

Zoom dialog fonts based on user scale setting #125

Merged
merged 2 commits into from
Aug 20, 2020
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
64 changes: 64 additions & 0 deletions app/src/processing/app/platform/DefaultPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.Graphics;
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import javax.swing.Icon;
import javax.swing.UIManager;
Expand All @@ -38,6 +41,7 @@

import processing.app.Base;
import processing.app.Preferences;
import processing.app.ui.Toolkit;


/**
Expand All @@ -56,6 +60,36 @@
* know if name is proper Java package syntax.)
*/
public class DefaultPlatform {

private final String[] FONT_SCALING_WIDGETS = {
"Button",
"CheckBox",
"CheckBoxMenuItem",
"ComboBox",
"List",
"Menu",
"MenuBar",
"MenuItem",
"OptionPane",
"Panel",
"PopupMenu",
"ProgressBar",
"RadioButton",
"RadioButtonMenuItem",
"ScrollPane",
"TabbedPane",
"Table",
"TableHeader",
"TextArea",
"TextPane",
"TitledBorder",
"ToggleButton",
"ToolBar",
"ToolTip",
"Tree",
"Viewport"
};

Base base;

private final float ZOOM_DEFAULT_SIZING = 1;
Expand Down Expand Up @@ -97,6 +131,16 @@ public void setLookAndFeel() throws Exception {
} else {
UIManager.setLookAndFeel(laf);
}

// Specify font when scaling is active.
if (!Preferences.getBoolean("editor.zoom.auto")) {
for (String widgetName : FONT_SCALING_WIDGETS) {
scaleDefaultFont(widgetName);
}

UIManager.put("Label.font", new Font("Dialog", Font.PLAIN, Toolkit.zoom(12)));
UIManager.put("TextField.font", new Font("Dialog", Font.PLAIN, Toolkit.zoom(12)));
}
}


Expand Down Expand Up @@ -237,6 +281,26 @@ public int getIconHeight() {
public void paintIcon(Component c, Graphics g, int x, int y) {}
}

/**
* Set the default font for the widget by the given name.
*
* @param name The name of the widget whose font will be set to a scaled version of its current
* default font in the selected look and feel. This must match the system widget name like
* "Button" or "CheckBox"
*/
private void scaleDefaultFont(String name) {
String fontPropertyName = name + ".font";

Font currentFont = (Font) UIManager.get(fontPropertyName);
System.out.println(currentFont);
float newSize = Toolkit.zoom(currentFont.getSize());
System.out.println(newSize);
Font newFont = currentFont.deriveFont(newSize);
System.out.println(newFont);

UIManager.put(fontPropertyName, newFont);
}

/**
* Replacement tree icon for mac when using Vaqua.
*
Expand Down
1 change: 1 addition & 0 deletions app/src/processing/app/tools/CreateFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.UIManager;


/**
Expand Down
1 change: 1 addition & 0 deletions app/src/processing/app/ui/Toolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ static public void zoomSwingFonts() {
static public int zoom(int pixels) {
if (zoom == 0) {
zoom = parseZoom();
System.out.println(zoom);
}
// Deal with 125% scaling badness
// https://github.com/processing/processing/issues/4902
Expand Down
7 changes: 5 additions & 2 deletions java/src/processing/mode/java/JavaEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1750,8 +1750,11 @@ protected void autoSave() {
+ " changes in your sketch.<br />"
+ "&nbsp;&nbsp;&nbsp; Do you want to save it before"
+ " running? </body></html>");
label.setFont(new Font(label.getFont().getName(),
Font.PLAIN, label.getFont().getSize() + 1));
label.setFont(new Font(
label.getFont().getName(),
Font.PLAIN,
Toolkit.zoom(label.getFont().getSize() + 1)
));
panelLabel.add(label);
panelMain.add(panelLabel);
final JCheckBox dontRedisplay = new JCheckBox("Remember this decision");
Expand Down