summaryrefslogtreecommitdiff
path: root/csrc/widgets/panel/panel-item-icon.c
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-06-19 23:17:58 +0200
committerHannes Schulze <haschu0103@outlook.de>2025-06-19 23:17:58 +0200
commit1af3d14f3f995645a0de08a54b244c19840709e9 (patch)
tree3c4098863d8a8fd004a2acc8912a23b6036ab4dd /csrc/widgets/panel/panel-item-icon.c
parent40efcf60a5f39674b5137f11de7bcfe37fb121b5 (diff)
init hs project
Diffstat (limited to 'csrc/widgets/panel/panel-item-icon.c')
-rw-r--r--csrc/widgets/panel/panel-item-icon.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/csrc/widgets/panel/panel-item-icon.c b/csrc/widgets/panel/panel-item-icon.c
new file mode 100644
index 0000000..0a3b4e9
--- /dev/null
+++ b/csrc/widgets/panel/panel-item-icon.c
@@ -0,0 +1,92 @@
+#include "widgets/panel/panel-item-icon.h"
+
+//
+// FoobarPanelItemIcon:
+//
+// Simple item implementation displaying an icon.
+//
+
+struct _FoobarPanelItemIcon
+{
+ FoobarPanelItem parent_instance;
+ GtkWidget* button;
+ FoobarPanelItemAction action;
+};
+
+static void foobar_panel_item_icon_class_init ( FoobarPanelItemIconClass* klass );
+static void foobar_panel_item_icon_init ( FoobarPanelItemIcon* self );
+static void foobar_panel_item_icon_handle_clicked( GtkButton* button,
+ gpointer userdata );
+
+G_DEFINE_FINAL_TYPE( FoobarPanelItemIcon, foobar_panel_item_icon, FOOBAR_TYPE_PANEL_ITEM )
+
+// ---------------------------------------------------------------------------------------------------------------------
+// Panel Item Implementation
+// ---------------------------------------------------------------------------------------------------------------------
+
+//
+// Static initialization for icon panel items.
+//
+void foobar_panel_item_icon_class_init( FoobarPanelItemIconClass* klass )
+{
+ (void)klass;
+}
+
+//
+// Instance initialization for icon panel items.
+//
+void foobar_panel_item_icon_init( FoobarPanelItemIcon* self )
+{
+ self->button = gtk_button_new( );
+ gtk_button_set_has_frame( GTK_BUTTON( self->button ), FALSE );
+ gtk_widget_set_halign( self->button, GTK_ALIGN_CENTER );
+ gtk_widget_set_valign( self->button, GTK_ALIGN_CENTER );
+ g_signal_connect(
+ self->button,
+ "clicked",
+ G_CALLBACK( foobar_panel_item_icon_handle_clicked ),
+ self );
+
+ gtk_widget_add_css_class( GTK_WIDGET( self ), "icon" );
+ foobar_panel_item_set_child( FOOBAR_PANEL_ITEM( self ), self->button );
+}
+
+// ---------------------------------------------------------------------------------------------------------------------
+// Public API
+// ---------------------------------------------------------------------------------------------------------------------
+
+//
+// Create a new icon panel item with the given configuration.
+//
+FoobarPanelItem* foobar_panel_item_icon_new( FoobarPanelItemConfiguration const* config )
+{
+ g_return_val_if_fail( config != NULL, NULL );
+ g_return_val_if_fail( foobar_panel_item_configuration_get_kind( config ) == FOOBAR_PANEL_ITEM_KIND_ICON, NULL );
+
+ FoobarPanelItemIcon* self = g_object_new( FOOBAR_TYPE_PANEL_ITEM_ICON, NULL );
+ self->action = foobar_panel_item_configuration_get_action( config );
+
+ gtk_widget_set_sensitive( self->button, self->action != FOOBAR_PANEL_ITEM_ACTION_NONE );
+ gtk_button_set_icon_name(
+ GTK_BUTTON( self->button ),
+ foobar_panel_item_icon_configuration_get_icon_name( config ) );
+
+ return FOOBAR_PANEL_ITEM( self );
+}
+
+// ---------------------------------------------------------------------------------------------------------------------
+// Signal Handlers
+// ---------------------------------------------------------------------------------------------------------------------
+
+//
+// Called when the button was clicked.
+//
+void foobar_panel_item_icon_handle_clicked(
+ GtkButton* button,
+ gpointer userdata )
+{
+ (void)button;
+ FoobarPanelItemIcon* self = (FoobarPanelItemIcon*)userdata;
+
+ foobar_panel_item_invoke_action( FOOBAR_PANEL_ITEM( self ), self->action );
+}