Line data Source code
1 : /* File: gui_button.inl; Copyright and License: see below */
2 :
3 0 : static inline void gui_button_init( gui_button_t *this_,
4 : GdkPaintable * icon_source,
5 : const char *label_text,
6 : const char *tooltip_text )
7 : {
8 0 : (*this_).icon = GTK_IMAGE( gtk_image_new_from_paintable( icon_source ) );
9 0 : gtk_widget_set_size_request( GTK_WIDGET((*this_).icon), 32 /*=w*/ , 32 /*=h*/ );
10 :
11 : /*
12 : utf8stream_writemem_t css_out;
13 : utf8stream_writemem_init( &css_out, css_buf, sizeof(css_buf) );
14 : utf8stream_writer_t *css_in = utf8stream_writemem_get_writer( &css_out );
15 : u8_error_t write_err = U8_ERROR_NONE;
16 : write_err |= utf8stream_writer_write_str( &css_in, "<small>" );
17 : write_err |= utf8stream_writer_write_str( &css_in, label_text );
18 : write_err |= utf8stream_writer_write_str( &css_in, "</small>" );
19 : write_err |= utf8stream_writer_flush( &css_in );
20 : utf8stream_writemem_destroy( &css_out );
21 : */
22 0 : char css_buf[48] = "";
23 0 : utf8stringbuf_t css = UTF8STRINGBUF( css_buf );
24 0 : utf8stringbuf_append_str( &css, "<small>" );
25 0 : utf8stringbuf_append_str( &css, label_text );
26 0 : utf8stringbuf_append_str( &css, "</small>" );
27 :
28 0 : (*this_).label = GTK_LABEL( gtk_label_new( NULL ) );
29 0 : gtk_label_set_markup( (*this_).label, utf8stringbuf_get_string( &css ) );
30 :
31 0 : (*this_).box = GTK_BOX( gtk_box_new( GTK_ORIENTATION_VERTICAL, 4 /* spacing */ ) );
32 0 : gtk_box_append( (*this_).box, GTK_WIDGET((*this_).icon) );
33 0 : gtk_box_append( (*this_).box, GTK_WIDGET((*this_).label) );
34 :
35 0 : (*this_).button = GTK_BUTTON( gtk_button_new() );
36 0 : gtk_button_set_child( (*this_).button, GTK_WIDGET((*this_).box) );
37 :
38 0 : gtk_widget_set_tooltip_text( GTK_WIDGET((*this_).button), tooltip_text );
39 :
40 : /* increase the reference counter to keep the button and its children alive */
41 : /* g_object_ref( (*this_).button ); */
42 0 : }
43 :
44 0 : static inline void gui_button_init_toggle( gui_button_t *this_,
45 : GdkPaintable * icon_source,
46 : const char *label_text,
47 : const char *tooltip_text )
48 : {
49 0 : (*this_).icon = GTK_IMAGE( gtk_image_new_from_paintable( icon_source ) );
50 0 : gtk_widget_set_size_request( GTK_WIDGET((*this_).icon), 32 /*=w*/ , 32 /*=h*/ );
51 :
52 0 : char css_buf[48] = "";
53 0 : utf8stringbuf_t css = UTF8STRINGBUF( css_buf );
54 0 : utf8stringbuf_append_str( &css, "<small>" );
55 0 : utf8stringbuf_append_str( &css, label_text );
56 0 : utf8stringbuf_append_str( &css, "</small>" );
57 :
58 0 : (*this_).label = GTK_LABEL( gtk_label_new( NULL ) );
59 0 : gtk_label_set_markup( (*this_).label, utf8stringbuf_get_string( &css ) );
60 :
61 0 : (*this_).box = GTK_BOX( gtk_box_new( GTK_ORIENTATION_VERTICAL, 2 /* spacing */ ) );
62 0 : gtk_box_append( (*this_).box, GTK_WIDGET((*this_).icon) );
63 0 : gtk_box_append( (*this_).box, GTK_WIDGET((*this_).label) );
64 :
65 0 : (*this_).button = GTK_BUTTON( gtk_toggle_button_new() );
66 0 : gtk_button_set_child( (*this_).button, GTK_WIDGET((*this_).box) );
67 :
68 0 : gtk_widget_set_tooltip_text( GTK_WIDGET((*this_).button), tooltip_text );
69 :
70 : /* increase the reference counter to keep the button and its children alive */
71 : /* g_object_ref( (*this_).button ); */
72 0 : }
73 :
74 0 : static inline void gui_button_destroy ( gui_button_t *this_ )
75 : {
76 : /* decrease the reference counter to allow the button and its children to be deleted */
77 : /* g_object_unref( (*this_).button ); */
78 0 : }
79 :
80 0 : static inline GtkImage * gui_button_get_icon_ptr ( const gui_button_t *this_ )
81 : {
82 0 : return (*this_).icon;
83 : }
84 :
85 : static inline GtkLabel * gui_button_get_label_ptr ( const gui_button_t *this_ )
86 : {
87 : return (*this_).label;
88 : }
89 :
90 0 : static inline GtkButton * gui_button_get_button_ptr ( const gui_button_t *this_ )
91 : {
92 0 : return GTK_BUTTON((*this_).button);
93 : }
94 :
95 0 : static inline GtkWidget * gui_button_get_widget_ptr ( const gui_button_t *this_ )
96 : {
97 0 : return GTK_WIDGET((*this_).button);
98 : }
99 :
100 :
101 : /*
102 : Copyright 2024-2025 Andreas Warnke
103 :
104 : Licensed under the Apache License, Version 2.0 (the "License");
105 : you may not use this file except in compliance with the License.
106 : You may obtain a copy of the License at
107 :
108 : http://www.apache.org/licenses/LICENSE-2.0
109 :
110 : Unless required by applicable law or agreed to in writing, software
111 : distributed under the License is distributed on an "AS IS" BASIS,
112 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113 : See the License for the specific language governing permissions and
114 : limitations under the License.
115 : */
|