| 1 |
#if defined(Hiro_Button) |
| 2 |
|
| 3 |
namespace hiro { |
| 4 |
|
| 5 |
static auto Button_activate(GtkButton* gtkButton, pButton* p) -> void { p->_doActivate(); } |
| 6 |
|
| 7 |
auto pButton::construct() -> void { |
| 8 |
gtkWidget = gtk_button_new(); |
| 9 |
gtkButton = GTK_BUTTON(gtkWidget); |
| 10 |
|
| 11 |
setBordered(state().bordered); |
| 12 |
setIcon(state().icon); |
| 13 |
setOrientation(state().orientation); |
| 14 |
setText(state().text); |
| 15 |
|
| 16 |
g_signal_connect(G_OBJECT(gtkButton), "clicked", G_CALLBACK(Button_activate), (gpointer)this); |
| 17 |
|
| 18 |
pWidget::construct(); |
| 19 |
} |
| 20 |
|
| 21 |
auto pButton::destruct() -> void { |
| 22 |
gtk_widget_destroy(gtkWidget); |
| 23 |
} |
| 24 |
|
| 25 |
auto pButton::minimumSize() const -> Size { |
| 26 |
Size size = pFont::size(self().font(true), state().text); |
| 27 |
|
| 28 |
if(state().orientation == Orientation::Horizontal) { |
| 29 |
size.setWidth(size.width() + state().icon.width()); |
| 30 |
size.setHeight(max(size.height(), state().icon.height())); |
| 31 |
} |
| 32 |
|
| 33 |
if(state().orientation == Orientation::Vertical) { |
| 34 |
size.setWidth(max(size.width(), state().icon.width())); |
| 35 |
size.setHeight(size.height() + state().icon.height()); |
| 36 |
} |
| 37 |
|
| 38 |
return {size.width() + (state().text ? 24 : 12), size.height() + 12}; |
| 39 |
} |
| 40 |
|
| 41 |
auto pButton::setBordered(bool bordered) -> void { |
| 42 |
gtk_button_set_relief(gtkButton, bordered ? GTK_RELIEF_NORMAL : GTK_RELIEF_NONE); |
| 43 |
} |
| 44 |
|
| 45 |
auto pButton::setIcon(const image& icon) -> void { |
| 46 |
if(icon) { |
| 47 |
auto gtkImage = CreateImage(icon); |
| 48 |
gtk_button_set_image(gtkButton, (GtkWidget*)gtkImage); |
| 49 |
} else { |
| 50 |
gtk_button_set_image(gtkButton, nullptr); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
auto pButton::setOrientation(Orientation orientation) -> void { |
| 55 |
switch(orientation) { |
| 56 |
case Orientation::Horizontal: gtk_button_set_image_position(gtkButton, GTK_POS_LEFT); break; |
| 57 |
case Orientation::Vertical: gtk_button_set_image_position(gtkButton, GTK_POS_TOP); break; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
auto pButton::setText(const string& text) -> void { |
| 62 |
gtk_button_set_label(gtkButton, text); |
| 63 |
setFont(self().font(true)); //gtk_button_set_label() recreates label, which destroys currently assigned font |
| 64 |
} |
| 65 |
|
| 66 |
auto pButton::_doActivate() -> void { |
| 67 |
self().doActivate(); |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
#endif |