Can I have a DropDown with image? ```dropDown(tr("...
# kvision
j
Can I have a DropDown with image?
Copy code
dropDown(tr("Dropdown with custom list"), icon = "far fa-image", style = ButtonStyle.WARNING) {
    minWidth = 250.px
    image(require("img/cat.jpg")) { height = 170.px; margin = 10.px; title = "Cat" }
    separator()
    image(require("img/dog.jpg")) { height = 170.px; margin = 10.px; title = "Dog" }
}
suggests I can have either a FontAwesome icon plus text or an image. What I want is a custom image with text.
r
You mean on the button or on the list ?
j
On the list and on the button. I would like to replace the "Three Objects" FA icon with an Image as well have text right of the coulored gif + regular menu item behaviour, i.e. elicit an event on click.
kroviz can connect to two or more different servers at the same time. Each serverApp may have its own icon etc. I want to provide the user with visual feedback, which serverApp is in the 'foreground' and allow to switch between them.
r
to use image instead of icon for the button of the
DropDown
component just use
image
property (it's there, it's just not exposed in the constructor)
j
Thanks - I'll try (thought I already did ...)
The following code comes pretty close:
Copy code
fun insertConnection() {
    mainEntry.separator()
    val resString = io.kvision.require("img/gift_48.png")
    val menuEntry = buildMenuEntryWithImage("Connection 1", image = resString, { LoginPrompt().open() })
    mainEntry.add(menuEntry)
}

private fun buildMenuEntryWithImage(label: String, image: ResString?, action: dynamic): Link {
    val link = Link(label, image = image, className = "dropdown-item")
    link.onClick { e ->
        val at = Point(e.pageX.toInt(), e.pageY.toInt())
        UiManager.position = at
        action()
    }
    return link
}
Can I scale the image (ResString) down?
r
Only with some css I'm afraid.
j
OK - no problem (I don't fear CSS anymore ;))
Thanks a lot for your help!
r
you can use Style object for this with pure kotlin 😉
j
resString.style doesn't suggest anythin in IJ ...
I got it:
Copy code
val resString = io.kvision.require("img/gift_48.png") {style}
Have a nice day and stay healthy!
r
I was talking about:
Copy code
val myStyle = style(".dropdown-item") {
    style("img") {
        width = 20.px
        height = 20.px
    }
}
j
I arrived at:
Copy code
val resString = require("img/gift_48.png")
resString { addCssClass("app-icon") }
but it doesn't work - I'll follow your suggestion, though