return obj;
}
+#define MZ_GRID_VIEW_PADDING_TOP 10
+#define MZ_GRID_VIEW_PADDING_BOTTOM 10
+#define MZ_GRID_VIEW_PADDING_LEFT 10
+#define MZ_GRID_VIEW_PADDING_RIGHT 10
+
void mz_files_view_snapshot(GtkWidget *widget, GtkSnapshot *snapshot) {
MzFilesView *view = (MzFilesView*)widget;
printf("MzFilesView snapshot\n");
view->current_width = width;
- int item_width = 80;
- int item_height = 120;
+ width -= MZ_GRID_VIEW_PADDING_LEFT + MZ_GRID_VIEW_PADDING_RIGHT;
+
+ int item_width = 170;
+ int item_height = 170;
int items_per_line = width / item_width;
GtkAllocation img_alloc;
GtkAllocation label_alloc;
- img_alloc.width = 64;
- img_alloc.height = 64;
- label_alloc.width = 76;
- label_alloc.height = 48;
+ img_alloc.width = 100;
+ img_alloc.height = 100;
+ label_alloc.width = 160;
+ label_alloc.height = 60;
+
+ int img_x_offset = (item_width - img_alloc.width) / 2;
+ int img_y_offset = (item_height - img_alloc.height - label_alloc.height) / 2;
+ int label_x_offset = (item_width - label_alloc.width) / 2;
int x = 0;
int y = 0;
for(size_t i=0;i<view->numitems;i++) {
- img_alloc.x = 20 + x * item_width;
- img_alloc.y = 20 + y * item_height;
+ img_alloc.x = MZ_GRID_VIEW_PADDING_LEFT + img_x_offset + x * item_width;
+ img_alloc.y = MZ_GRID_VIEW_PADDING_TOP + img_y_offset + y * item_height;
gtk_widget_size_allocate(view->items[i].image, &img_alloc, -1);
- label_alloc.x = img_alloc.x -1;
- label_alloc.y = img_alloc.y + 64 + 4;
+ label_alloc.x = MZ_GRID_VIEW_PADDING_LEFT + x * item_width + label_x_offset;
+ label_alloc.y = img_alloc.y + img_alloc.height;
gtk_widget_size_allocate(view->items[i].label, &label_alloc, -1);
+ PangoLayout *layout = gtk_label_get_layout(GTK_LABEL(view->items[i].label));
+ pango_layout_set_width(layout, 160 * PANGO_SCALE);
+ pango_layout_set_height(layout, 60 * PANGO_SCALE);
+ pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
+ pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_MIDDLE);
+ pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
+
x++;
if(x >= items_per_line) {
x = 0;
}
if(orientation == GTK_ORIENTATION_VERTICAL) {
- int item_width = 80;
- int item_height = 120;
- int items_per_line = view->current_width / item_width;
+ int item_width = 170;
+ int item_height = 170;
+ int items_per_line = (view->current_width - MZ_GRID_VIEW_PADDING_LEFT - MZ_GRID_VIEW_PADDING_RIGHT) / item_width;
int lines = view->numitems / items_per_line;
int r = lines*items_per_line < view->numitems ? 1 : 0;
int height = (lines+r) * item_height;
//printf("minimum height: %d\n", height);
- *minimum = height;
- *natural = height;
+ *minimum = height + MZ_GRID_VIEW_PADDING_TOP + MZ_GRID_VIEW_PADDING_BOTTOM;
+ *natural = height + MZ_GRID_VIEW_PADDING_TOP + MZ_GRID_VIEW_PADDING_BOTTOM;
}
}
GtkIconTheme *icontheme = gtk_icon_theme_get_for_display(gdk_display_get_default());
GtkIconPaintable *dir_icon = gtk_icon_theme_lookup_icon(icontheme, "folder", NULL, 64, 1, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_REGULAR);
- GtkIconPaintable *file_icon = gtk_icon_theme_lookup_icon(icontheme, "folder", NULL, 64, 1, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_REGULAR);
+ GtkIconPaintable *file_icon = gtk_icon_theme_lookup_icon(icontheme, "application-x-generic", NULL, 64, 1, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_REGULAR);
// create widgets
view->items = calloc(nchildren, sizeof(MzIconGadget));
MzIconGadget gadget;
gadget.image = gtk_image_new_from_paintable(GDK_PAINTABLE(S_ISDIR(finfo->mode) ? dir_icon : file_icon));
gadget.label = gtk_label_new(finfo->name);
+ gtk_label_set_yalign(GTK_LABEL(gadget.label), 0.0);
+ //gtk_widget_add_css_class(gadget.label, "ui_test");
gtk_widget_set_parent(gadget.image, GTK_WIDGET(view));
gtk_widget_set_parent(gadget.label, GTK_WIDGET(view));