Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions src/main/kotlin/chatroom/ChatroomWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import org.koin.core.component.createScope
import org.koin.core.component.inject
import org.koin.core.scope.Scope
import view.AppWindow
import view.DEFAULT_TERMINAL_HEIGHT
import view.DEFAULT_TERMINAL_WIDTH
import view.linearLayoutFill

class ChatroomWindow(
Expand All @@ -32,29 +30,23 @@ class ChatroomWindow(

init {
setHints(listOf(CENTERED))
val totalColumns = DEFAULT_TERMINAL_WIDTH * 3
val totalRows = DEFAULT_TERMINAL_HEIGHT
val leftWidth = LEFT_PANEL_WIDTH
val rightWidth = totalColumns - leftWidth
val sendMessagesHeight = 5
val chatHeight = totalRows - sendMessagesHeight

val rightPanel =
Panel(LinearLayout(VERTICAL)).apply {
setPreferredSize(TerminalSize(rightWidth, totalRows))
setPreferredSize(TerminalSize(RIGHT_WIDTH, TOTAL_ROWS))
addComponent(
viewMessages.bordered()
.setPreferredSize(TerminalSize(0, chatHeight)).linearLayoutFill(),
.setPreferredSize(TerminalSize(0, CHAT_HEIGHT)).linearLayoutFill(),
)
addComponent(
sendMessages.bordered()
.setPreferredSize(TerminalSize(0, sendMessagesHeight)).linearLayoutFill(),
.setPreferredSize(TerminalSize(0, SEND_MESSAGES_HEIGHT)).linearLayoutFill(),
)
}
val chatroom =
Panel(LinearLayout(HORIZONTAL)).apply {
setPreferredSize(TerminalSize(totalColumns, totalRows))
addComponent(usersList.bordered().setPreferredSize(TerminalSize(leftWidth, 0)).linearLayoutFill())
setPreferredSize(TerminalSize(TOTAL_COLUMNS, TOTAL_ROWS))
addComponent(usersList.bordered().setPreferredSize(TerminalSize(LEFT_WIDTH, 0)).linearLayoutFill())
addComponent(rightPanel)
}
component = chatroom
Expand All @@ -65,8 +57,4 @@ class ChatroomWindow(
scope.close()
windowScope.cancel()
}

companion object {
private const val LEFT_PANEL_WIDTH = 20
}
}
19 changes: 19 additions & 0 deletions src/main/kotlin/chatroom/ChatroomWindowConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package chatroom

import view.DEFAULT_TERMINAL_HEIGHT
import view.DEFAULT_TERMINAL_WIDTH

const val TOTAL_COLUMNS = DEFAULT_TERMINAL_WIDTH * 3
const val TOTAL_ROWS = DEFAULT_TERMINAL_HEIGHT
const val LEFT_WIDTH = 20
const val RIGHT_WIDTH = TOTAL_COLUMNS - LEFT_WIDTH
const val SEND_MESSAGES_HEIGHT = 5
const val SEND_MESSAGES_WIDTH = RIGHT_WIDTH - 7
const val CHAT_HEIGHT = TOTAL_ROWS - SEND_MESSAGES_HEIGHT

fun sendMessagesWidth(): Int {
assert(SEND_MESSAGES_WIDTH > 10) {
"Send Message Width must never be less than 10 columns."
}
return SEND_MESSAGES_WIDTH
}
3 changes: 2 additions & 1 deletion src/main/kotlin/chatroom/sendmessages/SendMessagePanel.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chatroom.sendmessages

import chatroom.BorderedPanel
import chatroom.sendMessagesWidth
import chatroom.sendmessages.SendMessageEvent.SendMessage
import chatroom.sendmessages.SendMessageViewState.Clear
import com.googlecode.lanterna.TerminalSize
Expand All @@ -15,7 +16,7 @@ class SendMessagePanel(
) : Panel(BorderLayout()), BorderedPanel, SendMessagesView {
private val message: CharacterWrapTextBox =
CharacterWrapTextBox(
TerminalSize(20, 3),
TerminalSize(sendMessagesWidth(), 3),
) { presenter.onEvent(SendMessage(text)) }
private val text: String
get() = message.text
Expand Down
Loading