Add alignment to stylesheet editor
authorThomas White <taw@bitwiz.me.uk>
Tue, 30 Oct 2018 20:35:10 +0000 (21:35 +0100)
committerThomas White <taw@bitwiz.me.uk>
Tue, 30 Oct 2018 20:35:10 +0000 (21:35 +0100)
data/stylesheeteditor.ui
src/stylesheet_editor.c
src/stylesheet_editor.h

index 19723bb..0e806be 100644 (file)
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkBox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">8</property>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Alignment:</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBoxText" id="narrative_style_alignment">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="active">0</property>
+                        <property name="active_id">left</property>
+                        <items>
+                          <item id="left" translatable="yes">Left</item>
+                          <item id="center" translatable="yes">Center</item>
+                          <item id="right" translatable="yes">Right</item>
+                        </items>
+                        <signal name="changed" handler="narrative_alignment_sig" swapped="no"/>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="padding">2</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkFrame">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
                     <property name="padding">4</property>
-                    <property name="position">3</property>
+                    <property name="position">4</property>
                   </packing>
                 </child>
                 <child>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
                     <property name="padding">4</property>
-                    <property name="position">4</property>
+                    <property name="position">5</property>
                   </packing>
                 </child>
               </object>
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkBox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">8</property>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Alignment:</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBoxText" id="frame_style_alignment">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="active">0</property>
+                        <property name="active_id">left</property>
+                        <items>
+                          <item id="left" translatable="yes">Left</item>
+                          <item id="center" translatable="yes">Center</item>
+                          <item id="right" translatable="yes">Right</item>
+                        </items>
+                        <signal name="changed" handler="frame_alignment_sig" swapped="no"/>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="padding">2</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkFrame">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
                     <property name="padding">4</property>
-                    <property name="position">3</property>
+                    <property name="position">4</property>
                   </packing>
                 </child>
                 <child>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
                     <property name="padding">4</property>
-                    <property name="position">4</property>
+                    <property name="position">5</property>
                   </packing>
                 </child>
               </object>
index 8100472..55ac3a9 100644 (file)
@@ -106,6 +106,27 @@ static void set_size_from_ss(Stylesheet *ss, const char *path,
        }
 }
 
+
+static int alignment_ok(const char *a)
+{
+       if ( a == NULL ) return 0;
+       if ( strcmp(a, "left") == 0 ) return 1;
+       if ( strcmp(a, "center") == 0 ) return 1;
+       if ( strcmp(a, "right") == 0 ) return 1;
+       return 0;
+}
+
+
+static void set_alignment_from_ss(Stylesheet *ss, const char *path,
+                                  GtkWidget *d)
+{
+       char *result = stylesheet_lookup(ss, path, "alignment");
+       if ( alignment_ok(result) ) {
+               gtk_combo_box_set_active_id(GTK_COMBO_BOX(d), result);
+       }
+}
+
+
 static void set_bg_from_ss(Stylesheet *ss, const char *path, GtkWidget *wcol,
                            GtkWidget *wcol2, GtkWidget *wgrad)
 {
@@ -173,6 +194,7 @@ static void set_values_from_presentation(StylesheetEditor *se)
        /* Narrative */
        set_font_from_ss(ss, "$.narrative", se->narrative_style_font);
        set_col_from_ss(ss, "$.narrative", se->narrative_style_fgcol);
+       set_alignment_from_ss(ss, "$.narrative", se->narrative_style_alignment);
        set_bg_from_ss(ss, "$.narrative", se->narrative_style_bgcol,
                                          se->narrative_style_bgcol2,
                                          se->narrative_style_bggrad);
@@ -195,6 +217,7 @@ static void set_values_from_presentation(StylesheetEditor *se)
        /* Frames */
        set_font_from_ss(ss, "$.slide.frame", se->frame_style_font);
        set_col_from_ss(ss, "$.slide.frame", se->frame_style_fgcol);
+       set_alignment_from_ss(ss, "$.slide.frame", se->frame_style_alignment);
        set_bg_from_ss(ss, "$.slide.frame", se->frame_style_bgcol,
                                            se->frame_style_bgcol2,
                                            se->frame_style_bggrad);
@@ -347,6 +370,15 @@ static void narrative_bg_sig(GtkColorButton *widget, StylesheetEditor *se)
 }
 
 
+static void narrative_alignment_sig(GtkComboBoxText *widget, StylesheetEditor *se)
+{
+       const gchar *id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget));
+       stylesheet_set(se->priv->p->stylesheet, "$.narrative", "alignment", id);
+       set_values_from_presentation(se);
+       g_signal_emit_by_name(se, "changed");
+}
+
+
 static void slide_size_sig(GtkSpinButton *widget, StylesheetEditor *se)
 {
        int w, h;
@@ -426,6 +458,15 @@ static void frame_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se)
 }
 
 
+static void frame_alignment_sig(GtkComboBoxText *widget, StylesheetEditor *se)
+{
+       const gchar *id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget));
+       stylesheet_set(se->priv->p->stylesheet, "$.slide.frame", "alignment", id);
+       set_values_from_presentation(se);
+       g_signal_emit_by_name(se, "changed");
+}
+
+
 static void narrative_padding_sig(GtkSpinButton *widget, StylesheetEditor *se)
 {
        update_spacing(se->priv->p, "$.narrative", "pad",
@@ -487,6 +528,7 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass)
        SE_BIND_CHILD(narrative_style_padding_r, narrative_padding_sig);
        SE_BIND_CHILD(narrative_style_padding_t, narrative_padding_sig);
        SE_BIND_CHILD(narrative_style_padding_b, narrative_padding_sig);
+       SE_BIND_CHILD(narrative_style_alignment, narrative_alignment_sig);
 
        /* Slide style */
        SE_BIND_CHILD(slide_size_w, slide_size_sig);
@@ -509,6 +551,7 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass)
        SE_BIND_CHILD(frame_style_padding_r, frame_padding_sig);
        SE_BIND_CHILD(frame_style_padding_t, frame_padding_sig);
        SE_BIND_CHILD(frame_style_padding_b, frame_padding_sig);
+       SE_BIND_CHILD(frame_style_alignment, frame_alignment_sig);
 
        gtk_widget_class_bind_template_callback(widget_class, revert_sig);
 
index 22856da..0dea6d5 100644 (file)
@@ -71,6 +71,7 @@ struct _stylesheeteditor
        GtkWidget *narrative_style_padding_r;
        GtkWidget *narrative_style_padding_t;
        GtkWidget *narrative_style_padding_b;
+       GtkWidget *narrative_style_alignment;
        GtkWidget *slide_size_w;
        GtkWidget *slide_size_h;
        GtkWidget *slide_style_bgcol;
@@ -89,6 +90,7 @@ struct _stylesheeteditor
        GtkWidget *frame_style_padding_r;
        GtkWidget *frame_style_padding_t;
        GtkWidget *frame_style_padding_b;
+       GtkWidget *frame_style_alignment;
        StylesheetEditorPrivate *priv;
 };