From: Olaf Wintermann Date: Sat, 1 Feb 2025 21:28:45 +0000 (+0100) Subject: remove hardcoded MzFilesView item with/height and store it in the widget object X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=f3293f03f8034548bdcef78084f3c079cf117d2a;p=mizunara.git remove hardcoded MzFilesView item with/height and store it in the widget object --- diff --git a/mizunara/gtk-filesview.c b/mizunara/gtk-filesview.c index a2e56b2..d35c3e3 100644 --- a/mizunara/gtk-filesview.c +++ b/mizunara/gtk-filesview.c @@ -93,10 +93,15 @@ static void mz_files_view_init(MzFilesView *self) { self->numitems = 0; self->current_width = 0; + self->current_items_per_line = 0; self->highlight = FALSE; self->highlight_col = -1; self->highlight_row = -1; + + // default item size + self->item_width = 180; + self->item_height = 170; // event handler GtkDragSource *dnd_source = gtk_drag_source_new(); @@ -141,8 +146,8 @@ static int point2item(MzFilesView *view, int x, int y, int *out_col, int *out_ro int width = view->current_width; width -= MZ_GRID_VIEW_PADDING_LEFT + MZ_GRID_VIEW_PADDING_RIGHT; - int item_width = 180; - int item_height = 170; + int item_width = view->item_width; + int item_height = view->item_height; int items_per_line = width / item_width; @@ -187,7 +192,6 @@ void mz_files_view_snapshot(GtkWidget *widget, GtkSnapshot *snapshot) { //printf("MzFilesView snapshot\n"); int width = gtk_widget_get_width(widget); - int height = gtk_widget_get_height(widget); //printf("wh: %d x %d\n", width, height); view->current_width = width; @@ -207,10 +211,11 @@ void mz_files_view_snapshot(GtkWidget *widget, GtkSnapshot *snapshot) { drag_h = -drag_h; } - int item_width = 180; - int item_height = 170; + int item_width = view->item_width; + int item_height = view->item_height; int items_per_line = width / item_width; + view->current_items_per_line = items_per_line; int highlight_col_start = view->drag_start_col; int highlight_row_start = view->drag_start_row; @@ -419,8 +424,8 @@ void mz_files_view_measure(GtkWidget *widget, } if(orientation == GTK_ORIENTATION_VERTICAL) { - int item_width = 180; - int item_height = 170; + int item_width = view->item_width; + int item_height = view->item_height; 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; @@ -491,8 +496,8 @@ static void drag_begin_cb( printf("drag_begin_cb: %f\n", start_x); // update selection - int item_width = 180; - int item_height = 170; + int item_width = view->item_width; + int item_height = view->item_height; int update_selection = 0; int col = -1; @@ -569,8 +574,8 @@ static void drag_update_cb( // update selection - int item_width = 180; - int item_height = 170; + int item_width = view->item_width; + int item_height = view->item_height; int col; if(view->drag_start_x + x <= MZ_GRID_VIEW_PADDING_LEFT) { diff --git a/mizunara/gtk-filesview.h b/mizunara/gtk-filesview.h index c8c55da..953eef0 100644 --- a/mizunara/gtk-filesview.h +++ b/mizunara/gtk-filesview.h @@ -65,7 +65,11 @@ typedef struct MzFilesView { FileInfo *drag_file; + int item_width; + int item_height; + int current_width; + int current_items_per_line; MzViewSection *sections; size_t numsections;