[gnome-software: 40/110] gs-screenshot-carousel: Subclass GtkWidget
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 40/110] gs-screenshot-carousel: Subclass GtkWidget
- Date: Tue, 5 Oct 2021 20:32:37 +0000 (UTC)
commit c73b7d5c012dc81c437e7bd6ab618b1dfb5a2f83
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Aug 23 10:57:12 2021 -0300
gs-screenshot-carousel: Subclass GtkWidget
Looks mostly like the previous commit, except that the child is a
GtkStack.
Notice that more GtkStack APIs changed, so more work will be required,
this commit merely moves the GtkStack to be a child instead of the
template parent class.
src/gs-screenshot-carousel.c | 9 +-
src/gs-screenshot-carousel.h | 2 +-
src/gs-screenshot-carousel.ui | 251 +++++++++++++++++++++---------------------
3 files changed, 135 insertions(+), 127 deletions(-)
---
diff --git a/src/gs-screenshot-carousel.c b/src/gs-screenshot-carousel.c
index b30d5eeac..c54f4379e 100644
--- a/src/gs-screenshot-carousel.c
+++ b/src/gs-screenshot-carousel.c
@@ -40,7 +40,7 @@
struct _GsScreenshotCarousel
{
- GtkStack parent_instance;
+ GtkWidget parent_instance;
SoupSession *session; /* (owned) (not nullable) */
gboolean has_screenshots;
@@ -53,6 +53,7 @@ struct _GsScreenshotCarousel
GtkWidget *button_previous_revealer;
GtkWidget *carousel;
GtkWidget *carousel_indicator;
+ GtkStack *stack;
};
typedef enum {
@@ -61,7 +62,7 @@ typedef enum {
static GParamSpec *obj_props[PROP_HAS_SCREENSHOTS + 1] = { NULL, };
-G_DEFINE_TYPE (GsScreenshotCarousel, gs_screenshot_carousel, GTK_TYPE_STACK)
+G_DEFINE_TYPE (GsScreenshotCarousel, gs_screenshot_carousel, GTK_TYPE_WIDGET)
static void
_set_state (GsScreenshotCarousel *self, guint length, gboolean allow_fallback, gboolean is_online)
@@ -69,7 +70,7 @@ _set_state (GsScreenshotCarousel *self, guint length, gboolean allow_fallback, g
gboolean has_screenshots;
gtk_widget_set_visible (self->carousel_indicator, length > 1);
- gtk_stack_set_visible_child_name (GTK_STACK (self), length > 0 ? "carousel" : "fallback");
+ gtk_stack_set_visible_child_name (self->stack, length > 0 ? "carousel" : "fallback");
has_screenshots = length > 0 || (allow_fallback && is_online);
if (self->has_screenshots != has_screenshots) {
@@ -335,6 +336,7 @@ gs_screenshot_carousel_class_init (GsScreenshotCarouselClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsScreenshotCarousel, button_previous_revealer);
gtk_widget_class_bind_template_child (widget_class, GsScreenshotCarousel, carousel);
gtk_widget_class_bind_template_child (widget_class, GsScreenshotCarousel, carousel_indicator);
+ gtk_widget_class_bind_template_child (widget_class, GsScreenshotCarousel, stack);
gtk_widget_class_bind_template_callback (widget_class, gs_screenshot_carousel_notify_n_pages_cb);
gtk_widget_class_bind_template_callback (widget_class, gs_screenshot_carousel_notify_position_cb);
@@ -342,6 +344,7 @@ gs_screenshot_carousel_class_init (GsScreenshotCarouselClass *klass)
gtk_widget_class_bind_template_callback (widget_class, gs_screenshot_carousel_button_next_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class,
gs_screenshot_carousel_navigate_button_direction_changed_cb);
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_css_name (widget_class, "screenshot-carousel");
}
diff --git a/src/gs-screenshot-carousel.h b/src/gs-screenshot-carousel.h
index ea208280a..460d88ded 100644
--- a/src/gs-screenshot-carousel.h
+++ b/src/gs-screenshot-carousel.h
@@ -15,7 +15,7 @@ G_BEGIN_DECLS
#define GS_TYPE_SCREENSHOT_CAROUSEL (gs_screenshot_carousel_get_type ())
-G_DECLARE_FINAL_TYPE (GsScreenshotCarousel, gs_screenshot_carousel, GS, SCREENSHOT_CAROUSEL, GtkStack)
+G_DECLARE_FINAL_TYPE (GsScreenshotCarousel, gs_screenshot_carousel, GS, SCREENSHOT_CAROUSEL, GtkWidget)
GsScreenshotCarousel *gs_screenshot_carousel_new (void);
void gs_screenshot_carousel_load_screenshots (GsScreenshotCarousel *self,
diff --git a/src/gs-screenshot-carousel.ui b/src/gs-screenshot-carousel.ui
index 2b3d2994d..d39eba6ab 100644
--- a/src/gs-screenshot-carousel.ui
+++ b/src/gs-screenshot-carousel.ui
@@ -2,158 +2,163 @@
<interface>
<requires lib="gtk+" version="3.10"/>
<requires lib="handy" version="1.0"/>
- <template class="GsScreenshotCarousel" parent="GtkStack">
- <property name="no-show-all">True</property>
+ <template class="GsScreenshotCarousel" parent="GtkWidget">
+ <property name="visible">False</property>
<child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <style>
- <class name="frame"/>
- <class name="view"/>
- </style>
+ <object class="GtkStack" id="stack">
+ <property name="no-show-all">True</property>
<child>
- <object class="GtkOverlay">
+ <object class="GtkBox">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <style>
+ <class name="frame"/>
+ <class name="view"/>
+ </style>
<child>
- <object class="AdwCarousel" id="carousel">
- <property name="visible">True</property>
- <signal name="notify::n-pages" handler="gs_screenshot_carousel_notify_n_pages_cb"
swapped="yes"/>
- <signal name="notify::position" handler="gs_screenshot_carousel_notify_position_cb"
swapped="yes"/>
- </object>
- </child>
- <child type="overlay">
- <object class="GtkRevealer" id="button_previous_revealer">
- <property name="halign">start</property>
- <property name="transition-type">crossfade</property>
- <property name="valign">center</property>
+ <object class="GtkOverlay">
<property name="visible">True</property>
<child>
- <object class="GtkButton" id="button_previous">
+ <object class="AdwCarousel" id="carousel">
+ <property name="visible">True</property>
+ <signal name="notify::n-pages" handler="gs_screenshot_carousel_notify_n_pages_cb"
swapped="yes"/>
+ <signal name="notify::position" handler="gs_screenshot_carousel_notify_position_cb"
swapped="yes"/>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkRevealer" id="button_previous_revealer">
+ <property name="halign">start</property>
+ <property name="transition-type">crossfade</property>
+ <property name="valign">center</property>
<property name="visible">True</property>
- <property name="width-request">64</property>
- <property name="height-request">64</property>
- <property name="margin">9</property>
- <signal name="clicked" handler="gs_screenshot_carousel_button_previous_clicked_cb"
swapped="yes"/>
- <child internal-child="accessible">
- <object class="AtkObject">
- <!-- Translators: This is the accessible description for a button to go to the
previous screenshot in the screenshot carousel. -->
- <property name="accessible-name" translatable="yes">Previous Screenshot</property>
- </object>
- </child>
- <style>
- <class name="circular"/>
- <class name="osd"/>
- </style>
<child>
- <object class="GtkImage" id="button_previous_image">
- <property name="halign">center</property>
- <property name="icon-name">carousel-arrow-previous-symbolic</property>
- <property name="icon-size">1</property>
- <property name="valign">center</property>
+ <object class="GtkButton" id="button_previous">
<property name="visible">True</property>
- <property name="name">previous</property>
- <signal name="direction-changed"
handler="gs_screenshot_carousel_navigate_button_direction_changed_cb"/>
+ <property name="width-request">64</property>
+ <property name="height-request">64</property>
+ <property name="margin">9</property>
+ <signal name="clicked" handler="gs_screenshot_carousel_button_previous_clicked_cb"
swapped="yes"/>
+ <child internal-child="accessible">
+ <object class="AtkObject">
+ <!-- Translators: This is the accessible description for a button to go to the
previous screenshot in the screenshot carousel. -->
+ <property name="accessible-name" translatable="yes">Previous
Screenshot</property>
+ </object>
+ </child>
+ <style>
+ <class name="circular"/>
+ <class name="osd"/>
+ </style>
+ <child>
+ <object class="GtkImage" id="button_previous_image">
+ <property name="halign">center</property>
+ <property name="icon-name">carousel-arrow-previous-symbolic</property>
+ <property name="icon-size">1</property>
+ <property name="valign">center</property>
+ <property name="visible">True</property>
+ <property name="name">previous</property>
+ <signal name="direction-changed"
handler="gs_screenshot_carousel_navigate_button_direction_changed_cb"/>
+ </object>
+ </child>
</object>
</child>
</object>
+ <packing>
+ <property name="pass-through">True</property>
+ </packing>
</child>
- </object>
- <packing>
- <property name="pass-through">True</property>
- </packing>
- </child>
- <child type="overlay">
- <object class="GtkRevealer" id="button_next_revealer">
- <property name="halign">end</property>
- <property name="transition-type">crossfade</property>
- <property name="valign">center</property>
- <property name="visible">True</property>
- <child>
- <object class="GtkButton" id="button_next">
+ <child type="overlay">
+ <object class="GtkRevealer" id="button_next_revealer">
+ <property name="halign">end</property>
+ <property name="transition-type">crossfade</property>
+ <property name="valign">center</property>
<property name="visible">True</property>
- <property name="width-request">64</property>
- <property name="height-request">64</property>
- <property name="margin">9</property>
- <signal name="clicked" handler="gs_screenshot_carousel_button_next_clicked_cb"
swapped="yes"/>
- <child internal-child="accessible">
- <object class="AtkObject">
- <!-- Translators: This is the accessible description for a button to go to the next
screenshot in the screenshot carousel. -->
- <property name="accessible-name" translatable="yes">Next Screenshot</property>
- </object>
- </child>
- <style>
- <class name="circular"/>
- <class name="osd"/>
- </style>
<child>
- <object class="GtkImage" id="button_next_image">
- <property name="halign">center</property>
- <property name="icon-name">carousel-arrow-next-symbolic</property>
- <property name="icon-size">1</property>
- <property name="valign">center</property>
+ <object class="GtkButton" id="button_next">
<property name="visible">True</property>
- <property name="name">next</property>
- <signal name="direction-changed"
handler="gs_screenshot_carousel_navigate_button_direction_changed_cb"/>
+ <property name="width-request">64</property>
+ <property name="height-request">64</property>
+ <property name="margin">9</property>
+ <signal name="clicked" handler="gs_screenshot_carousel_button_next_clicked_cb"
swapped="yes"/>
+ <child internal-child="accessible">
+ <object class="AtkObject">
+ <!-- Translators: This is the accessible description for a button to go to the
next screenshot in the screenshot carousel. -->
+ <property name="accessible-name" translatable="yes">Next Screenshot</property>
+ </object>
+ </child>
+ <style>
+ <class name="circular"/>
+ <class name="osd"/>
+ </style>
+ <child>
+ <object class="GtkImage" id="button_next_image">
+ <property name="halign">center</property>
+ <property name="icon-name">carousel-arrow-next-symbolic</property>
+ <property name="icon-size">1</property>
+ <property name="valign">center</property>
+ <property name="visible">True</property>
+ <property name="name">next</property>
+ <signal name="direction-changed"
handler="gs_screenshot_carousel_navigate_button_direction_changed_cb"/>
+ </object>
+ </child>
</object>
</child>
</object>
+ <packing>
+ <property name="pass-through">True</property>
+ </packing>
</child>
</object>
- <packing>
- <property name="pass-through">True</property>
- </packing>
+ </child>
+ <child>
+ <object class="AdwCarouselIndicatorDots" id="carousel_indicator">
+ <property name="carousel">carousel</property>
+ <property name="visible">True</property>
+ </object>
</child>
</object>
+ <packing>
+ <property name="name">carousel</property>
+ </packing>
</child>
<child>
- <object class="AdwCarouselIndicatorDots" id="carousel_indicator">
- <property name="carousel">carousel</property>
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="name">carousel</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
- <!-- Arbitrary size chosen to tile together at 16:9;
- see https://blogs.gnome.org/hughsie/2014/07/02/blurry-screenshots-in-gnome-software/ -->
- <property name="height_request">423</property>
- <property name="hexpand">True</property>
- <property name="halign">fill</property>
- <style>
- <class name="screenshot-image"/>
- <class name="frame"/>
- <class name="view"/>
- </style>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="pixel_size">64</property>
- <property name="icon_name">camera-photo-symbolic</property>
- <property name="valign">end</property>
- <property name="vexpand">True</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel">
+ <object class="GtkBox">
<property name="visible">True</property>
- <property name="halign">center</property>
- <property name="valign">start</property>
- <property name="vexpand">True</property>
- <property name="label" translatable="yes">No screenshot provided</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <!-- Arbitrary size chosen to tile together at 16:9;
+ see https://blogs.gnome.org/hughsie/2014/07/02/blurry-screenshots-in-gnome-software/ -->
+ <property name="height_request">423</property>
+ <property name="hexpand">True</property>
+ <property name="halign">fill</property>
+ <style>
+ <class name="screenshot-image"/>
+ <class name="frame"/>
+ <class name="view"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="pixel_size">64</property>
+ <property name="icon_name">camera-photo-symbolic</property>
+ <property name="valign">end</property>
+ <property name="vexpand">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="halign">center</property>
+ <property name="valign">start</property>
+ <property name="vexpand">True</property>
+ <property name="label" translatable="yes">No screenshot provided</property>
+ </object>
+ </child>
</object>
+ <packing>
+ <property name="name">fallback</property>
+ </packing>
</child>
</object>
- <packing>
- <property name="name">fallback</property>
- </packing>
</child>
</template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]