JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.9k stars 1.16k forks source link

Cannot find the api to implement the requirement,please help. #2909

Open s949492225 opened 1 year ago

s949492225 commented 1 year ago

May I ask how to achieve the effect in the following picture? Display the icon in the title bar, click the icon to display a window below the icon, and do not display the application in the dock of mac.

It is said that jetbrain toolbox is written in compose desktop, and the interaction used is also in the form mentioned above. preferably a simple demo, thank you

image

malliaridis commented 1 year ago

I guess you want to use the tray (see Menu, tray, notifications) with a Dialog? Sample implementation would be:

fun main() = application {
    var count by remember { mutableStateOf(0) }
    var isOpen by remember { mutableStateOf(false) }

    val trayState = rememberTrayState()

    Tray(
        state = trayState,
        icon = TrayIcon,
        onAction = { isOpen = true },
    )

    if (isOpen) {
        Dialog(
            onCloseRequest = { isOpen = false },
        ) {
            this.window.size
            Box(
                modifier = Modifier.size(256.dp),
                contentAlignment = Alignment.Center
            ) {
                Text(text = "Value: $count")
            }
        }
    }
}

object TrayIcon : Painter() {
    override val intrinsicSize = Size(256f, 256f)

    override fun DrawScope.onDraw() {
        drawOval(Color(0xFFFFA500))
    }
}
s949492225 commented 1 year ago

Is there any way to get the tray's position and width on the screen?

malliaridis commented 1 year ago

As far as I know there is no way to do that, not with the current version of Compose, and I don't think it will be easy to support or work around this limitation. But correct me if I'm wrong.

Giuliopime commented 1 year ago

That Dialog trick did not work for me, the icon is still visible in the dock, any solution?

okushnikov commented 2 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.