mirror of
https://github.com/diamondburned/cchat-gtk.git
synced 2025-01-03 09:36:50 +00:00
fixed oversized image in hidpi
This commit is contained in:
parent
3221c18658
commit
296346bbe7
|
@ -18,33 +18,21 @@ import (
|
|||
type ImageContainer interface {
|
||||
SetFromPixbuf(*gdk.Pixbuf)
|
||||
SetFromAnimation(*gdk.PixbufAnimation)
|
||||
GetSizeRequest() (w, h int)
|
||||
Connect(string, interface{}, ...interface{}) (glib.SignalHandle, error)
|
||||
}
|
||||
|
||||
type ImageContainerSizer interface {
|
||||
ImageContainer
|
||||
GetSizeRequest() (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.
|
||||
func AsyncImage(img ImageContainer, url string, procs ...imgutil.Processor) {
|
||||
asyncImage(dummySizer{img}, url, procs)
|
||||
}
|
||||
|
||||
// AsyncImageSized resizes using GdkPixbuf. This method uses the cache.
|
||||
func AsyncImageSized(img ImageContainerSizer, url string, procs ...imgutil.Processor) {
|
||||
asyncImage(img, url, procs)
|
||||
}
|
||||
|
||||
func asyncImage(img ImageContainerSizer, url string, procs []imgutil.Processor) {
|
||||
// AsyncImageSized resizes using GdkPixbuf. This method uses the cache.
|
||||
func AsyncImageSized(img ImageContainer, url string, procs ...imgutil.Processor) {
|
||||
asyncImage(img, url, procs)
|
||||
}
|
||||
|
||||
func asyncImage(img ImageContainer, url string, procs []imgutil.Processor) {
|
||||
if url == "" {
|
||||
return
|
||||
}
|
||||
|
@ -68,7 +56,6 @@ func asyncImage(img ImageContainerSizer, url string, procs []imgutil.Processor)
|
|||
w, h = imgutil.MaxSize(imgW, imgH, w, h)
|
||||
if w != imgW || h != imgH {
|
||||
l.SetSize(w, h)
|
||||
execIfCtx(ctx, func() { img.SetSizeRequest(w, h) })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -23,25 +23,25 @@ func NewButton() (*Button, error) {
|
|||
image, _ := NewImage(0)
|
||||
image.Show()
|
||||
|
||||
b, _ := NewEmptyButton()
|
||||
b := NewEmptyButton()
|
||||
b.SetImage(image)
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func NewEmptyButton() (*Button, error) {
|
||||
func NewEmptyButton() *Button {
|
||||
b, _ := gtk.ButtonNew()
|
||||
b.SetRelief(gtk.RELIEF_NONE)
|
||||
roundButtonCSS(b)
|
||||
|
||||
return &Button{Button: b}, nil
|
||||
return &Button{Button: b}
|
||||
}
|
||||
|
||||
// NewCustomButton creates a new rounded button with the given Imager. If the
|
||||
// given Imager implements the Connector interface (aka *StaticImage), then the
|
||||
// function will implicitly connect its handlers to the button.
|
||||
func NewCustomButton(img Imager) (*Button, error) {
|
||||
b, _ := NewEmptyButton()
|
||||
b := NewEmptyButton()
|
||||
b.SetImage(img)
|
||||
|
||||
if connector, ok := img.(Connector); ok {
|
||||
|
|
|
@ -26,9 +26,10 @@ type Connector interface {
|
|||
type Imager interface {
|
||||
gtk.IWidget
|
||||
RadiusSetter
|
||||
SetSizeRequest(w, h int)
|
||||
|
||||
// Embed setters.
|
||||
httputil.ImageContainerSizer
|
||||
httputil.ImageContainer
|
||||
|
||||
GetPixbuf() *gdk.Pixbuf
|
||||
GetAnimation() *gdk.PixbufAnimation
|
||||
|
|
|
@ -193,7 +193,7 @@ func largeText(text string) string {
|
|||
func popoverImg(url string, round bool) gtk.IWidget {
|
||||
var btn *gtk.Button
|
||||
var img *gtk.Image
|
||||
var idl httputil.ImageContainerSizer
|
||||
var idl httputil.ImageContainer
|
||||
|
||||
if round {
|
||||
b, _ := roundimage.NewButton()
|
||||
|
|
Loading…
Reference in a new issue