slight tweaks for hidpi
This commit is contained in:
parent
61550351a3
commit
3221c18658
2
go.mod
2
go.mod
|
@ -14,7 +14,7 @@ require (
|
||||||
github.com/Xuanwo/go-locale v1.0.0
|
github.com/Xuanwo/go-locale v1.0.0
|
||||||
github.com/alecthomas/chroma v0.7.3
|
github.com/alecthomas/chroma v0.7.3
|
||||||
github.com/diamondburned/cchat v0.3.15
|
github.com/diamondburned/cchat v0.3.15
|
||||||
github.com/diamondburned/cchat-discord v0.0.0-20201220054426-918719599f2d
|
github.com/diamondburned/cchat-discord v0.0.0-20201220081640-288591a535af
|
||||||
github.com/diamondburned/cchat-mock v0.0.0-20201115033644-df8d1b10f9db
|
github.com/diamondburned/cchat-mock v0.0.0-20201115033644-df8d1b10f9db
|
||||||
github.com/diamondburned/gspell v0.0.0-20200830182722-77e5d27d6894
|
github.com/diamondburned/gspell v0.0.0-20200830182722-77e5d27d6894
|
||||||
github.com/diamondburned/handy v0.0.0-20200829011954-4667e7a918f4
|
github.com/diamondburned/handy v0.0.0-20200829011954-4667e7a918f4
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -58,6 +58,8 @@ github.com/diamondburned/cchat v0.3.15 h1:BJf8ZiRtDWTGMtQ3QqjNU0H+784WSrkJEpFGkK
|
||||||
github.com/diamondburned/cchat v0.3.15/go.mod h1:IlMtF+XIvAJh0GL/2yFdf0/34w+Hdy5A1GgvSwAXtQI=
|
github.com/diamondburned/cchat v0.3.15/go.mod h1:IlMtF+XIvAJh0GL/2yFdf0/34w+Hdy5A1GgvSwAXtQI=
|
||||||
github.com/diamondburned/cchat-discord v0.0.0-20201220054426-918719599f2d h1:n61DxLdX7nPj7KA1N/azaR8wa0pnDBDT6Yi1seOsBWM=
|
github.com/diamondburned/cchat-discord v0.0.0-20201220054426-918719599f2d h1:n61DxLdX7nPj7KA1N/azaR8wa0pnDBDT6Yi1seOsBWM=
|
||||||
github.com/diamondburned/cchat-discord v0.0.0-20201220054426-918719599f2d/go.mod h1:pvp1TOHK7NUM+GDRPixQGsKyCSbGYhiseK2jM+1I+ms=
|
github.com/diamondburned/cchat-discord v0.0.0-20201220054426-918719599f2d/go.mod h1:pvp1TOHK7NUM+GDRPixQGsKyCSbGYhiseK2jM+1I+ms=
|
||||||
|
github.com/diamondburned/cchat-discord v0.0.0-20201220081640-288591a535af h1:pTdxsrVSYCdraGormbu1t8uQJMe/OD/ZIz9KljDWAvc=
|
||||||
|
github.com/diamondburned/cchat-discord v0.0.0-20201220081640-288591a535af/go.mod h1:pvp1TOHK7NUM+GDRPixQGsKyCSbGYhiseK2jM+1I+ms=
|
||||||
github.com/diamondburned/cchat-mock v0.0.0-20201115033644-df8d1b10f9db h1:VQI2PdbsdsRJ7d669kp35GbCUO44KZ0Xfqdu4o/oqVg=
|
github.com/diamondburned/cchat-mock v0.0.0-20201115033644-df8d1b10f9db h1:VQI2PdbsdsRJ7d669kp35GbCUO44KZ0Xfqdu4o/oqVg=
|
||||||
github.com/diamondburned/cchat-mock v0.0.0-20201115033644-df8d1b10f9db/go.mod h1:M87kjNzWVPlkZycFNzpGPKQXzkHNnZphuwMf3E9ckgc=
|
github.com/diamondburned/cchat-mock v0.0.0-20201115033644-df8d1b10f9db/go.mod h1:M87kjNzWVPlkZycFNzpGPKQXzkHNnZphuwMf3E9ckgc=
|
||||||
github.com/diamondburned/gotk3 v0.0.0-20201209182406-e7291341a091 h1:lQpSWzbi3rQf66aMSip/rIypasIFwqCqF0Wfn5og6gw=
|
github.com/diamondburned/gotk3 v0.0.0-20201209182406-e7291341a091 h1:lQpSWzbi3rQf66aMSip/rIypasIFwqCqF0Wfn5og6gw=
|
||||||
|
|
|
@ -23,20 +23,28 @@ type ImageContainer interface {
|
||||||
|
|
||||||
type ImageContainerSizer interface {
|
type ImageContainerSizer interface {
|
||||||
ImageContainer
|
ImageContainer
|
||||||
|
GetSizeRequest() (w, h int)
|
||||||
SetSizeRequest(w, h int)
|
SetSizeRequest(w, h int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type dummySizer struct {
|
||||||
|
ImageContainer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dummySizer) GetSizeRequest() (int, int) { return -1, -1 }
|
||||||
|
func (dummySizer) SetSizeRequest(int, int) {}
|
||||||
|
|
||||||
// AsyncImage loads an image. This method uses the cache.
|
// AsyncImage loads an image. This method uses the cache.
|
||||||
func AsyncImage(img ImageContainer, url string, procs ...imgutil.Processor) {
|
func AsyncImage(img ImageContainer, url string, procs ...imgutil.Processor) {
|
||||||
asyncImage(img, url, 0, 0, procs)
|
asyncImage(dummySizer{img}, url, procs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsyncImageSized resizes using GdkPixbuf. This method uses the cache.
|
// AsyncImageSized resizes using GdkPixbuf. This method uses the cache.
|
||||||
func AsyncImageSized(img ImageContainerSizer, url string, w, h int, procs ...imgutil.Processor) {
|
func AsyncImageSized(img ImageContainerSizer, url string, procs ...imgutil.Processor) {
|
||||||
asyncImage(img, url, w, h, procs)
|
asyncImage(img, url, procs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func asyncImage(img ImageContainer, url string, w, h int, procs []imgutil.Processor) {
|
func asyncImage(img ImageContainerSizer, url string, procs []imgutil.Processor) {
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -55,14 +63,12 @@ func asyncImage(img ImageContainer, url string, w, h int, procs []imgutil.Proces
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if w > 0 && h > 0 {
|
if w, h := img.GetSizeRequest(); w > 0 && h > 0 {
|
||||||
l.Connect("size-prepared", func(l *gdk.PixbufLoader, imgW, imgH int) {
|
l.Connect("size-prepared", func(l *gdk.PixbufLoader, imgW, imgH int) {
|
||||||
w, h = imgutil.MaxSize(imgW, imgH, w, h)
|
w, h = imgutil.MaxSize(imgW, imgH, w, h)
|
||||||
if w != imgW || h != imgH {
|
if w != imgW || h != imgH {
|
||||||
l.SetSize(w, h)
|
l.SetSize(w, h)
|
||||||
execIfCtx(ctx, func() {
|
execIfCtx(ctx, func() { img.SetSizeRequest(w, h) })
|
||||||
img.(ImageContainerSizer).SetSizeRequest(w, h)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -73,7 +79,7 @@ func asyncImage(img ImageContainer, url string, w, h int, procs []imgutil.Proces
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectDestroyer(img ImageContainer, cancel func()) {
|
func connectDestroyer(img ImageContainer, cancel func()) {
|
||||||
img.Connect("destroy", func(img ImageContainer) {
|
img.Connect("destroy", func() {
|
||||||
cancel()
|
cancel()
|
||||||
img.SetFromPixbuf(nil)
|
img.SetFromPixbuf(nil)
|
||||||
})
|
})
|
||||||
|
|
|
@ -195,8 +195,8 @@ func NewAvatar() *Avatar {
|
||||||
img.Show()
|
img.Show()
|
||||||
|
|
||||||
avatar, _ := roundimage.NewCustomButton(img)
|
avatar, _ := roundimage.NewCustomButton(img)
|
||||||
avatar.SetSizeRequest(AvatarSize, AvatarSize)
|
|
||||||
avatar.SetVAlign(gtk.ALIGN_START)
|
avatar.SetVAlign(gtk.ALIGN_START)
|
||||||
|
avatar.Image.SetSizeRequest(AvatarSize, AvatarSize)
|
||||||
|
|
||||||
// Default icon.
|
// Default icon.
|
||||||
primitives.SetImageIcon(img, "user-available-symbolic", AvatarSize)
|
primitives.SetImageIcon(img, "user-available-symbolic", AvatarSize)
|
||||||
|
@ -215,7 +215,7 @@ func (a *Avatar) SetURL(url string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
a.url = url
|
a.url = url
|
||||||
httputil.AsyncImageSized(a.Image, url, AvatarSize, AvatarSize)
|
httputil.AsyncImageSized(a.Image, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManuallySetURL sets the URL without downloading the image. It assumes the
|
// ManuallySetURL sets the URL without downloading the image. It assumes the
|
||||||
|
|
|
@ -58,7 +58,7 @@ func New(ctrl Controller) *Container {
|
||||||
sw.Show()
|
sw.Show()
|
||||||
|
|
||||||
rev, _ := gtk.RevealerNew()
|
rev, _ := gtk.RevealerNew()
|
||||||
rev.SetTransitionType(gtk.REVEALER_TRANSITION_TYPE_SLIDE_RIGHT)
|
rev.SetTransitionType(gtk.REVEALER_TRANSITION_TYPE_SLIDE_LEFT)
|
||||||
rev.SetTransitionDuration(75)
|
rev.SetTransitionDuration(75)
|
||||||
rev.SetRevealChild(false)
|
rev.SetRevealChild(false)
|
||||||
rev.Add(sw)
|
rev.Add(sw)
|
||||||
|
|
|
@ -234,7 +234,7 @@ func (c *Completer) update() []gtk.IWidget {
|
||||||
pps = ppIcon
|
pps = ppIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
httputil.AsyncImageSized(img, entry.IconURL, size, size, pps...)
|
httputil.AsyncImageSized(img, entry.IconURL, pps...)
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets[i] = b
|
widgets[i] = b
|
||||||
|
|
|
@ -112,6 +112,7 @@ func NewImageIconPx(icon string, sizepx int) *gtk.Image {
|
||||||
|
|
||||||
type ImageIconSetter interface {
|
type ImageIconSetter interface {
|
||||||
SetProperty(name string, value interface{}) error
|
SetProperty(name string, value interface{}) error
|
||||||
|
GetSizeRequest() (w, h int)
|
||||||
SetSizeRequest(w, h int)
|
SetSizeRequest(w, h int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,11 @@ func TrySetText(imager Imager, text string) {
|
||||||
type Avatar struct {
|
type Avatar struct {
|
||||||
handy.Avatar
|
handy.Avatar
|
||||||
pixbuf *gdk.Pixbuf
|
pixbuf *gdk.Pixbuf
|
||||||
|
size int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a better API that allows scaling.
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ Imager = (*Avatar)(nil)
|
_ Imager = (*Avatar)(nil)
|
||||||
_ TextSetter = (*Avatar)(nil)
|
_ TextSetter = (*Avatar)(nil)
|
||||||
|
@ -33,12 +36,18 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewAvatar(size int) *Avatar {
|
func NewAvatar(size int) *Avatar {
|
||||||
a := handy.AvatarNew(size, "", true)
|
avatar := Avatar{
|
||||||
if a == nil {
|
Avatar: *handy.AvatarNew(size, "", true),
|
||||||
return nil
|
size: size,
|
||||||
|
}
|
||||||
|
// Set the load function. This should hopefully trigger a reload.
|
||||||
|
avatar.SetImageLoadFunc(avatar.loadFunc)
|
||||||
|
|
||||||
|
return &avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Avatar{*a, nil}
|
func (a *Avatar) GetSizeRequest() (int, int) {
|
||||||
|
return a.size, a.size
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSizeRequest sets the avatar size. The actual size is min(w, h).
|
// SetSizeRequest sets the avatar size. The actual size is min(w, h).
|
||||||
|
@ -52,7 +61,23 @@ func (a *Avatar) SetSizeRequest(w, h int) {
|
||||||
a.Avatar.SetSizeRequest(w, h)
|
a.Avatar.SetSizeRequest(w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Avatar) loadFunc(int) *gdk.Pixbuf {
|
func (a *Avatar) loadFunc(size int) *gdk.Pixbuf {
|
||||||
|
if a.pixbuf == nil {
|
||||||
|
a.size = size
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.size != size {
|
||||||
|
a.size = size
|
||||||
|
|
||||||
|
p, err := a.pixbuf.ScaleSimple(size, size, gdk.INTERP_HYPER)
|
||||||
|
if err != nil {
|
||||||
|
return a.pixbuf
|
||||||
|
}
|
||||||
|
|
||||||
|
a.pixbuf = p
|
||||||
|
}
|
||||||
|
|
||||||
return a.pixbuf
|
return a.pixbuf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ type Icon struct {
|
||||||
*gtk.Revealer
|
*gtk.Revealer
|
||||||
Image RoundIconContainer
|
Image RoundIconContainer
|
||||||
procs []imgutil.Processor
|
procs []imgutil.Processor
|
||||||
size int
|
|
||||||
|
|
||||||
r *Reusable
|
r *Reusable
|
||||||
|
|
||||||
|
@ -93,10 +92,6 @@ func (i *Icon) URL() string {
|
||||||
return i.url
|
return i.url
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Icon) Size() int {
|
|
||||||
return i.size
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Icon) CopyPixbuf(dst httputil.ImageContainer) {
|
func (i *Icon) CopyPixbuf(dst httputil.ImageContainer) {
|
||||||
switch i.Image.GetStorageType() {
|
switch i.Image.GetStorageType() {
|
||||||
case gtk.IMAGE_PIXBUF:
|
case gtk.IMAGE_PIXBUF:
|
||||||
|
@ -120,10 +115,18 @@ func (i *Icon) SetPlaceholderIcon(iconName string, iconSzPx int) {
|
||||||
|
|
||||||
// SetSize is not thread-safe.
|
// SetSize is not thread-safe.
|
||||||
func (i *Icon) SetSize(szpx int) {
|
func (i *Icon) SetSize(szpx int) {
|
||||||
i.size = szpx
|
|
||||||
i.Image.SetSizeRequest(szpx, szpx)
|
i.Image.SetSizeRequest(szpx, szpx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns the minimum of the image size. It is not thread-safe.
|
||||||
|
func (i *Icon) Size() int {
|
||||||
|
w, h := i.Image.GetSizeRequest()
|
||||||
|
if h < w {
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
// AddProcessors is not thread-safe.
|
// AddProcessors is not thread-safe.
|
||||||
func (i *Icon) AddProcessors(procs ...imgutil.Processor) {
|
func (i *Icon) AddProcessors(procs ...imgutil.Processor) {
|
||||||
i.procs = append(i.procs, procs...)
|
i.procs = append(i.procs, procs...)
|
||||||
|
@ -154,7 +157,7 @@ func (i *Icon) SetIconUnsafe(url string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Icon) updateAsync() {
|
func (i *Icon) updateAsync() {
|
||||||
httputil.AsyncImageSized(i.Image, i.url, i.size, i.size, i.procs...)
|
httputil.AsyncImageSized(i.Image, i.url, i.procs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventIcon struct {
|
type EventIcon struct {
|
||||||
|
|
|
@ -211,7 +211,7 @@ func popoverImg(url string, round bool) gtk.IWidget {
|
||||||
img.SetHAlign(gtk.ALIGN_CENTER)
|
img.SetHAlign(gtk.ALIGN_CENTER)
|
||||||
img.Show()
|
img.Show()
|
||||||
|
|
||||||
httputil.AsyncImageSized(idl, url, AvatarSize, AvatarSize)
|
httputil.AsyncImageSized(idl, url)
|
||||||
|
|
||||||
btn.SetHAlign(gtk.ALIGN_CENTER)
|
btn.SetHAlign(gtk.ALIGN_CENTER)
|
||||||
btn.SetRelief(gtk.RELIEF_NONE)
|
btn.SetRelief(gtk.RELIEF_NONE)
|
||||||
|
@ -263,11 +263,12 @@ func bind(connector WidgetConnector, activator func(uri string, r gdk.Rectangle)
|
||||||
img = r.Image
|
img = r.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img.SetSizeRequest(w, h)
|
||||||
img.SetFromIconName("image-loading", gtk.ICON_SIZE_BUTTON)
|
img.SetFromIconName("image-loading", gtk.ICON_SIZE_BUTTON)
|
||||||
img.Show()
|
img.Show()
|
||||||
|
|
||||||
// Asynchronously fetch the image.
|
// Asynchronously fetch the image.
|
||||||
httputil.AsyncImageSized(img, uri, w, h)
|
httputil.AsyncImageSized(img, uri)
|
||||||
|
|
||||||
btn, _ := gtk.ButtonNew()
|
btn, _ := gtk.ButtonNew()
|
||||||
btn.Add(img)
|
btn.Add(img)
|
||||||
|
|
Loading…
Reference in New Issue