[libadwaita/wip/cdavis/spin-row] Add AdwSpinRow




commit e740749859154d18cf3310e1cbd3a465e0df2814
Author: Christopher Davis <christopherdavis gnome org>
Date:   Mon Jul 11 17:47:34 2022 -0400

    Add AdwSpinRow

 src/adw-spin-row.c         | 94 ++++++++++++++++++++++++++++++++++++++++++++
 src/adw-spin-row.h         | 29 ++++++++++++++
 src/adw-spin-row.ui        | 98 ++++++++++++++++++++++++++++++++++++++++++++++
 src/adwaita.gresources.xml |  1 +
 src/adwaita.h              |  1 +
 src/meson.build            |  2 +
 6 files changed, 225 insertions(+)
---
diff --git a/src/adw-spin-row.c b/src/adw-spin-row.c
new file mode 100644
index 00000000..f0f0d0bf
--- /dev/null
+++ b/src/adw-spin-row.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2022 Christopher Davis <christopherdavis gnome org>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#include "adw-spin-row.h"
+
+#include "adw-macros-private.h"
+
+/**
+ * AdwSpinRow
+ */
+
+struct _AdwSpinRow
+{
+  AdwPreferencesRow parent_instance;
+
+  GtkWidget *header;
+  GtkWidget *title;
+  GtkWidget *subtitle;
+  GtkWidget *prefixes;
+  GtkWidget *suffixes;
+  GtkWidget *title_box;
+
+  GtkWidget *spin_button;
+};
+
+static void adw_spin_row_editable_init (GtkEditableInterface *iface);
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (AdwSpinRow, adw_spin_row, ADW_TYPE_SPIN_ROW,
+                               G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, adw_spin_row_editable_init))
+
+/* enum { */
+/*   PROP_0, */
+/*   PROP_ADJUSTMENT, */
+/*   PROP_CLIMB_RATE, */
+/*   PROP_DIGITS, */
+/*   PROP_NUMERIC, */
+/*   PROP_SNAP_TO_TICKS, */
+/*   PROP_UPDATE_POLICY, */
+/*   PROP_VALUE, */
+/*   PROP_WRAP, */
+/*   PROP_LAST_PROP, */
+/* }; */
+
+/* static GParamSpec *props[PROP_LAST_PROP]; */
+
+static void
+adw_spin_row_class_init (AdwSpinRowClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class,
+                                               "/org/gnome/Adwaita/ui/adw-spin-row.ui");
+  gtk_widget_class_bind_template_child (widget_class, AdwSpinRow, header);
+  gtk_widget_class_bind_template_child (widget_class, AdwSpinRow, prefixes);
+  gtk_widget_class_bind_template_child (widget_class, AdwSpinRow, suffixes);
+  gtk_widget_class_bind_template_child (widget_class, AdwSpinRow, title_box);
+  gtk_widget_class_bind_template_child (widget_class, AdwSpinRow, title);
+  gtk_widget_class_bind_template_child (widget_class, AdwSpinRow, subtitle);
+  gtk_widget_class_bind_template_child (widget_class, AdwSpinRow, spin_button);
+
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_TEXT_BOX);
+}
+
+static void
+adw_spin_row_init (AdwSpinRow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+  gtk_editable_init_delegate (GTK_EDITABLE (self));
+}
+
+static GtkEditable *
+adw_spin_row_editable_get_delegate (GtkEditable *editable)
+{
+  AdwSpinRow *self = ADW_SPIN_ROW (editable);
+  return GTK_EDITABLE (self->spin_button);
+}
+
+void
+adw_spin_row_editable_init (GtkEditableInterface *iface)
+{
+    iface->get_delegate = adw_spin_row_editable_get_delegate;
+}
+
+GtkWidget *
+adw_spin_row_new (void)
+{
+  return g_object_new (ADW_TYPE_SPIN_ROW, NULL);
+}
diff --git a/src/adw-spin-row.h b/src/adw-spin-row.h
new file mode 100644
index 00000000..017e4017
--- /dev/null
+++ b/src/adw-spin-row.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2022 Christopher Davis <christopherdavis gnome org>
+ *
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined(_ADWAITA_INSIDE) && !defined(ADWAITA_COMPILATION)
+#error "Only <adwaita.h> can be included directly."
+#endif
+
+#include "adw-version.h"
+
+#include <gtk/gtk.h>
+
+#include "adw-preferences-row.h"
+
+G_BEGIN_DECLS
+
+#define ADW_TYPE_SPIN_ROW (adw_spin_row_get_type ())
+
+ADW_AVAILABLE_IN_1_2
+G_DECLARE_FINAL_TYPE (AdwSpinRow, adw_spin_row, ADW, SPIN_ROW, AdwPreferencesRow)
+
+ADW_AVAILABLE_IN_1_2
+GtkWidget *adw_spin_row_new (void) G_GNUC_WARN_UNUSED_RESULT;
+
+G_END_DECLS
diff --git a/src/adw-spin-row.ui b/src/adw-spin-row.ui
new file mode 100644
index 00000000..08e76120
--- /dev/null
+++ b/src/adw-spin-row.ui
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="libadwaita">
+  <requires lib="gtk" version="4.0"/>
+  <template class="AdwSpinRow" parent="AdwPreferencesRow">
+    <accessibility>
+      <relation name="labelled-by">title</relation>
+    </accessibility>
+    <property name="activatable">True</property>
+    <child>
+      <object class="GtkGestureClick">
+        <signal name="pressed" handler="pressed_cb"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkBox" id="header">
+        <property name="valign">center</property>
+        <style>
+          <class name="header"/>
+        </style>
+        <child>
+          <object class="GtkBox" id="prefixes">
+            <property name="visible">False</property>
+            <style>
+              <class name="prefixes"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox" id="title_box">
+            <property name="orientation">vertical</property>
+            <property name="valign">center</property>
+            <property name="hexpand">True</property>
+            <style>
+              <class name="title"/>
+            </style>
+            <child>
+              <object class="GtkLabel" id="title">
+                <binding name="visible">
+                  <closure function="string_is_not_empty" type="gboolean">
+                    <lookup name="label">title</lookup>
+                  </closure>
+                </binding>
+                <property name="ellipsize">none</property>
+                <property name="label" bind-source="AdwSpinRow" bind-property="title" 
bind-flags="sync-create"/>
+                <property name="lines">0</property>
+                <property name="mnemonic-widget">AdwSpinRow</property>
+                <property name="use-underline" bind-source="AdwSpinRow" bind-property="use-underline" 
bind-flags="sync-create"/>
+                <property name="selectable" bind-source="AdwSpinRow" bind-property="title-selectable" 
bind-flags="sync-create"/>
+                <property name="wrap">True</property>
+                <property name="wrap-mode">word-char</property>
+                <property name="xalign">0</property>
+                <property name="use-markup" bind-source="AdwSpinRow" bind-property="use-markup" 
bind-flags="sync-create"/>
+                <style>
+                  <class name="title"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="subtitle">
+                <binding name="visible">
+                  <closure function="string_is_not_empty" type="gboolean">
+                    <lookup name="label">subtitle</lookup>
+                  </closure>
+                </binding>
+                <property name="ellipsize">none</property>
+                <property name="lines">0</property>
+                <property name="wrap">True</property>
+                <property name="wrap-mode">word-char</property>
+                <property name="xalign">0</property>
+                <property name="use-markup" bind-source="AdwSpinRow" bind-property="use-markup" 
bind-flags="sync-create"/>
+                <style>
+                  <class name="subtitle"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkSpinButton" id="spin_button">
+            <property name="valign">center</property>
+            <property name="xalign">1</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox" id="suffixes">
+            <property name="visible">False</property>
+            <style>
+              <class name="suffixes"/>
+            </style>
+          </object>
+        </child>
+     </object>
+    </child>
+    <style>
+      <class name="spin"/>
+    </style>
+  </template>
+</interface>
diff --git a/src/adwaita.gresources.xml b/src/adwaita.gresources.xml
index 58a0d7c4..df251529 100644
--- a/src/adwaita.gresources.xml
+++ b/src/adwaita.gresources.xml
@@ -21,6 +21,7 @@
     <file preprocess="xml-stripblanks">adw-preferences-group.ui</file>
     <file preprocess="xml-stripblanks">adw-preferences-page.ui</file>
     <file preprocess="xml-stripblanks">adw-preferences-window.ui</file>
