]> uap-core.de Git - mizunara.git/commitdiff
remove hardcoded MzFilesView item with/height and store it in the widget object
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 1 Feb 2025 21:28:45 +0000 (22:28 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 1 Feb 2025 21:28:45 +0000 (22:28 +0100)
mizunara/gtk-filesview.c
mizunara/gtk-filesview.h

index a2e56b23d6c7c9bec3a1f31ed55f3f4e51b7ce27..d35c3e302c759f27b3d7b2e611eb7a543b941c7b 100644 (file)
@@ -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) {
index c8c55dacc917758eb725dea1283f3885e42d08d5..953eef002330de4d01c34746bb6646e7a653ffd7 100644 (file)
@@ -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;