ui/gtk/list.c

changeset 855
37f8a9fa8251
parent 853
380ec881faa2
child 856
b769e01035a7
equal deleted inserted replaced
854:9291921f21c5 855:37f8a9fa8251
2393 button, 2393 button,
2394 "clicked", 2394 "clicked",
2395 G_CALLBACK(listbox_button_clicked), 2395 G_CALLBACK(listbox_button_clicked),
2396 event 2396 event
2397 ); 2397 );
2398 gtk_widget_set_visible(button, FALSE);
2399
2400 g_object_set_data(G_OBJECT(row), "ui-listbox-row-button", button);
2398 } 2401 }
2399 } 2402 }
2400 2403
2401 static void update_sublist_item(UiListBox *listbox, UiListBoxSubList *sublist, int index) { 2404 static void update_sublist_item(UiListBox *listbox, UiListBoxSubList *sublist, int index) {
2402 int header_row = listbox->header_is_item && sublist->header ? 1 : 0; 2405 int header_row = listbox->header_is_item && sublist->header ? 1 : 0;
2427 free(item.button_label); 2430 free(item.button_label);
2428 free(item.button_icon); 2431 free(item.button_icon);
2429 free(item.badge); 2432 free(item.badge);
2430 } 2433 }
2431 2434
2435 static void listbox_row_on_enter(GtkWidget *row) {
2436 GtkWidget *button = g_object_get_data(G_OBJECT(row), "ui-listbox-row-button");
2437 if(button) {
2438 gtk_widget_set_visible(button, TRUE);
2439 }
2440 }
2441
2442 static void listbox_row_on_leave(GtkWidget *row) {
2443 GtkWidget *button = g_object_get_data(G_OBJECT(row), "ui-listbox-row-button");
2444 if(button) {
2445 gtk_widget_set_visible(button, FALSE);
2446 }
2447 }
2448
2449 #if GTK_CHECK_VERSION(4, 0, 0)
2450 static void listbox_row_enter(
2451 GtkEventControllerMotion* self,
2452 gdouble x,
2453 gdouble y,
2454 GtkWidget *row)
2455 {
2456 listbox_row_on_enter(row);
2457 }
2458
2459 static void listbox_row_leave(
2460 GtkEventControllerMotion* self,
2461 GtkWidget *row)
2462 {
2463 listbox_row_on_leave(row);
2464 }
2465 #else
2466 static gboolean listbox_row_enter(
2467 GtkWidget *row,
2468 GdkEventCrossing event,
2469 gpointer user_data)
2470 {
2471 listbox_row_on_enter(row);
2472 return FALSE;
2473 }
2474
2475
2476 static gboolean listbox_row_leave(
2477 GtkWidget *row,
2478 GdkEventCrossing *event,
2479 gpointer user_data)
2480 {
2481 listbox_row_on_leave(row);
2482 return FALSE;
2483 }
2484
2485 #endif
2486
2432 void ui_listbox_update_sublist(UiListBox *listbox, UiListBoxSubList *sublist, size_t listbox_insert_index) { 2487 void ui_listbox_update_sublist(UiListBox *listbox, UiListBoxSubList *sublist, size_t listbox_insert_index) {
2433 // clear sublist 2488 // clear sublist
2434 CxIterator r = cxListIterator(sublist->widgets); 2489 CxIterator r = cxListIterator(sublist->widgets);
2435 cx_foreach(GtkWidget*, widget, r) { 2490 cx_foreach(GtkWidget*, widget, r) {
2436 LISTBOX_REMOVE(listbox->listbox, widget); 2491 LISTBOX_REMOVE(listbox->listbox, widget);
2456 // empty row for header 2511 // empty row for header
2457 GtkWidget *row = gtk_list_box_row_new(); 2512 GtkWidget *row = gtk_list_box_row_new();
2458 cxListAdd(sublist->widgets, row); 2513 cxListAdd(sublist->widgets, row);
2459 g_object_set_data(G_OBJECT(row), "ui_listbox", listbox); 2514 g_object_set_data(G_OBJECT(row), "ui_listbox", listbox);
2460 g_object_set_data(G_OBJECT(row), "ui_listbox_sublist", sublist); 2515 g_object_set_data(G_OBJECT(row), "ui_listbox_sublist", sublist);
2461 intptr_t rowindex = listbox_insert_index + index; 2516 //intptr_t rowindex = listbox_insert_index + index;
2462 //g_object_set_data(G_OBJECT(row), "ui_listbox_row_index", (gpointer)rowindex); 2517 //g_object_set_data(G_OBJECT(row), "ui_listbox_row_index", (gpointer)rowindex);
2463 gtk_list_box_insert(listbox->listbox, row, listbox_insert_index + index); 2518 gtk_list_box_insert(listbox->listbox, row, listbox_insert_index + index);
2464 sublist->numitems = 1; 2519 sublist->numitems = 1;
2465 return; 2520 return;
2466 } 2521 }
2482 item.label = strdup(elm); 2537 item.label = strdup(elm);
2483 } 2538 }
2484 2539
2485 // create listbox item 2540 // create listbox item
2486 GtkWidget *row = gtk_list_box_row_new(); 2541 GtkWidget *row = gtk_list_box_row_new();
2542 #if GTK_CHECK_VERSION(4, 0, 0)
2543 GtkEventController *motion_controller = gtk_event_controller_motion_new();
2544 gtk_widget_add_controller(GTK_WIDGET(row), motion_controller);
2545 g_signal_connect(motion_controller, "enter", G_CALLBACK(listbox_row_enter), row);
2546 g_signal_connect(motion_controller, "leave", G_CALLBACK(listbox_row_leave), row);
2547 #else
2548 gtk_widget_set_events(GTK_WIDGET(row), GDK_POINTER_MOTION_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
2549 g_signal_connect(row, "enter-notify-event", G_CALLBACK(listbox_row_enter), NULL);
2550 g_signal_connect(row, "leave-notify-event", G_CALLBACK(listbox_row_leave), NULL);
2551 #endif
2552
2487 listbox_fill_row(listbox, row, sublist, &item, index); 2553 listbox_fill_row(listbox, row, sublist, &item, index);
2488 if(index == first_index) { 2554 if(index == first_index) {
2489 // first row in the sublist, set ui_listbox data to the row 2555 // first row in the sublist, set ui_listbox data to the row
2490 // which is then used by the headerfunc 2556 // which is then used by the headerfunc
2491 g_object_set_data(G_OBJECT(row), "ui_listbox", listbox); 2557 g_object_set_data(G_OBJECT(row), "ui_listbox", listbox);
2494 if(listbox_insert_index == 0) { 2560 if(listbox_insert_index == 0) {
2495 // first row in the GtkListBox 2561 // first row in the GtkListBox
2496 listbox->first_row = GTK_LIST_BOX_ROW(row); 2562 listbox->first_row = GTK_LIST_BOX_ROW(row);
2497 } 2563 }
2498 } 2564 }
2499 intptr_t rowindex = listbox_insert_index + index; 2565 //intptr_t rowindex = listbox_insert_index + index;
2500 //g_object_set_data(G_OBJECT(row), "ui_listbox_row_index", (gpointer)rowindex); 2566 //g_object_set_data(G_OBJECT(row), "ui_listbox_row_index", (gpointer)rowindex);
2501 gtk_list_box_insert(listbox->listbox, row, listbox_insert_index + index + header_row); 2567 gtk_list_box_insert(listbox->listbox, row, listbox_insert_index + index + header_row);
2502 cxListAdd(sublist->widgets, row); 2568 cxListAdd(sublist->widgets, row);
2503 2569
2504 // cleanup 2570 // cleanup

mercurial