Fix uncolored names for light theme

This commit is contained in:
diamondburned 2021-05-11 18:36:37 -07:00
parent d8f68cb852
commit 52655c2859
5 changed files with 37 additions and 21 deletions

View File

@ -48,6 +48,10 @@ type Message struct {
var _ container.MessageRow = (*Message)(nil)
var renderCfg = markup.RenderConfig{
NoReferencing: true,
}
func WrapMessage(ct *message.State) Message {
ts := message.NewTimestamp()
ts.SetVAlign(gtk.ALIGN_START)
@ -74,12 +78,8 @@ func WrapMessage(ct *message.State) Message {
ct.PackStart(ct.Content, true, true, 0)
ct.SetClass("compact")
rcfg := markup.RenderConfig{}
rcfg.NoReferencing = true
rcfg.SetForegroundAnchor(ct.ContentBodyStyle)
user.SetRenderer(func(rich text.Rich) markup.RenderOutput {
return markup.RenderCmplxWithConfig(rich, rcfg)
return markup.RenderCmplxWithConfig(rich, renderCfg)
})
return Message{

View File

@ -54,6 +54,10 @@ func NewFullMessage(msg cchat.MessageCreate) *FullMessage {
return WrapFullMessage(message.NewState(msg))
}
var renderCfg = markup.RenderConfig{
NoReferencing: true,
}
func WrapFullMessage(gc *message.State) *FullMessage {
header := labeluri.NewLabel(text.Rich{})
header.SetHAlign(gtk.ALIGN_START) // left-align
@ -103,12 +107,8 @@ func WrapFullMessage(gc *message.State) *FullMessage {
unwrap: func() { removeUpdate() },
}
cfg := markup.RenderConfig{}
cfg.NoReferencing = true
cfg.SetForegroundAnchor(gc.ContentBodyStyle)
header.SetRenderer(func(rich text.Rich) markup.RenderOutput {
output := markup.RenderCmplxWithConfig(rich, cfg)
output := markup.RenderCmplxWithConfig(rich, renderCfg)
output.Markup = `<span font_weight="600">` + output.Markup + "</span>"
output.Markup += msg.timestamp

View File

@ -46,7 +46,7 @@ func (m *MenuButton) Bind(menu *Menu) {
// menu items.
m.SetSensitive(model.GetNItems() > 0)
// Subscribe the button to menu update events.
m.lastsig = model.Connect("items-changed", func(model *glib.MenuModel) {
m.lastsig = model.Connect("items-changed", func() {
m.SetSensitive(model.GetNItems() > 0)
})
} else {

View File

@ -4,11 +4,13 @@ import (
"bytes"
"fmt"
"html"
"log"
"net/url"
"sort"
"strconv"
"strings"
"github.com/diamondburned/cchat-gtk/internal/gts"
"github.com/diamondburned/cchat-gtk/internal/ui/rich/parser/attrmap"
"github.com/diamondburned/cchat-gtk/internal/ui/rich/parser/hl"
"github.com/diamondburned/cchat/text"
@ -136,13 +138,10 @@ type RenderConfig struct {
}
}
// SetForegroundAnchor sets the AnchorColor of the render config to be that of
// setForegroundAnchor sets the AnchorColor of the render config to be that of
// the regular text foreground color.
func (c *RenderConfig) SetForegroundAnchor(ctx *gtk.StyleContext) {
rgba := ctx.GetColor(gtk.STATE_FLAG_NORMAL)
if rgba == nil {
return
}
func (c *RenderConfig) setForegroundAnchor(ctx *gtk.StyleContext) {
rgba := ctx.GetColor(gtk.STATE_FLAG_ACTIVE)
var color uint32
for _, v := range rgba.Floats() { // [0.0, 1.0]
@ -153,6 +152,21 @@ func (c *RenderConfig) SetForegroundAnchor(ctx *gtk.StyleContext) {
c.AnchorColor.uint32 = text.SolidColor(color) // force alpha 100%
}
// ensureAnchorColor ensures the RenderConfig has an AnchorColor.
func (c *RenderConfig) ensureAnchorColor() {
if c.AnchorColor.bool {
return
}
styleCtx, _ := gts.App.Window.GetStyleContext()
if styleCtx == nil {
log.Println("Window's StyleCtx is nil.")
return
}
c.setForegroundAnchor(styleCtx)
}
func RenderCmplxWithConfig(content text.Rich, cfg RenderConfig) RenderOutput {
// Fast path.
if len(content.Segments) == 0 {
@ -232,7 +246,8 @@ func RenderCmplxWithConfig(content text.Rich, cfg RenderConfig) RenderOutput {
if colorer := segment.AsColorer(); colorer != nil {
appended.Span(start, end, colorAttrs(colorer.Color(), false)...)
} else if hasAnchor && cfg.AnchorColor.bool {
} else if hasAnchor {
cfg.ensureAnchorColor()
appended.Span(start, end, colorAttrs(cfg.AnchorColor.uint32, false)...)
}

View File

@ -135,16 +135,17 @@ func (s *Servers) SetList(slist cchat.Lister) {
}
func (s *Servers) load() {
// Return if we're loading.
if s.IsLoading() {
if s.Lister == nil || s.IsLoading() {
return
}
// Mark the servers list as loading.
s.setLoading()
lister := s.Lister
go func() {
stop, err := s.Lister.Servers(s)
stop, err := lister.Servers(s)
gts.ExecAsync(func() {
if err != nil {
s.setFailed(err)