From: Olaf Wintermann Date: Sat, 25 Jan 2025 10:58:05 +0000 (+0100) Subject: improve MzFilesView grid and text layout X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=4f25ca992c8a36031360b9ab5d42b55159bc2ee5;p=mizunara.git improve MzFilesView grid and text layout --- diff --git a/mizunara/gtk-filesview.c b/mizunara/gtk-filesview.c index 6a3afe5..ab0ee6b 100644 --- a/mizunara/gtk-filesview.c +++ b/mizunara/gtk-filesview.c @@ -87,6 +87,11 @@ MzFilesView* mz_files_view_new(void) { 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"); @@ -97,8 +102,10 @@ void mz_files_view_snapshot(GtkWidget *widget, GtkSnapshot *snapshot) { 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; @@ -108,21 +115,32 @@ void mz_files_view_snapshot(GtkWidget *widget, GtkSnapshot *snapshot) { 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;inumitems;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; @@ -153,9 +171,9 @@ void mz_files_view_measure(GtkWidget *widget, } 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; @@ -164,8 +182,8 @@ void mz_files_view_measure(GtkWidget *widget, 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; } } @@ -237,7 +255,7 @@ void mz_update_files_view(MzFilesView *view, FilesSection *sections, size_t nums 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)); @@ -251,6 +269,8 @@ void mz_update_files_view(MzFilesView *view, FilesSection *sections, size_t nums 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)); diff --git a/mizunara/window.c b/mizunara/window.c index d7fd02a..3b41a00 100644 --- a/mizunara/window.c +++ b/mizunara/window.c @@ -54,6 +54,7 @@ void window_update_gridview( UiObject* window_create(const char *url) { // toplevel window object UiObject *obj = ui_sidebar_window("Mizunara", NULL); + ui_window_size(obj, 1000, 600); // create window data object MainWindow *wdata = ui_malloc(obj->ctx, sizeof(MainWindow));