Skip to content

Commit

Permalink
Merge pull request #40 from csmith/themes
Browse files Browse the repository at this point in the history
Flesh out a default stylesheet a bit more
  • Loading branch information
greboid committed Feb 24, 2019
2 parents 85b16df + 5394798 commit ff62019
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 68 deletions.
59 changes: 25 additions & 34 deletions src/main/kotlin/MainView.kt
Expand Up @@ -45,44 +45,35 @@ class MainView : View() {
}
}
}
left = vbox {
scrollpane {
listview(SortedList(controller.windows, compareBy { it.sortKey })) {
isFitToHeight = true
bindSelected(controller.selectedWindow)
cellFormat {
text = when (it.type) {
WindowType.SERVER -> "${it.name} [${it.connection?.networkName ?: ""}]"
WindowType.CHANNEL -> "\t${it.name}"
else -> it.name
}
}
controller.selectedWindow.addListener(ChangeListener { _, _, newValue ->
center = newValue.windowUI.root
}
)
prefWidth = 148.0
contextmenu {
item("Close") {
action {
selectedItem?.let {
if (!it.isConnection) {
controller.leaveChannel(it.name)
} else {
it.connection?.disconnect()
}
}

left = listview(SortedList(controller.windows, compareBy { it.sortKey })) {
styleClass.add("tree-view")
bindSelected(controller.selectedWindow)
cellFormat {
text = when (it.type) {
WindowType.SERVER -> "${it.name} [${it.connection?.networkName ?: ""}]"
WindowType.CHANNEL -> it.name
else -> it.name
}
styleClass.removeIf { it.startsWith("node-") }
styleClass.add("node-${it.type.name.toLowerCase()}")
}
controller.selectedWindow.addListener(ChangeListener { _, _, newValue ->
center = newValue.windowUI.root
})
prefWidth = 148.0
contextmenu {
item("Close") {
action {
selectedItem?.let {
if (!it.isConnection) {
controller.leaveChannel(it.name)
} else {
it.connection?.disconnect()
}
}
}
}
vboxConstraints {
vgrow = Priority.ALWAYS
hgrow = Priority.ALWAYS
}
}
borderpaneConstraints {
maxWidth = 150.00
}
}
center = vbox {
Expand Down
10 changes: 4 additions & 6 deletions src/main/kotlin/Stylesheets.kt
Expand Up @@ -6,20 +6,18 @@ import java.nio.file.*


fun installStyles(root: Scene, file: Path) {
runLater {
root.stylesheets.add(MainApp::class.java.getResource("/stylesheet.css").toExternalForm())
}
file.checkAndInstall(root)
val directory = file.toAbsolutePath().parent
directory.watchFile(file) {
root.stylesheets.clear()
file.checkAndInstall(root)
}
}

private fun Path.checkAndInstall(root: Scene) {
if (Files.exists(this)) {
runLater {
runLater {
root.stylesheets.clear()
root.stylesheets.add(MainApp::class.java.getResource("/stylesheet.css").toExternalForm())
if (Files.exists(this)) {
root.stylesheets.add(this.toAbsolutePath().toUri().toURL().toExternalForm())
}
}
Expand Down
40 changes: 12 additions & 28 deletions src/main/kotlin/WindowUI.kt
Expand Up @@ -36,36 +36,20 @@ class WindowUI(connection: Connection?) : View("Right bit") {
}

override val root = borderpane {
center = hbox {
vbox {
add(VirtualizedScrollPane(textArea.apply {
isEditable = false
isWrapText = true
}).apply {
vgrow = Priority.ALWAYS
})
vboxConstraints {
vgrow = Priority.ALWAYS
hgrow = Priority.ALWAYS
}
}
center = VirtualizedScrollPane(textArea.apply {
isEditable = false
isWrapText = true
}).apply {
hgrow = Priority.ALWAYS
vgrow = Priority.ALWAYS
}
right = vbox {
scrollpane {
listview(users) {
isFitToHeight = true
prefWidth = 148.0
}
vboxConstraints {
vgrow = Priority.ALWAYS
hgrow = Priority.ALWAYS
}
}
borderpaneConstraints {
maxWidth = 150.00
}
right = listview(users) {
styleClass.add("nick-list")
prefWidth = 148.0
}

bottom = textfield(inputText) {
styleClass.add("input-field")
action {
if (inputText.value.isNotEmpty()) {
runAsync {
Expand All @@ -76,4 +60,4 @@ class WindowUI(connection: Connection?) : View("Right bit") {
}
}
}
}
}
53 changes: 53 additions & 0 deletions src/main/resources/stylesheet.css
@@ -1,3 +1,56 @@
/* General styling */
.tree-view {
-fx-background-color: transparent;
-fx-pref-width: 175px;
-fx-padding: 0;
-fx-border-width: 0 1px 0 0;
-fx-border-style: solid;
-fx-border-color: #999999;
}

.tree-view .node-channel {
-fx-label-padding: 5px 5px 5px 20px;
}

.tree-view .node-server {
-fx-label-padding: 5px 5px 5px 5px;
-fx-background-color: #dfdfdf;
}

.tree-view .cell {
-fx-padding: 0;
}

.tree-view .cell:selected {
-fx-background-color: #004b7a;
-fx-text-fill: #ffffff;
}

/* Hide the horizontal scrollbar in the tree-view (yuck). */
.tree-view .scroll-bar:horizontal .increment-arrow,
.tree-view .scroll-bar:horizontal .decrement-arrow,
.tree-view .scroll-bar:horizontal .increment-button,
.tree-view .scroll-bar:horizontal .decrement-button {
-fx-padding:0;
}

.nick-list {
-fx-background-color: transparent;
-fx-padding: 0;
-fx-border-width: 0 0 0 1px;
-fx-border-style: solid;
-fx-border-color: #999999;
}

.input-field {
-fx-background-color: #ffffff;
-fx-padding: 5px;
-fx-border-width: 1px 0 0 0;
-fx-border-style: solid;
-fx-border-color: #999999;
}


/* Supported text styles */
.irc-bold { -fx-font-weight: bold; }
.irc-italic { -fx-font-style: italic; }
Expand Down

0 comments on commit ff62019

Please sign in to comment.