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