I am trying to make a custom combobox in GTK3 with C.
I create a window and then attach a grid to it. The grid is composed of buttons (called generic_buttons). Here is the struct for that.
struct generic_button {
int x;
int y;
int j_width;
int j_height;
const char *pc_name[6];
GtkWidget *po_label;
/* The following are set by init_button() */
GdkPixbuf *po_pixbuf[6];
GtkWidget *po_layout;
GtkWidget *po_image;
int j_state;
int j_assignment;
};
Here is the function that initializes these windows and widgets
void init_meas_assign_combobox() {
// Create the window
meas_assign_combo.po_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_decorated(GTK_WINDOW(meas_assign_combo.po_window), FALSE);
gtk_window_set_type_hint(GTK_WINDOW(meas_assign_combo.po_window), GDK_WINDOW_TYPE_HINT_DIALOG);
gtk_window_set_position(GTK_WINDOW(meas_assign_combo.po_window), GTK_WIN_POS_MOUSE);
gtk_window_set_keep_above(GTK_WINDOW(meas_assign_combo.po_window), TRUE);
gtk_widget_set_size_request(meas_assign_combo.po_window, COMBO_WIDTH, COMBO_HEIGHT);
// Create the main layout
meas_assign_combo.po_main_layout = gtk_layout_new(NULL, NULL);
gtk_layout_set_size(GTK_LAYOUT(meas_assign_combo.po_main_layout), COMBO_WIDTH, COMBO_HEIGHT);
gtk_widget_set_size_request(meas_assign_combo.po_main_layout, COMBO_WIDTH, COMBO_HEIGHT);
gtk_container_add(GTK_CONTAINER(meas_assign_combo.po_window), meas_assign_combo.po_main_layout);
// Create the grid
meas_assign_combo.po_grid = gtk_grid_new();
// gtk_grid_insert_row(GTK_GRID(meas_assign_combo.po_grid), NELEM(ac_meas_assignments));
gtk_widget_set_size_request(GTK_WIDGET(meas_assign_combo.po_grid), COMBO_WIDTH, COMBO_HEIGHT);
gtk_grid_set_row_spacing(GTK_GRID(meas_assign_combo.po_grid), 5);
gtk_layout_put(GTK_LAYOUT(meas_assign_combo.po_main_layout), meas_assign_combo.po_grid, 0, 0);
// initialize measurement option titles
// initially I used i = 0, and this behaves the same way. I was
// trying to see if there was a problem with inserting a 0 row.
// But the problem persists.
for (int i = 1; i < NELEM(ac_meas_assignments)+1; i++) {
gtk_grid_insert_row(GTK_GRID(meas_assign_combo.po_grid), i);
init_button(&as_meas_assignments[i-1], "/recipe_panel"); // ((i*2)+1)
gtk_grid_attach(GTK_GRID(meas_assign_combo.po_grid), as_meas_assignments[i-1].po_layout, 1, i, 1, 1);
as_meas_assignments[i-1].po_label=gtk_label_new(ac_meas_assignments[i-1]);
gtk_layout_put(GTK_LAYOUT(as_meas_assignments[i-1].po_layout), as_meas_assignments[i-1].po_label, 0, 5);
}
g_signal_connect(G_OBJECT(meas_assign_combo.po_window), "leave-notify-event", G_CALLBACK(handle_leave_notify_event), NULL);
// Create the list of measurements
gtk_widget_show_all(meas_assign_combo.po_window);
}
And finally here is the array of buttons that is being used (as_meas_assignments):
// measurement assignment buttons (for combo box selections)
static struct generic_button as_meas_assignments[]={
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
{0, 0, 120, 20, {"measurement-name-bg"}},
};
As you can see, the height of all these buttons should be twenty. However, the first button placed in the gtk grid is ALWAYS around 25 pixels high instead of the 20 which is specified. I am also attaching an image of how this custom combo box looks so y'all can see the problem.
Thanks for the help!
