diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-03-22 18:14:08 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-03-22 18:14:08 +0200 |
commit | 232f7fe1be917bf91f6342946f6d001948b8559e (patch) | |
tree | d80dce99e0f681d8a4fba8a5c62f4116c5d0c7df | |
parent | c32fffda15e98dd753fbcfed2d475f04de8669cf (diff) |
Update constants and demagicify RoomView drawing
-rw-r--r-- | ui/types/message.go | 2 | ||||
-rw-r--r-- | ui/view-main.go | 2 | ||||
-rw-r--r-- | ui/widget/message-view.go | 2 | ||||
-rw-r--r-- | ui/widget/room-view.go | 49 |
4 files changed, 44 insertions, 11 deletions
diff --git a/ui/types/message.go b/ui/types/message.go index 7b96193..6775597 100644 --- a/ui/types/message.go +++ b/ui/types/message.go @@ -61,7 +61,7 @@ func (message *Message) CopyTo(to *Message) { } func (message *Message) CalculateBuffer(width int) { - if width < 1 { + if width < 2 { return } message.Buffer = []string{} diff --git a/ui/view-main.go b/ui/view-main.go index 6f3689c..0c3b0a4 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -70,7 +70,7 @@ func (ui *GomuksUI) NewMainView() tview.Primitive { SetBorderPadding(0, 0, 1, 0) mainView.SetDirection(tview.FlexColumn) - mainView.AddItem(mainView.roomList, 30, 0, false) + mainView.AddItem(mainView.roomList, 25, 0, false) mainView.AddItem(widget.NewBorder(), 1, 0, false) mainView.AddItem(mainView.roomView, 0, 1, true) diff --git a/ui/widget/message-view.go b/ui/widget/message-view.go index 941b987..f263350 100644 --- a/ui/widget/message-view.go +++ b/ui/widget/message-view.go @@ -53,7 +53,7 @@ type MessageView struct { func NewMessageView() *MessageView { return &MessageView{ Box: tview.NewBox(), - MaxSenderWidth: 20, + MaxSenderWidth: 15, DateFormat: "January _2, 2006", TimestampFormat: "15:04:05", TimestampWidth: 8, diff --git a/ui/widget/room-view.go b/ui/widget/room-view.go index a194054..433d5dd 100644 --- a/ui/widget/room-view.go +++ b/ui/widget/room-view.go @@ -114,17 +114,50 @@ func (view *RoomView) Focus(delegate func(p tview.Primitive)) { delegate(view.input) } +// Constants defining the size of the room view grid. +const ( + UserListBorderWidth = 1 + UserListWidth = 20 + StaticHorizontalSpace = UserListBorderWidth + UserListWidth + + TopicBarHeight = 1 + StatusBarHeight = 1 + InputBarHeight = 1 + StaticVerticalSpace = TopicBarHeight + StatusBarHeight + InputBarHeight +) + func (view *RoomView) Draw(screen tcell.Screen) { - view.Box.Draw(screen) + x, y, width, height := view.GetInnerRect() + if width <= 0 || height <= 0 { + return + } - x, y, width, height := view.GetRect() - view.topic.SetRect(x, y, width, 1) - view.content.SetRect(x, y+1, width-30, height-3) - view.status.SetRect(x, y+height-2, width, 1) - view.userList.SetRect(x+width-29, y+1, 29, height-3) - view.ulBorder.SetRect(x+width-30, y+1, 1, height-3) - view.input.SetRect(x, y+height-1, width, 1) + // Calculate actual grid based on view rectangle and constants defined above. + var ( + contentHeight = height - StaticVerticalSpace + contentWidth = width - StaticHorizontalSpace + + userListBorderColumn = x + contentWidth + userListColumn = userListBorderColumn + UserListBorderWidth + + topicRow = y + contentRow = topicRow + TopicBarHeight + statusRow = contentRow + contentHeight + inputRow = statusRow + StatusBarHeight + ) + + // Update the rectangles of all the children. + view.topic.SetRect(x, topicRow, width, TopicBarHeight) + view.content.SetRect(x, contentRow, contentWidth, contentHeight) + view.status.SetRect(x, statusRow, width, StatusBarHeight) + if userListColumn > x { + view.userList.SetRect(userListColumn, contentRow, UserListWidth, contentHeight) + view.ulBorder.SetRect(userListBorderColumn, contentRow, UserListBorderWidth, contentHeight) + } + view.input.SetRect(x, inputRow, width, InputBarHeight) + // Draw everything + view.Box.Draw(screen) view.topic.Draw(screen) view.content.Draw(screen) view.status.Draw(screen) |