Skip to content

Commit

Permalink
[Gtk] Correctly draw image cells aligned to their x/y ratio.
Browse files Browse the repository at this point in the history
Previously, the code would just draw at the top of the cell_area which is wrong if the image being drawn is smaller than said area.
  • Loading branch information
garuma committed Jan 6, 2016
1 parent a6c8b12 commit a416492
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererImage.cs
Expand Up @@ -68,7 +68,9 @@ protected override void OnRender (Cairo.Context cr, Gtk.Widget widget, Gdk.Recta
if (image.IsNull)
return;
var pix = ((GtkImage)image.Backend);
pix.Draw (Context, cr, Util.GetScaleFactor (widget), cell_area.X, cell_area.Y, image);
int x_offset, y_offset, width, height;
GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height);
pix.Draw (Context, cr, Util.GetScaleFactor (widget), cell_area.X + x_offset, cell_area.Y + y_offset, image);

}

Expand All @@ -80,7 +82,11 @@ protected override void OnGetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_are
width = (int) image.Size.Width;
height = (int) image.Size.Height;
}
x_offset = y_offset = 0;
if (!cell_area.IsEmpty && width > 0 && height > 0) {
x_offset = (int)Math.Max (0, Xalign * (cell_area.Width - width));
y_offset = (int)Math.Max (0, Yalign * (cell_area.Height - height));
} else
x_offset = y_offset = 0;
}
}
}

0 comments on commit a416492

Please sign in to comment.