Fixed the shrinking not working: the Cairo clip rect apparently can fall outside the actual size of the widget. (I did notice this before.)
This commit is contained in:
parent
cd49e05da8
commit
bbccf96981
|
@ -45,11 +45,18 @@ func gtkAreaGetControl(scrollarea *gtkWidget) *gtkWidget {
|
|||
//export our_area_draw_callback
|
||||
func our_area_draw_callback(widget *C.GtkWidget, cr *C.cairo_t, data C.gpointer) C.gboolean {
|
||||
var x, y, w, h C.double
|
||||
var maxwid, maxht C.gint
|
||||
|
||||
s := (*sysData)(unsafe.Pointer(data))
|
||||
// thanks to desrt in irc.gimp.net/#gtk+
|
||||
C.cairo_clip_extents(cr, &x, &y, &w, &h)
|
||||
cliprect := image.Rect(int(x), int(y), int(w), int(h))
|
||||
// the cliprect can actually fall outside the size of the Area; clip it by intersecting the two rectangles
|
||||
C.gtk_widget_get_size_request(widget, &maxwid, &maxht)
|
||||
cliprect = image.Rect(0, 0, int(maxwid), int(maxht)).Intersect(cliprect)
|
||||
if cliprect.Empty() { // no intersection; nothing to paint
|
||||
return C.FALSE // signals handled without stopping the event chain (thanks to desrt again)
|
||||
}
|
||||
i := s.handler.Paint(cliprect)
|
||||
// pixel order is [R G B A] (see Example 1 on https://developer.gnome.org/gdk-pixbuf/2.26/gdk-pixbuf-The-GdkPixbuf-Structure.html) so we don't have to convert anything
|
||||
// gdk-pixbuf is not alpha-premultiplied (thanks to desrt in irc.gimp.net/#gtk+)
|
||||
|
|
|
@ -217,7 +217,3 @@ func gtk_progress_bar_set_fraction(w *gtkWidget, percent int) {
|
|||
func gtk_progress_bar_pulse(w *gtkWidget) {
|
||||
C.gtk_progress_bar_pulse(togtkprogressbar(w))
|
||||
}
|
||||
|
||||
func gtk_widget_queue_draw(widget *gtkWidget) {
|
||||
C.gtk_widget_queue_draw(togtkwidget(widget))
|
||||
}
|
||||
|
|
|
@ -357,7 +357,6 @@ func (s *sysData) setAreaSize(width int, height int) {
|
|||
uitask <- func() {
|
||||
c := gtkAreaGetControl(s.widget)
|
||||
gtk_widget_set_size_request(c, width, height)
|
||||
gtk_widget_queue_draw(c) // force repaint (TODO doesn't have an effect when shrinking?)
|
||||
ret <- struct{}{}
|
||||
}
|
||||
<-ret
|
||||
|
|
|
@ -194,7 +194,6 @@ func areaTest() {
|
|||
if err != nil { println(err); continue }
|
||||
height, err := strconv.Atoi(heightbox.Text())
|
||||
if err != nil { println(err); continue }
|
||||
println(width, height)
|
||||
a.SetSize(width, height)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue