Skip to content

Style RichTextFX in TornadoFX with Type Safe CSS #447

@dmorawetz

Description

@dmorawetz

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions