From bfad966cd2eca2ead5055d1a6c4ad685a294bc3b Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sat, 2 Jan 2021 01:55:19 -0800 Subject: [PATCH] only highlight message for a short while --- internal/ui/messages/container/container.go | 4 +--- .../container/cozy/message_collapsed.go | 2 +- internal/ui/messages/container/list.go | 24 +++++++++---------- internal/ui/messages/message/message.go | 2 ++ internal/ui/service/auth/entries.go | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/internal/ui/messages/container/container.go b/internal/ui/messages/container/container.go index 44439bf..3c51a0c 100644 --- a/internal/ui/messages/container/container.go +++ b/internal/ui/messages/container/container.go @@ -52,10 +52,8 @@ type Container interface { // Message finds and returns the message, if any. Message(id cchat.ID, nonce string) MessageRow - // Highlight temporarily highlights the given message. + // Highlight temporarily highlights the given message for a short while. Highlight(msg MessageRow) - // Unhighlight removes the message highlight. - Unhighlight() // UI methods. diff --git a/internal/ui/messages/container/cozy/message_collapsed.go b/internal/ui/messages/container/cozy/message_collapsed.go index 77ddb2d..2a4902f 100644 --- a/internal/ui/messages/container/cozy/message_collapsed.go +++ b/internal/ui/messages/container/cozy/message_collapsed.go @@ -29,8 +29,8 @@ func WrapCollapsedMessage(gc *message.GenericContainer) *CollapsedMessage { gc.Timestamp.SetSizeRequest(AvatarSize, -1) gc.Timestamp.SetVAlign(gtk.ALIGN_START) gc.Timestamp.SetXAlign(0.5) // middle align + gc.Timestamp.SetMarginEnd(container.ColumnSpacing) gc.Timestamp.SetMarginStart(container.ColumnSpacing * 2) - gc.Timestamp.SetMarginTop(container.ColumnSpacing) // Set Content's padding accordingly to FullMessage's main box. gc.Content.ToWidget().SetMarginEnd(container.ColumnSpacing * 2) diff --git a/internal/ui/messages/container/list.go b/internal/ui/messages/container/list.go index 02dedba..8fb66c0 100644 --- a/internal/ui/messages/container/list.go +++ b/internal/ui/messages/container/list.go @@ -3,6 +3,7 @@ package container import ( "container/list" "log" + "time" "github.com/diamondburned/cchat" "github.com/diamondburned/cchat-gtk/internal/gts" @@ -83,10 +84,10 @@ func (c *ListStore) findIndex(id cchat.ID) (*messageRow, int) { // // TODO: combine compact and full so they share the same attach method. func (c *ListStore) SwapMessage(msg MessageRow) bool { - // Wrap msg inside a *messageRow if it's not already. + // Unwrap msg from a *messageRow if it's not already. m, ok := msg.(*messageRow) - if !ok { - m = &messageRow{MessageRow: msg} + if ok { + msg = m.MessageRow } // Get the current message's index. @@ -95,16 +96,16 @@ func (c *ListStore) SwapMessage(msg MessageRow) bool { return false } + // Remove the to-be-replaced message box. We should probably reuse the row. + c.ListBox.Remove(oldMsg.Row()) + // Add a row at index. The actual row we want to delete will be shifted // downwards. - c.ListBox.Insert(m.Row(), ix) - - // Delete the to-be-replaced message. - oldMsg.Row().Destroy() + c.ListBox.Insert(msg.Row(), ix) // Set the message into the map. - row := c.messages[idKey(m.ID())] - *row = *m + row := c.messages[idKey(msg.ID())] + row.MessageRow = msg return true } @@ -403,9 +404,6 @@ func (c *ListStore) Highlight(msg MessageRow) { row := msg.Row() row.GrabFocus() c.ListBox.DragHighlightRow(row) + gts.DoAfter(2*time.Second, c.ListBox.DragUnhighlightRow) }) } - -func (c *ListStore) Unhighlight() { - c.ListBox.DragUnhighlightRow() -} diff --git a/internal/ui/messages/message/message.go b/internal/ui/messages/message/message.go index 166acbf..21d2ef1 100644 --- a/internal/ui/messages/message/message.go +++ b/internal/ui/messages/message/message.go @@ -113,6 +113,8 @@ func NewEmptyContainer() *GenericContainer { user.Show() ctbody := labeluri.NewLabel(text.Rich{}) + ctbody.SetVExpand(true) + ctbody.SetHExpand(true) ctbody.SetEllipsize(pango.ELLIPSIZE_NONE) ctbody.SetLineWrap(true) ctbody.SetLineWrapMode(pango.WRAP_WORD_CHAR) diff --git a/internal/ui/service/auth/entries.go b/internal/ui/service/auth/entries.go index db38725..74062ab 100644 --- a/internal/ui/service/auth/entries.go +++ b/internal/ui/service/auth/entries.go @@ -108,7 +108,7 @@ func NewRequest(auther cchat.Authenticator, done func()) *Request { continueBtn, _ := gtk.ButtonNewWithLabel("Continue") continueBtn.SetHAlign(gtk.ALIGN_CENTER) - continueBtn.Connect("clicked", done) + continueBtn.Connect("clicked", func(*gtk.Button) { done() }) continueBtn.SetBorderWidth(12) continueBtn.Show()