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

Style RichTextFX in TornadoFX with Type Safe CSS #447

Closed
dmorawetz opened this issue Mar 6, 2017 · 4 comments
Closed

Style RichTextFX in TornadoFX with Type Safe CSS #447

dmorawetz opened this issue Mar 6, 2017 · 4 comments

Comments

@dmorawetz
Copy link

dmorawetz commented Mar 6, 2017

I want to include the RichtTextFX CodeArea into my TornadoFX project. Showing it works fine. But setting a style class with codeArea.setStyleClass(0, codeArea.length, "command") doesn't apply my css.

When I check if the class was set with println(codeArea.getStyleAtPosition(codeArea.length / 2)) I get the expected output [command].

My CSS class is defined using the TornadoFX Type-Safe CSS functionality:

class Keywords: Stylesheet() {
    companion object {
        val command by cssclass()
    }

    init {
        command {
            fill = Color.RED
            fontSize = 40.px
            fontWeight = FontWeight.BOLD
        }
    }
}

My MainView:

class MainView: View("Test") {
    var codeArea: CodeArea by singleAssign()
    val controller: mainController by inject()

    override val root = borderpane {
        top = text("Test") {
            addClass(Keywords.command)
        }
        codeArea = CodeArea()
        codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea))

        codeArea.richChanges().subscribe { change ->
            codeArea.setStyleClass(0, codeArea.length, "command")
            println(codeArea.getStyleAtPosition(codeArea.length / 2))
            //codeArea.setStyleSpans(0, controller.computeHighlighting(codeArea.text))
        }
        center = codeArea
    }
}

The text Test showes up as expected with the red color and huge font size.

Does anybody know, how I can apply the CSS properly?

@JordanMartinez
Copy link
Contributor

Shouldn't you be using Collections.singletonList("command") instead of "command"?

@JordanMartinez
Copy link
Contributor

Ah, nevermind. StyleClassedTextArea adds a convenience method...

@JordanMartinez
Copy link
Contributor

The issue must be elsewhere as you're using the right method for that.

@dmorawetz
Copy link
Author

@JordanMartinez You were right! The problem was with TornadoFX (see other issue). Thank you anyway!

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

No branches or pull requests

2 participants