Skip to content
This repository was archived by the owner on Jun 24, 2021. It is now read-only.

Relative sizes don't work if a relative -fx-font-size is used on the same node #93

Open
tomsontom opened this issue Jun 7, 2018 · 0 comments
Labels
bug Something isn't working

Comments

@tomsontom
Copy link
Contributor

This is a clone of https://bugs.openjdk.java.net/browse/JDK-8204568 running the following application

package bla;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class RelativeFontIssues extends Application {

	public static void main(String[] args) {
		launch(args);
	}

    @Override
    public void start(Stage primaryStage) throws Exception {
        System.err.println("Default Font: " + Font.getDefault().getSize());
        System.err.println("    0.2857142857142857em == " + 0.2857142857142857 * Font.getDefault().getSize());
        System.err.println("    0.3333333333333333em == " + 0.3333333333333333 * Font.getDefault().getSize());
        
        BorderPane pane = new BorderPane();
        pane.setStyle("-fx-font-size: 14");
        
        Label b = new Label("Default");
        b.setStyle("-fx-padding: 0.2857142857142857em; -fx-background-color: red; -fx-background-radius: 0.2857142857142857em");
        Label b2 = new Label("Relative size");
        b2.setStyle("-fx-padding: 0.3333333333333333em; -fx-font-size: 0.8571428571428571em; -fx-background-color: red; -fx-background-radius: 0.3333333333333333em;");
        pane.setCenter(new HBox(b,b2));
        
        Button flip = new Button("Flip size");
        flip.setOnAction( e -> pane.setStyle("-fx-font-size: 28"));
        
        Button print = new Button("Print info");
        print.setOnAction( e -> {
            System.err.println("============");
            System.err.println("Default:");
            System.err.println("    Padding: " + b.getPadding()); // expected 4 & 8
            System.err.println("    Corner: " + b.getBackground().getFills().get(0).getRadii()); // expected 4 & 8
            System.err.println("	Font: " + b.getFont());
            System.err.println("Rel:");
            System.err.println("    Padding: " + b2.getPadding()); // expected 4 & 8
            System.err.println("    Corner: " + b2.getBackground().getFills().get(0).getRadii()); // expected 4 & 8
            System.err.println("	Font: " + b2.getFont());
        });
        pane.setBottom(new HBox(flip, print));
        
        Scene s = new Scene(pane, 500, 500);
        primaryStage.setScene(s);
        primaryStage.show();
    }

}

Now execute the following steps:

  • Click "Print info"
  • Click "Flip size"
  • Click "Print info"
Default Font: 13.0
    0.2857142857142857em == 3.714285714285714
    0.3333333333333333em == 4.333333333333333
============
Default:
    Padding: Insets [top=4.0, right=4.0, bottom=4.0, left=4.0]
    Corner: CornerRadii [uniform radius = 4.0]
	Font: Font[name=System Regular, family=System, style=Regular, size=14.0]
Rel:
    Padding: Insets [top=4.3, right=4.3, bottom=4.3, left=4.3]
    Corner: CornerRadii [uniform radius = 4.3]
	Font: Font[name=System Regular, family=System, style=Regular, size=12.0]
============
Default:
    Padding: Insets [top=8.0, right=8.0, bottom=8.0, left=8.0]
    Corner: CornerRadii [uniform radius = 8.0]
	Font: Font[name=System Regular, family=System, style=Regular, size=28.0]
Rel:
    Padding: Insets [top=4.3, right=4.3, bottom=4.3, left=4.3]
    Corner: CornerRadii [uniform radius = 4.3]
	Font: Font[name=System Regular, family=System, style=Regular, size=24.0]
@eugener eugener added the bug Something isn't working label Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants