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

Optimize background color and underline shapes #558

Merged

Conversation

JordanMartinez
Copy link
Contributor

@JordanMartinez JordanMartinez commented Aug 2, 2017

Only uses 1 shape for a value (background, underline) shared between multiple consecutive TextExt segments.

This provides the needed support to quickly implement #346 without the adjacent segments issue.

@JordanMartinez JordanMartinez changed the title Optimize background color shapes Optimize background color and underline shapes Aug 2, 2017
@JordanMartinez JordanMartinez merged commit b366da3 into FXMisc:master Aug 2, 2017
@JordanMartinez JordanMartinez deleted the optimizeBackgroundColorShapes branch August 2, 2017 17:43
@JordanMartinez
Copy link
Contributor Author

Tested via:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;

public class ConsecutiveDemo extends Application {

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

    InlineCssTextArea area;

    @Override
    public void start(Stage primaryStage) {
        area = new InlineCssTextArea();
        area.replaceText("Some long line of text");
        area.setStyle("-fx-font-size: 32pt;");

        String blueBackground = "-rtfx-background-color: blue;";
        String greenBackground = "-rtfx-background-color: green;";
        String narrowUnderline = "-rtfx-underline-width: 2;";
        String redUnderline = "-rtfx-underline-color: red;";
        String dashedUnderline =  "-rtfx-underline-dash-array: 8;";
        String wideUnderline = "-rtfx-underline-width: 4;";
        setStyles(
                narrowUnderline,    // shouldn't produce an underline, no color specified
                blueBackground + redUnderline, // shouldn't produce an underline (no width specified)
                blueBackground + redUnderline + wideUnderline,
                greenBackground + redUnderline + wideUnderline,
                greenBackground + redUnderline + narrowUnderline + dashedUnderline,
                blueBackground + redUnderline + narrowUnderline + dashedUnderline
                
                /* 
                    Expected Shapes & Total Count:
                        background color shapes: blue, green, blue           = total of 3
                        underline shapes:        red wide, red narrow dashed = total of 2
                 */
        );

        VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(area);

        Scene scene = new Scene(vsPane, 500, 500);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private void setStyles(String... styles) {
        int index = 0;
        for (String s : styles) {
            area.setStyle(index, index + 1, s);
            index++;
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant