From 1b60a1b49990b5efc33ccb75f20cb7c7d6327cbe Mon Sep 17 00:00:00 2001 From: ryoii <ryoii@foxmail.com> Date: Sun, 22 Mar 2020 00:21:28 +0800 Subject: [PATCH] Real closable tab --- .../graphical/styleSheet/PrimaryStyleSheet.kt | 24 ++++++++++++++----- .../console/graphical/util/JFoenixAdaptor.kt | 3 +-- .../console/graphical/view/PrimaryView.kt | 12 ++++++---- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/styleSheet/PrimaryStyleSheet.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/styleSheet/PrimaryStyleSheet.kt index 593dad8d9..5b8580d07 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/styleSheet/PrimaryStyleSheet.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/styleSheet/PrimaryStyleSheet.kt @@ -1,9 +1,8 @@ package net.mamoe.mirai.console.graphical.styleSheet -import tornadofx.box -import tornadofx.c -import tornadofx.cssclass -import tornadofx.px +import javafx.scene.Cursor +import javafx.scene.paint.Color +import tornadofx.* class PrimaryStyleSheet : BaseStyleSheet() { companion object { @@ -12,7 +11,8 @@ class PrimaryStyleSheet : BaseStyleSheet() { val container by cssclass("jfx-decorator-content-container") // tab - val tabPane by cssclass("tab-header-background") + val jfxTabPane by cssclass("tab-header-background") + val closeButton by cssclass("tab-close-button") } init { @@ -32,8 +32,20 @@ class PrimaryStyleSheet : BaseStyleSheet() { /* * tab pane */ - tabPane { + jfxTabPane { backgroundColor += c(primaryColor) } + + // 去除JFoenix默认样式 + tab { + and(":closable") { + borderWidth += box(0.px) + borderInsets += box(6.px, 0.px) + } + + closeButton { + and(hover) { cursor = Cursor.HAND } + } + } } } \ No newline at end of file diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt index 394cd82fa..c81136fb9 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt @@ -8,12 +8,11 @@ import javafx.event.EventTarget import javafx.scene.Node import javafx.scene.control.Button import javafx.scene.control.ListView -import javafx.scene.control.TabPane import tornadofx.SortedFilteredList import tornadofx.attachTo import tornadofx.bind -internal fun EventTarget.jfxTabPane(op: TabPane.() -> Unit = {}) = JFXTabPane().attachTo(this, op) +internal fun EventTarget.jfxTabPane(op: JFXTabPane.() -> Unit = {}) = JFXTabPane().attachTo(this, op) internal fun EventTarget.jfxButton(text: String = "", graphic: Node? = null, op: Button.() -> Unit = {}) = JFXButton(text).attachTo(this, op) { diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt index 0f9601cec..11d7f88bc 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt @@ -72,13 +72,15 @@ class PrimaryView : View() { center = jfxTabPane { + tabClosingPolicy = TabPane.TabClosingPolicy.ALL_TABS + logTab("Main", controller.mainLog, closeable = false) - tab("Plugins").content = find<PluginsView>().root + tab("Plugins").apply { isClosable = false }.content = find<PluginsView>().root - tab("Settings").content = find<SettingsView>().root + tab("Settings").apply { isClosable = false }.content = find<SettingsView>().root - tab("Login").content = find<LoginView>().root + tab("Login").apply { isClosable = false }.content = find<LoginView>().root mainTabPane = this } @@ -97,6 +99,8 @@ private fun TabPane.logTab( op: Tab.() -> Unit = {} ) = tab(text) { + this.isClosable = closeable + vbox { buttonbar { @@ -119,8 +123,6 @@ private fun TabPane.logTab( }.ui {// isSucceed: Boolean -> // notify something } - - if (closeable) button("关闭").action { close() } } }