Commit 8e3511be authored by Jan-Michael Brummer's avatar Jan-Michael Brummer

dzl-suggestion: Add compact mode

If compact mode for a DzlSuggestionEntry is activated the layout for title/subtitle changes from horizontal to vertical.
This improves readability for small screen factors.
parent 7772c5c3
......@@ -37,6 +37,10 @@ dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > li
color: @theme_fg_color;
}
dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row box.vertical .subtitle {
margin-left: 12px;
}
dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row .separator {
margin-left: 12px;
margin-right: 12px;
......
......@@ -1050,3 +1050,12 @@ dzl_suggestion_entry_get_popover (DzlSuggestionEntry *self)
return GTK_WIDGET (priv->popover);
}
void
dzl_suggestion_entry_set_compact (DzlSuggestionEntry *self,
gboolean compact)
{
DzlSuggestionEntryPrivate *priv = dzl_suggestion_entry_get_instance_private (self);
dzl_suggestion_popover_set_compact (priv->popover, compact);
}
......@@ -108,6 +108,10 @@ void dzl_suggestion_entry_window_position_func (DzlSuggestionEntry *self,
gboolean *is_absolute,
gpointer user_data);
DZL_AVAILABLE_IN_3_34
void dzl_suggestion_entry_set_compact (DzlSuggestionEntry *self,
gboolean compact);
G_END_DECLS
#endif /* DZL_SUGGESTION_ENTRY_H */
......@@ -75,6 +75,7 @@ struct _DzlSuggestionPopover
guint popup_requested : 1;
guint entry_focused : 1;
guint has_grab : 1;
guint compact : 1;
};
enum {
......@@ -500,6 +501,7 @@ attach_cb (DzlListBox *list_box,
_dzl_suggestion_row_set_ellipsize (DZL_SUGGESTION_ROW (row),
self->title_ellipsize,
self->subtitle_ellipsize);
gtk_orientable_set_orientation (GTK_ORIENTABLE (row), self->compact ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
}
static gboolean
......@@ -1340,3 +1342,10 @@ _dzl_suggestion_popover_set_device (DzlSuggestionPopover *self,
g_set_object (&self->grab_device, device);
}
}
void
dzl_suggestion_popover_set_compact (DzlSuggestionPopover *self,
gboolean compact)
{
self->compact = compact;
}
......@@ -58,6 +58,9 @@ void dzl_suggestion_popover_set_selected (DzlSuggestionPopover *s
DZL_AVAILABLE_IN_ALL
void dzl_suggestion_popover_activate_selected (DzlSuggestionPopover *self);
void dzl_suggestion_popover_set_compact (DzlSuggestionPopover *self,
gboolean compact);
G_END_DECLS
#endif /* DZL_SUGGESTION_POPOVER_H */
......@@ -27,21 +27,28 @@ typedef struct
{
DzlSuggestion *suggestion;
GtkOrientation orientation;
gulong notify_icon_handler;
GtkImage *image;
GtkLabel *title;
GtkLabel *separator;
GtkLabel *subtitle;
GtkLabel *box;
} DzlSuggestionRowPrivate;
enum {
PROP_0,
PROP_SUGGESTION,
PROP_ORIENTATION,
N_PROPS
};
G_DEFINE_TYPE_WITH_PRIVATE (DzlSuggestionRow, dzl_suggestion_row, DZL_TYPE_LIST_BOX_ROW)
G_DEFINE_TYPE_EXTENDED (DzlSuggestionRow, dzl_suggestion_row, DZL_TYPE_LIST_BOX_ROW, 0,
G_ADD_PRIVATE (DzlSuggestionRow)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
static GParamSpec *properties [N_PROPS];
......@@ -107,7 +114,13 @@ dzl_suggestion_row_connect (DzlSuggestionRow *self)
subtitle = dzl_suggestion_get_subtitle (priv->suggestion);
gtk_label_set_label (priv->subtitle, subtitle);
gtk_widget_set_visible (GTK_WIDGET (priv->separator), !!subtitle);
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
gtk_widget_set_visible (GTK_WIDGET (priv->separator), FALSE);
else
gtk_widget_set_visible (GTK_WIDGET (priv->separator), !!subtitle);
gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), priv->orientation);
}
static void
......@@ -132,6 +145,7 @@ dzl_suggestion_row_get_property (GObject *object,
GParamSpec *pspec)
{
DzlSuggestionRow *self = DZL_SUGGESTION_ROW (object);
DzlSuggestionRowPrivate *priv = dzl_suggestion_row_get_instance_private (self);
switch (prop_id)
{
......@@ -139,6 +153,10 @@ dzl_suggestion_row_get_property (GObject *object,
g_value_set_object (value, dzl_suggestion_row_get_suggestion (self));
break;
case PROP_ORIENTATION:
g_value_set_enum (value, priv->orientation);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
......@@ -151,6 +169,7 @@ dzl_suggestion_row_set_property (GObject *object,
GParamSpec *pspec)
{
DzlSuggestionRow *self = DZL_SUGGESTION_ROW (object);
DzlSuggestionRowPrivate *priv = dzl_suggestion_row_get_instance_private (self);
switch (prop_id)
{
......@@ -158,6 +177,14 @@ dzl_suggestion_row_set_property (GObject *object,
dzl_suggestion_row_set_suggestion (self, g_value_get_object (value));
break;
case PROP_ORIENTATION:
priv->orientation = g_value_get_enum (value);
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
gtk_widget_set_visible (GTK_WIDGET (priv->separator), FALSE);
gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), priv->orientation);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
......@@ -180,13 +207,22 @@ dzl_suggestion_row_class_init (DzlSuggestionRowClass *klass)
DZL_TYPE_SUGGESTION,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
properties [PROP_ORIENTATION] =
g_param_spec_enum ("orientation",
"Orientation",
"Orientation",
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_VERTICAL,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/dazzle/ui/dzl-suggestion-row.ui");
gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, image);
gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, title);
gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, subtitle);
gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, separator);
gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, box);
}
static void
......
......@@ -13,39 +13,60 @@
</object>
</child>
<child>
<object class="GtkLabel" id="title">
<property name="hexpand">false</property>
<property name="visible">true</property>
<property name="xalign">0.0</property>
<property name="use-markup">true</property>
<property name="ellipsize">end</property>
<style>
<class name="title"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="separator">
<property name="hexpand">false</property>
<property name="label"></property>
<property name="visible">true</property>
<style>
<class name="separator"/>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="subtitle">
<property name="hexpand">true</property>
<object class="GtkBox" id="box">
<property name="orientation">horizontal</property>
<property name="visible">true</property>
<property name="xalign">0.0</property>
<property name="use-markup">true</property>
<property name="ellipsize">end</property>
<style>
<class name="dim-label"/>
<class name="subtitle"/>
</style>
<child>
<object class="GtkLabel" id="title">
<property name="hexpand">false</property>
<property name="visible">true</property>
<property name="xalign">0.0</property>
<property name="use-markup">true</property>
<property name="ellipsize">end</property>
<style>
<class name="title"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="separator">
<property name="hexpand">false</property>
<property name="label"></property>
<property name="visible">true</property>
<style>
<class name="separator"/>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="subtitle">
<property name="hexpand">true</property>
<property name="visible">true</property>
<property name="xalign">0.0</property>
<property name="use-markup">true</property>
<property name="ellipsize">end</property>
<style>
<class name="dim-label"/>
<class name="subtitle"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment