Minor UI changes

This commit is contained in:
Tulir Asokan 2019-04-13 17:04:52 +03:00
parent e5264a242d
commit 98a8b52862
2 changed files with 15 additions and 17 deletions

View File

@ -22,11 +22,12 @@ import (
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/ui/widget"
"maunium.net/go/mautrix" "maunium.net/go/mautrix"
"maunium.net/go/mauview" "maunium.net/go/mauview"
"maunium.net/go/tcell" "maunium.net/go/tcell"
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/ui/widget"
) )
type MemberList struct { type MemberList struct {
@ -50,14 +51,11 @@ func (rml roomMemberList) Len() int {
return len(rml) return len(rml)
} }
func (rml roomMemberList) lessMembership(i, j int) bool {
return rml[j].Membership == "invite" && rml[i].Membership == "join"
}
func (rml roomMemberList) Less(i, j int) bool { func (rml roomMemberList) Less(i, j int) bool {
return rml.lessMembership(i, j) || if rml[i].PowerLevel != rml[j].PowerLevel {
rml[i].PowerLevel > rml[j].PowerLevel || return rml[i].PowerLevel > rml[j].PowerLevel
strings.Compare(rml[i].Displayname, rml[j].Displayname) < 0 }
return strings.Compare(strings.ToLower(rml[i].Displayname), strings.ToLower(rml[j].Displayname)) < 0
} }
func (rml roomMemberList) Swap(i, j int) { func (rml roomMemberList) Swap(i, j int) {
@ -67,7 +65,6 @@ func (rml roomMemberList) Swap(i, j int) {
func (ml *MemberList) Update(data map[string]*mautrix.Member, levels *mautrix.PowerLevels) *MemberList { func (ml *MemberList) Update(data map[string]*mautrix.Member, levels *mautrix.PowerLevels) *MemberList {
ml.list = make(roomMemberList, len(data)) ml.list = make(roomMemberList, len(data))
i := 0 i := 0
debug.Print(levels)
for userID, member := range data { for userID, member := range data {
ml.list[i] = &memberListItem{ ml.list[i] = &memberListItem{
Member: *member, Member: *member,
@ -84,10 +81,11 @@ func (ml *MemberList) Update(data map[string]*mautrix.Member, levels *mautrix.Po
func (ml *MemberList) Draw(screen mauview.Screen) { func (ml *MemberList) Draw(screen mauview.Screen) {
width, _ := screen.Size() width, _ := screen.Size()
for y, member := range ml.list { for y, member := range ml.list {
debug.Print(member.UserID, member.Displayname, member.Membership, member.PowerLevel)
if member.Membership == "invite" { if member.Membership == "invite" {
widget.WriteLineSimpleColor(screen, member.Displayname, 1, y, member.Color) widget.WriteLineSimpleColor(screen, member.Displayname, 1, y, member.Color)
screen.SetCell(0, y, tcell.StyleDefault, '(') screen.SetCell(0, y, tcell.StyleDefault, '(')
if sw := runewidth.StringWidth(member.Displayname); sw < width { if sw := runewidth.StringWidth(member.Displayname); sw < width-1 {
screen.SetCell(sw+1, y, tcell.StyleDefault, ')') screen.SetCell(sw+1, y, tcell.StyleDefault, ')')
} else { } else {
screen.SetCell(width-1, y, tcell.StyleDefault, ')') screen.SetCell(width-1, y, tcell.StyleDefault, ')')

View File

@ -178,7 +178,7 @@ func (msg *BaseMessage) TimestampColor() tcell.Color {
func (msg *BaseMessage) ReplyHeight() int { func (msg *BaseMessage) ReplyHeight() int {
if msg.ReplyTo != nil { if msg.ReplyTo != nil {
return 2 + msg.ReplyTo.Height() return 1 + msg.ReplyTo.Height()
} }
return 0 return 0
} }
@ -278,14 +278,14 @@ func (msg *BaseMessage) DrawReply(screen mauview.Screen) mauview.Screen {
} }
width, height := screen.Size() width, height := screen.Size()
replyHeight := msg.ReplyTo.Height() replyHeight := msg.ReplyTo.Height()
widget.WriteLineSimpleColor(screen, "In reply to", 0, 0, tcell.ColorGreen) widget.WriteLineSimpleColor(screen, "In reply to", 1, 0, tcell.ColorGreen)
widget.WriteLineSimpleColor(screen, msg.ReplyTo.RealSender(), len("In reply to "), 0, msg.ReplyTo.SenderColor()) widget.WriteLineSimpleColor(screen, msg.ReplyTo.RealSender(), 13, 0, msg.ReplyTo.SenderColor())
for y := 1; y < 1+replyHeight; y++ { for y := 0; y < 1+replyHeight; y++ {
screen.SetCell(0, y, tcell.StyleDefault, '') screen.SetCell(0, y, tcell.StyleDefault, '')
} }
replyScreen := mauview.NewProxyScreen(screen, 1, 1, width-1, replyHeight) replyScreen := mauview.NewProxyScreen(screen, 1, 1, width-1, replyHeight)
msg.ReplyTo.Draw(replyScreen) msg.ReplyTo.Draw(replyScreen)
return mauview.NewProxyScreen(screen, 0, replyHeight+2, width, height-replyHeight-2) return mauview.NewProxyScreen(screen, 0, replyHeight+1, width, height-replyHeight-1)
} }
func (msg *BaseMessage) String() string { func (msg *BaseMessage) String() string {