Debian Codegraph @

phoenix/gtk/widget/button.cpp

raw
1 namespace phoenix {
2
3 static void Button_activate(Button* self) {
4 if(self->onActivate) self->onActivate();
5 }
6
7 Size pButton::minimumSize() {
8 Size size = pFont::size(widget.state.font, button.state.text);
9
10 if(button.state.orientation == Orientation::Horizontal) {
11 size.width += button.state.image.width;
12 size.height = max(button.state.image.height, size.height);
13 }
14
15 if(button.state.orientation == Orientation::Vertical) {
16 size.width = max(button.state.image.width, size.width);
17 size.height += button.state.image.height;
18 }
19
20 return {size.width + 24, size.height + 12};
21 }
22
23 void pButton::setImage(const image& image, Orientation orientation) {
24 if(image.empty() == false) {
25 GtkImage* gtkImage = CreateImage(image);
26 gtk_button_set_image(GTK_BUTTON(gtkWidget), (GtkWidget*)gtkImage);
27 } else {
28 gtk_button_set_image(GTK_BUTTON(gtkWidget), nullptr);
29 }
30 switch(orientation) {
31 case Orientation::Horizontal: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_LEFT); break;
32 case Orientation::Vertical: gtk_button_set_image_position(GTK_BUTTON(gtkWidget), GTK_POS_TOP); break;
33 }
34 }
35
36 void pButton::setText(string text) {
37 gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
38 setFont(widget.state.font);
39 }
40
41 void pButton::constructor() {
42 gtkWidget = gtk_button_new();
43 g_signal_connect_swapped(G_OBJECT(gtkWidget), "clicked", G_CALLBACK(Button_activate), (gpointer)&button);
44
45 setText(button.state.text);
46 }
47
48 void pButton::destructor() {
49 gtk_widget_destroy(gtkWidget);
50 }
51
52 void pButton::orphan() {
53 destructor();
54 constructor();
55 }
56
57 }