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

Change position of MenuBar #4838

Closed
guiiamorim opened this issue May 20, 2024 · 3 comments
Closed

Change position of MenuBar #4838

guiiamorim opened this issue May 20, 2024 · 3 comments
Labels
desktop question Not a bug, but question or comment

Comments

@guiiamorim
Copy link

Hi, I'm facing a problem when creating a MenuBar on a transparent window. I hoped that would be possible to place the menubar below my custom titlebar, but it shows above it. Is there a way to customize the position of the menubar?

@Composable
@Preview
fun App() {
    MaterialTheme {
        Box(
            modifier = Modifier.fillMaxSize()
                .background(Color.hsl(232F, .37F, .08F))
                .padding(8.dp),
        ) {
            Row(
                Modifier.fillMaxSize(),
            ) {
                Surface(
                    Modifier.weight(.7F)
                        .fillMaxHeight(),
                    shape = RoundedCornerShape(4.dp)
                ) {
                    Box(
                        Modifier.background(Color.hsl(232F, .38F, .12F))
                            .fillMaxHeight()
                            .padding(4.dp),
                    ) {

                    }
                }
                Spacer(Modifier.width(4F.dp))
                Surface(
                    Modifier.weight(2F)
                        .fillMaxHeight(),
                    shape = RoundedCornerShape(4.dp)
                ) {
                    Box(
                        Modifier
                            .background(Color.hsl(232F, .38F, .12F))
                            .fillMaxHeight()
                            .padding(4.dp),
                    ) {

                    }
                }
                Spacer(Modifier.width(4F.dp))
                Surface(
                    Modifier.weight(1F)
                        .fillMaxHeight(),
                    shape = RoundedCornerShape(4.dp)
                ) {
                    Box(
                        Modifier.background(Color.hsl(232F, .38F, .12F))
                            .fillMaxHeight()
                            .padding(4.dp),
                    ) {

                    }
                }
            }
        }
    }
}

@Composable
fun WindowScope.AppWindowTitleBar(
    state: WindowState,
    title: String,
    onClose: () -> Unit,
    onMinimize: () -> Unit = { state.isMinimized = state.isMinimized.not() },
    onMaximize: () -> Unit = {
        state.placement = if (state.placement == WindowPlacement.Maximized)
            WindowPlacement.Floating else WindowPlacement.Maximized
    },
) {
    Box(
        Modifier.fillMaxWidth()
            .background(Color.hsl(233F, .4F, .04F))
    ) {
        WindowDraggableArea(Modifier.fillMaxWidth()) {
            Row(Modifier.align(Alignment.TopEnd).fillMaxWidth().padding(horizontal = 8.dp)) {
                Box(Modifier.align(Alignment.CenterVertically)) {
                    Text(title, color = Color.White)
                }
                Spacer(Modifier.weight(1F))

                IconButton(onClick = onMinimize) {
                    Icon(Icons.Outlined.Minimize, "Minimizar", tint = Color.White)
                }

                val isFloating = state.placement == WindowPlacement.Floating
                IconButton(onClick = onMaximize) {
                    Icon(
//                        if (isFloating) Icons.Outlined.Maximize else SelectedWindow,
                        Icons.Outlined.Maximize,
                        "Maximizar",
                        tint = Color.White
                    )
                }

                IconButton(onClick = onClose) {
                    Icon(Icons.Outlined.Close, "Close", tint = Color.White)
                }
            }
        }
    }
}

fun main() = application {
    val state = rememberWindowState(size = DpSize(1280.dp, 800.dp), position = WindowPosition(Alignment.Center))
    val roundedCorners = state.placement == WindowPlacement.Floating

    Window(
        onCloseRequest = ::exitApplication,
        state = state,
        title = "FreeWorship",
        undecorated = true,
        transparent = true,
    ) {
        window.minimumSize = Dimension(1280, 800)

        Surface(
            modifier = Modifier.fillMaxSize(),
            shape = if (roundedCorners) RoundedCornerShape(6.dp) else RoundedCornerShape(0.dp),

            ) {
            Column {
                AppWindowTitleBar(state, "FreeWorship", ::exitApplication)
                MenuBar {
                    Menu("Arquivo") {}
                }
                App()
            }
        }
    }
}

image

@guiiamorim guiiamorim added enhancement New feature or request submitted labels May 20, 2024
@mazunin-v-jb mazunin-v-jb added question Not a bug, but question or comment desktop and removed enhancement New feature or request submitted labels May 21, 2024
@mazunin-v-jb
Copy link
Contributor

@guiiamorim hello!
Could you provide information about Kotlin and Compose versions of your project as well as OS and Java version?

@mazunin-v-jb mazunin-v-jb added the wait for reply Further information is requested label May 22, 2024
@guiiamorim
Copy link
Author

OS: Ubuntu 24.04
Java:
openjdk 21.0.3 2024-04-16
OpenJDK Runtime Environment (build 21.0.3+9-Ubuntu-1ubuntu1)
OpenJDK 64-Bit Server VM (build 21.0.3+9-Ubuntu-1ubuntu1, mixed mode, sharing)

Compose: 1.6.0
Kotlin: 1.9.22

@mazunin-v-jb mazunin-v-jb removed the wait for reply Further information is requested label May 23, 2024
@igordmn
Copy link
Collaborator

igordmn commented May 27, 2024

If you use a custom titleBar, you should also implement a custom MenuBar yourself.

The built-in MenuBar by design is always attached to the top of the window, or to the top of the screen (depending on the OS).

Placing MenuBar in other places is only possible if we add a new standalone component, with its own design (you can create a separate issue for that).

@igordmn igordmn closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop question Not a bug, but question or comment
Projects
None yet
Development

No branches or pull requests

3 participants