history-box: compose with GtkBin instead of subclassing GtkStack

Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/714>
This commit is contained in:
Anton Lazarev
2023-08-26 18:49:13 -07:00
parent 08603179c3
commit f1e63c4979
3 changed files with 35 additions and 28 deletions

View File

@@ -39,8 +39,9 @@
#define CALLS_HISTORY_INCREASE_N_PAGES_THRESHOLD 2 #define CALLS_HISTORY_INCREASE_N_PAGES_THRESHOLD 2
struct _CallsHistoryBox { struct _CallsHistoryBox {
GtkStack parent_instance; GtkBin parent_instance;
GtkStack *stack;
GtkListBox *history; GtkListBox *history;
GtkScrolledWindow *scrolled_window; GtkScrolledWindow *scrolled_window;
GtkAdjustment *scroll_adjustment; GtkAdjustment *scroll_adjustment;
@@ -54,7 +55,7 @@ struct _CallsHistoryBox {
}; };
G_DEFINE_TYPE (CallsHistoryBox, calls_history_box, GTK_TYPE_STACK); G_DEFINE_TYPE (CallsHistoryBox, calls_history_box, GTK_TYPE_BIN);
enum { enum {
@@ -80,7 +81,7 @@ on_model_changed (GListModel *model,
else else
child_name = "history"; child_name = "history";
gtk_stack_set_visible_child_name (GTK_STACK (self), child_name); gtk_stack_set_visible_child_name (self->stack, child_name);
} }
@@ -256,6 +257,7 @@ calls_history_box_class_init (CallsHistoryBoxClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/history-box.ui"); gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/history-box.ui");
gtk_widget_class_bind_template_child (widget_class, CallsHistoryBox, stack);
gtk_widget_class_bind_template_child (widget_class, CallsHistoryBox, history); gtk_widget_class_bind_template_child (widget_class, CallsHistoryBox, history);
gtk_widget_class_bind_template_child (widget_class, CallsHistoryBox, scrolled_window); gtk_widget_class_bind_template_child (widget_class, CallsHistoryBox, scrolled_window);
} }

View File

@@ -33,7 +33,7 @@ G_BEGIN_DECLS
#define CALLS_TYPE_HISTORY_BOX (calls_history_box_get_type ()) #define CALLS_TYPE_HISTORY_BOX (calls_history_box_get_type ())
G_DECLARE_FINAL_TYPE (CallsHistoryBox, calls_history_box, CALLS, HISTORY_BOX, GtkStack); G_DECLARE_FINAL_TYPE (CallsHistoryBox, calls_history_box, CALLS, HISTORY_BOX, GtkBin);
CallsHistoryBox *calls_history_box_new (GListModel *model); CallsHistoryBox *calls_history_box_new (GListModel *model);

View File

@@ -2,41 +2,46 @@
<!-- Generated with glade 3.22.0 --> <!-- Generated with glade 3.22.0 -->
<interface> <interface>
<requires lib="gtk+" version="3.22"/> <requires lib="gtk+" version="3.22"/>
<template class="CallsHistoryBox" parent="GtkStack"> <template class="CallsHistoryBox" parent="GtkBin">
<child> <child>
<object class="HdyStatusPage"> <object class="GtkStack" id="stack">
<property name="visible">True</property> <property name="visible">True</property>
<property name="icon-name">call-start-symbolic</property>
<property name="title" translatable="yes">No Recent Calls</property>
</object>
<packing>
<property name="name">empty</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<child> <child>
<object class="HdyClamp"> <object class="HdyStatusPage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="icon-name">call-start-symbolic</property>
<property name="title" translatable="yes">No Recent Calls</property>
</object>
<packing>
<property name="name">empty</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<child> <child>
<object class="GtkListBox" id="history"> <object class="HdyClamp">
<property name="visible">True</property> <property name="visible">True</property>
<property name="margin">12</property> <child>
<property name="valign">start</property> <object class="GtkListBox" id="history">
<style> <property name="visible">True</property>
<class name="content"/> <property name="margin">12</property>
</style> <property name="valign">start</property>
<style>
<class name="content"/>
</style>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>
<packing>
<property name="name">history</property>
</packing>
</child> </child>
</object> </object>
<packing>
<property name="name">history</property>
</packing>
</child> </child>
</template> </template>
</interface> </interface>