aboutsummaryrefslogtreecommitdiff
path: root/ui/widget
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-22 18:14:08 +0200
committerTulir Asokan <tulir@maunium.net>2018-03-22 18:14:08 +0200
commit232f7fe1be917bf91f6342946f6d001948b8559e (patch)
treed80dce99e0f681d8a4fba8a5c62f4116c5d0c7df /ui/widget
parentc32fffda15e98dd753fbcfed2d475f04de8669cf (diff)
Update constants and demagicify RoomView drawing
Diffstat (limited to 'ui/widget')
-rw-r--r--ui/widget/message-view.go2
-rw-r--r--ui/widget/room-view.go49
2 files changed, 42 insertions, 9 deletions
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)