The xml document can be use to create your interface, it is not a mandatory use, it is an available fonctionnality
It can be used to create object templates, than can be used later in the XML document to create an UI
As I am adapting one of my GTK2 software to be available with GTK3 & libhandy
I will use this post to make some mini-tutorials, and how I solved encountered problems
You juste have to set the property valign of the switch widget to GTK_ALIGN_CENTER, 2 choices : gtk_widget_set_valign( item, GTK_ALIGN_CENTER );
or if you are a g_object_set() user : g_object_set( item, "valign", GTK_ALIGN_CENTER, NULL );
So if you want this kind of visual for your option:
it is done with :
GtkWidget *page = hdy_preferences_page_new();
gtk_container_add( GTK_CONTAINER(parent), page );
GtkWidget *group = hdy_preferences_group_new();
gtk_container_add( GTK_CONTAINER(page), group );
GtkWidget *row = hdy_action_row_new();
hdy_preferences_row_set_title( (HdyPreferencesRow*) row, "Modal" );
hdy_action_row_set_subtitle( (HdyActionRow*) row, "Clicking outside the sidebar or pressing Esc will close it when folded" );
g_object_set( row, "subtitle-lines", 2, NULL );
gtk_container_add( GTK_CONTAINER(group), row );
GtkWidget *item = gtk_switch_new();
gtk_widget_set_valign( item, GTK_ALIGN_CENTER );
hdy_action_row_set_activatable_widget( (HdyActionRow*) row, item );
gtk_container_add( GTK_CONTAINER(row), item );
Side notes :
hdy_preferences_page_new() is use to stack multiple preferences group
hdy_preferences_group_new() permits to group multiple rows in one block
The property ‘subtitle-lines’ of the row will allow to auto-cut the subtitle in 2 lines if it’s too long to fit in one line, else the subtitle is truncated with ‘…’
hdy_action_row_set_activatable_widget() permits the user to activate the switch widget by clicking anywhere inside the row
Your popup window is now linked to a parent window but, still it happens when mapping the popup window before the parent window
To solve this, make sure you mapped your parent window before your popup window
Side notes :
The mapping happens in gtk_widget_show_all() and gtk_widget_show()
In Callback_list(), you have to return an allocated copy of the value, else it doesn’t show the name of the selected item in the GUI
During the call hdy_combo_row_bind_name_model(), Callback_list() is called N times, N being the number of elements you have in your list
The values in the list can also be set from an enumration, see hdy_combo_row_set_for_enum()
If you compile as is and you face the following error (from gcc):
dereferencing pointer to incomplete type ‘HdyValueObject’
It’s because the structure is not declared in the includes of the library, which is far from perfect so you will have to add this declaration in your code:
Hello! I don’t have anything useful to add here right now other than to say that I appreciate you keeping up your monologue here, looks like it could be very useful to look at if/when I might try doing something with libhandy later. The “trying to understand” kind of forum threads are my favorite kind.
Thanks, but to be honest I’m running out of “things I did” to show
The others things I did were pretty straight forward to do, so not enough interesting to make some mini-tutorial about
I still have 1 or 2 things in mind to show, but first I have take time to try and figure out how to make them
So to make it work with libadwaita, you probably only have to replace the hdy prefixes with adw
To add a widget to the left of the row, you have to use the hdy_expander_row_add_prefix() function
Using hdy_expander_row_set_enable_expansion() will expand or close the row while it enables or disables it
We need 2 variables for the 2 widgets to be passed to the callback functions
I used the parameter of the callback, and a global variable
It’s just an out context exemple to make it work
It would be probably better to pass a pointer to an allocated structure/table containing those 2 variables
You could also use only one callback function and check the state of one of the radio button
Just to giving a overview of the migration from GTK2 to GTK3 to libhandy (aka libadwaita) I made
The theme used for GTK2 and GTK3 is ‘greybird’, and I think ‘adwaita’ for libhandy
Here my original GTK2 version
Then migrated to GTK3 (I could have made a better job to align the options in the ‘Main window’ frame)