DigitalRedPanda/Kivarino

Selected Tab's CloseText disappears

DigitalRedPanda opened this issue · 1 comments

When adding channels, the tab doesn't show the CloseText
adding channel
Or when hovering over a focused button the CloseText disappears
hovering the focused button

Cause

the focus property wasn't utilized, but it depended on the hover state, which was the reason for the bug. As shown below:

focusedProperty().addListener(focusEvent -> {
    if(isFocused()) {
        setStyle("-fx-background-color: #0B6623;");
        colorAdjust.setBrightness(0.25);
        hBox.setPadding(modifiedInset);
    } else {
        setStyle("-fx-background-color: #404446;");
        colorAdjust.setBrightness(0);
        hBox.setPadding(defaultInset);
    }
});
hoverProperty().addListener(hoverEvent -> {
    if(!isFocused()) {
        if (isHover()) {
            timeline1.play();
            hBox.setPadding(modifiedInset);
            closeText.setVisible(true);
            closeText.setFont(Font.font(15));
        } else {
            new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(colorAdjust.brightnessProperty(), colorAdjust.brightnessProperty().getValue(), EASE_BOTH)),
                new KeyFrame(Duration.millis(100), new KeyValue(colorAdjust.brightnessProperty(), 0, EASE_BOTH))).play();
            hBox.setPadding(defaultInset);
            closeText.setFont(Font.font(0));
            closeText.setVisible(false);
        }
    }
});

Solution

Use implication

We should use an implication to substitute the focus property

$$isFocused(Stage)\implies isFocused(Tab)$$

Which is equivalent to:

$$\neg isFocused(Stage)\lor isFocused(Tab)$$

Hence, this will result in this code:

focusedProperty().addListener(focusEvent -> {
    if(!GUI.primaryStage.isFocused() || isFocused()) {
        Tab.focusedTab = this;
        setStyle("-fx-background-color: #0B6623;");
        colorAdjust.setBrightness(0.25);
        closeText.setVisible(true);
        closeText.setFont(Font.font(15));
        hBox.setPadding(modifiedInset);
    } else {
        setStyle("-fx-background-color: #404446;");
        closeText.setVisible(false);
        colorAdjust.setBrightness(0);
        closeText.setFont(Font.font(0));
        hBox.setPadding(defaultInset);
    }
});

The Tab.focusedTab = this; will be addressed below

Use an instance

We can use the instance above to keep track of the focused tab and then check for inequality:

hoverProperty().addListener(hoverEvent -> {
    if(Tab.focusedTab != this) {
        if (isHover()) {
            timeline1.play();
            hBox.setPadding(modifiedInset);
            closeText.setVisible(true);
            closeText.setFont(Font.font(15));

        }
        else {
            new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(colorAdjust.brightnessProperty(), colorAdjust.brightnessProperty().getValue(), EASE_BOTH)),
                new KeyFrame(Duration.millis(100), new KeyValue(colorAdjust.brightnessProperty(), 0, EASE_BOTH))).play();
            hBox.setPadding(defaultInset);
            closeText.setFont(Font.font(0));
            closeText.setVisible(false);
        }
    }
});

Result

The result of applying the solution