+    <file preprocess="xml-stripblanks">adw-spin-row.ui</file>
     <file preprocess="xml-stripblanks">adw-status-page.ui</file>
     <file preprocess="xml-stripblanks">adw-tab.ui</file>
     <file preprocess="xml-stripblanks">adw-tab-bar.ui</file>
diff --git a/src/adwaita.h b/src/adwaita.h
index 509a9740..8f03dcbb 100644
--- a/src/adwaita.h
+++ b/src/adwaita.h
@@ -55,6 +55,7 @@ G_BEGIN_DECLS
 #include "adw-preferences-page.h"
 #include "adw-preferences-row.h"
 #include "adw-preferences-window.h"
+#include "adw-spin-row.h"
 #include "adw-split-button.h"
 #include "adw-spring-animation.h"
 #include "adw-spring-params.h"
diff --git a/src/meson.build b/src/meson.build
index b2c47498..be03752c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -115,6 +115,7 @@ src_headers = [
   'adw-preferences-page.h',
   'adw-preferences-row.h',
   'adw-preferences-window.h',
+  'adw-spin-row.h',
   'adw-split-button.h',
   'adw-spring-animation.h',
   'adw-spring-params.h',
@@ -179,6 +180,7 @@ src_sources = [
   'adw-preferences-page.c',
   'adw-preferences-row.c',
   'adw-preferences-window.c',
+  'adw-spin-row.c',
   'adw-split-button.c',
   'adw-spring-animation.c',
   'adw-spring-params.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]