桌面上的 Compose 入门程序在 Linux 上非常滞后

发布于 2025-01-20 23:16:54 字数 1449 浏览 7 评论 0原文

我刚刚使用 Intellij 启动了一个桌面项目,使用默认生成的代码构建,在 Linux 上运行它,并且它有效。然后我为按钮文本添加了一个计数器变量(如下所示),它也像以前一样运行。但是当我点击按钮时,点击反应后文本的变化需要长达 10 秒的时间。想知道可能出了什么问题。

我运行的是 Xubuntu 22.04。

@Composable
@Preview
fun App() {
    var text by remember { mutableStateOf("Hello, World!") }
    var ic by remember { mutableStateOf(0) }
    MaterialTheme {
        Button(onClick = {
            ic++
            text = "Hello, Desktop! $ic"
        }) {
            Text(text)
        }
    }
}

fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        App()
    }
}

我的构建.gradle:

import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.6.10"
    id("org.jetbrains.compose") version "1.1.1"
}

group = "me.xxxx"
version = "1.0"

repositories {
    google()
    mavenCentral()
    maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

dependencies {
    implementation(compose.desktop.currentOs)
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "11"
}

compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "Test"
            packageVersion = "1.0.0"
        }
    }
}

I just started a desktop project with Intellij, built with the default generated code, ran it on Linux, and it worked. Then I added a counter variable for the button text (shown as follows), it also ran as before. But when I click on the button, the change of text on reaction to the click takes as long as 10 seconds. Wonder what can be wrong.

I am running Xubuntu 22.04.

@Composable
@Preview
fun App() {
    var text by remember { mutableStateOf("Hello, World!") }
    var ic by remember { mutableStateOf(0) }
    MaterialTheme {
        Button(onClick = {
            ic++
            text = "Hello, Desktop! $ic"
        }) {
            Text(text)
        }
    }
}

fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        App()
    }
}

My build.gradle:

import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.6.10"
    id("org.jetbrains.compose") version "1.1.1"
}

group = "me.xxxx"
version = "1.0"

repositories {
    google()
    mavenCentral()
    maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

dependencies {
    implementation(compose.desktop.currentOs)
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "11"
}

compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "Test"
            packageVersion = "1.0.0"
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2025-01-27 23:16:54

好吧,事实证明一个虚拟盒设置问题。我在MacBook Pro托管的VirtualBox上运行Xubuntu。我需要将图形控制器设置为VirtualBox上的VMSVGA。所以现在响应迅速。

Well, it turns out a VirtualBox setting issue. I run Xubuntu on VirtualBox hosted by MacBook Pro. I need to set graphics controller to VMSVGA on VirtualBox. So now it's responsive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文