HanSolo / medusa

A JavaFX library for Gauges
Apache License 2.0
688 stars 129 forks source link

Strange section behaviour with Gauge in ScrollPane #163

Closed DJViking closed 5 years ago

DJViking commented 5 years ago

Strange problems with Gauge sections and tick labels when placed in ScrollPane.

PLAIN_AMP Setting value after application shown: Sections and ticks are wrong: screenshot_20190204_132411

Setting value before application shown: Sections and ticks are correct: screenshot_20190204_132408

SIMPLE Setting value before application shown: Sections and ticks are wrong and value is wrong: screenshot_20190204_132415

Setting value before application shown: Sections and ticks are wrong and value is correct: screenshot_20190204_132418

This shows a PLAN_AMP and SIMPLE correctly without ScrollPane: screenshot_20190204_133045 screenshot_20190204_132424

The PLAIN_AMP gets correct sections and ticks in either case If I set the ScrollPane fit-to-width and fit-to-height true. However SIMPLE does not.

The test application:

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

import eu.hansolo.medusa.Gauge;
import eu.hansolo.medusa.Gauge.SkinType;
import eu.hansolo.medusa.GaugeBuilder;
import eu.hansolo.medusa.Section;

public class GaugeTest extends Application {

    public static void main(String[] argv) {
        GaugeTest.launch();
    }

    @Override
    public void start(Stage stage) throws Exception {
        final BorderPane root = new BorderPane();

        final ScrollPane scroll = new ScrollPane();
        scroll.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
        scroll.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
        root.setCenter(scroll);

        final HBox box = new HBox();
        scroll.setContent(box);

        Gauge gauge1 = GaugeBuilder.create()
                .skinType(SkinType.PLAIN_AMP) // .skinType(SkinType.SIMPLE)
                .areasVisible(true)
                .sectionsVisible(true)
                .decimals(2)
                .build();

        gauge1.setPrefWidth(500);
        gauge1.setMinValue(-70.0);
        gauge1.setMaxValue(5.0);
        gauge1.setSections(new Section(-70, -50, Color.web("#fffd5b")),
                new Section(-50, -5, Color.web("#39cc74")),
                new Section(-5, 0, Color.web("#fffd5b")),
                new Section(0, 5, Color.web("#fb4a4a")));

        Gauge gauge2 = GaugeBuilder.create()
                .skinType(SkinType.PLAIN_AMP) // .skinType(SkinType.SIMPLE)
                .areasVisible(true)
                .sectionsVisible(true)
                .decimals(2)
                .build();

        gauge2.setPrefWidth(500);
        gauge2.setMinValue(-5.0);
        gauge2.setMaxValue(50.0);
        gauge2.setSections(new Section(-5, 5, Color.web("#fffd5b")),
                new Section(5, 50, Color.web("#39cc74")));

        box.getChildren().addAll(gauge1, gauge2);

        // gauge1.setValue(-35.0);
        // gauge2.setValue(4.0);

        stage.setScene(new Scene(root));
        stage.setWidth(1000);
        stage.setHeight(600);
        stage.setTitle("GaugeTest");
        stage.show();

        gauge1.setValue(-35.0);
        gauge2.setValue(4.0);
    }
}
DJViking commented 5 years ago

It seems to be a regression from 8.0.

Running 8.0 screenshot_20190205_085607

Running 8.2 screenshot_20190205_085654

HanSolo commented 5 years ago

Should be fixed with commit #0a2590246efefbd54f4b15522bd31520b43729ab