1 /*
2 * Copyright (C) 2019-2020 Alexandros Theodotou <alex at zrythm dot org>
3 *
4 * This file is part of Zrythm
5 *
6 * Zrythm is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Zrythm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 /**
21 * \file
22 *
23 * Expander box.
24 */
25
26 #ifndef __GUI_WIDGETS_EXPANDER_BOX_H__
27 #define __GUI_WIDGETS_EXPANDER_BOX_H__
28
29 #include <stdbool.h>
30
31 #include "utils/resources.h"
32
33 #include <gtk/gtk.h>
34
35 #define EXPANDER_BOX_WIDGET_TYPE \
36 (expander_box_widget_get_type ())
37 G_DECLARE_DERIVABLE_TYPE (
38 ExpanderBoxWidget,
39 expander_box_widget,
40 Z, EXPANDER_BOX_WIDGET,
41 GtkBox)
42
43 /**
44 * @addtogroup widgets
45 *
46 * @{
47 */
48
49 /**
50 * Reveal callback prototype.
51 */
52 typedef void (*ExpanderBoxRevealFunc) (
53 ExpanderBoxWidget * expander_box,
54 bool revealed,
55 void * user_data);
56
57 /**
58 * An expander box is a base widget with a button that
59 * when clicked expands the contents.
60 */
61 typedef struct
62 {
63 GtkButton * button;
64 GtkBox * btn_box;
65 GtkLabel * btn_label;
66 GtkImage * btn_img;
67 GtkRevealer * revealer;
68 GtkBox * content;
69
70 /** Horizontal or vertical. */
71 GtkOrientation orientation;
72
73 ExpanderBoxRevealFunc reveal_cb;
74
75 void * user_data;
76
77 } ExpanderBoxWidgetPrivate;
78
79 typedef struct _ExpanderBoxWidgetClass
80 {
81 GtkBoxClass parent_class;
82 } ExpanderBoxWidgetClass;
83
84 /**
85 * Gets the private.
86 */
87 ExpanderBoxWidgetPrivate *
88 expander_box_widget_get_private (
89 ExpanderBoxWidget * self);
90
91 /**
92 * Sets the label to show.
93 */
94 void
95 expander_box_widget_set_label (
96 ExpanderBoxWidget * self,
97 const char * label);
98
99 /**
100 * Sets the icon name to show.
101 */
102 void
103 expander_box_widget_set_icon_name (
104 ExpanderBoxWidget * self,
105 const char * icon_name);
106
107 /**
108 * Sets the icon resource to show.
109 */
110 static inline void
expander_box_widget_set_icon_resource(ExpanderBoxWidget * self,IconType icon_type,const char * path)111 expander_box_widget_set_icon_resource (
112 ExpanderBoxWidget * self,
113 IconType icon_type,
114 const char * path)
115 {
116 ExpanderBoxWidgetPrivate * prv =
117 expander_box_widget_get_private (self);
118
119 resources_set_image_icon (
120 prv->btn_img,
121 icon_type,
122 path);
123 }
124
125 static inline void
expander_box_widget_add_content(ExpanderBoxWidget * self,GtkWidget * content)126 expander_box_widget_add_content (
127 ExpanderBoxWidget * self,
128 GtkWidget * content)
129 {
130 ExpanderBoxWidgetPrivate * prv =
131 expander_box_widget_get_private (self);
132 gtk_container_add (
133 GTK_CONTAINER (prv->content),
134 content);
135 }
136
137 /**
138 * Reveals or hides the expander box's contents.
139 */
140 void
141 expander_box_widget_set_reveal (
142 ExpanderBoxWidget * self,
143 int reveal);
144
145 void
146 expander_box_widget_set_reveal_callback (
147 ExpanderBoxWidget * self,
148 ExpanderBoxRevealFunc cb,
149 void * user_data);
150
151 void
152 expander_box_widget_set_orientation (
153 ExpanderBoxWidget * self,
154 GtkOrientation orientation);
155
156 void
157 expander_box_widget_set_vexpand (
158 ExpanderBoxWidget * self,
159 bool expand);
160
161 ExpanderBoxWidget *
162 expander_box_widget_new (
163 const char * label,
164 const char * icon_name,
165 GtkOrientation orientation);
166
167 /**
168 * @}
169 */
170
171 #endif
172