Update constants and demagicify RoomView drawing
This commit is contained in:
parent
c32fffda15
commit
232f7fe1be
@ -61,7 +61,7 @@ func (message *Message) CopyTo(to *Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (message *Message) CalculateBuffer(width int) {
|
func (message *Message) CalculateBuffer(width int) {
|
||||||
if width < 1 {
|
if width < 2 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
message.Buffer = []string{}
|
message.Buffer = []string{}
|
||||||
|
@ -70,7 +70,7 @@ func (ui *GomuksUI) NewMainView() tview.Primitive {
|
|||||||
SetBorderPadding(0, 0, 1, 0)
|
SetBorderPadding(0, 0, 1, 0)
|
||||||
|
|
||||||
mainView.SetDirection(tview.FlexColumn)
|
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(widget.NewBorder(), 1, 0, false)
|
||||||
mainView.AddItem(mainView.roomView, 0, 1, true)
|
mainView.AddItem(mainView.roomView, 0, 1, true)
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ type MessageView struct {
|
|||||||
func NewMessageView() *MessageView {
|
func NewMessageView() *MessageView {
|
||||||
return &MessageView{
|
return &MessageView{
|
||||||
Box: tview.NewBox(),
|
Box: tview.NewBox(),
|
||||||
MaxSenderWidth: 20,
|
MaxSenderWidth: 15,
|
||||||
DateFormat: "January _2, 2006",
|
DateFormat: "January _2, 2006",
|
||||||
TimestampFormat: "15:04:05",
|
TimestampFormat: "15:04:05",
|
||||||
TimestampWidth: 8,
|
TimestampWidth: 8,
|
||||||
|
@ -114,17 +114,50 @@ func (view *RoomView) Focus(delegate func(p tview.Primitive)) {
|
|||||||
delegate(view.input)
|
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) {
|
func (view *RoomView) Draw(screen tcell.Screen) {
|
||||||
|
x, y, width, height := view.GetInnerRect()
|
||||||
|
if width <= 0 || height <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.Box.Draw(screen)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
view.topic.Draw(screen)
|
view.topic.Draw(screen)
|
||||||
view.content.Draw(screen)
|
view.content.Draw(screen)
|
||||||
view.status.Draw(screen)
|
view.status.Draw(screen)
|
||||||
|
Loading…
Reference in New Issue
Block a user