[gnome-builder/wip/gtk4-port: 507/736] libide/gui: add frame position helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 507/736] libide/gui: add frame position helper
- Date: Tue, 26 Apr 2022 01:46:29 +0000 (UTC)
commit ef5a53dcb3fbafd21231784e8ceca713458796f0
Author: Christian Hergert <chergert redhat com>
Date: Thu Apr 7 14:33:05 2022 -0700
libide/gui: add frame position helper
src/libide/gui/ide-frame.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++
src/libide/gui/ide-frame.h | 5 ++++-
2 files changed, 55 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/gui/ide-frame.c b/src/libide/gui/ide-frame.c
index 59c76c4ca..b54c6a5db 100644
--- a/src/libide/gui/ide-frame.c
+++ b/src/libide/gui/ide-frame.c
@@ -240,3 +240,54 @@ ide_frame_addin_find_by_module_name (IdeFrame *frame,
return ret ? IDE_FRAME_ADDIN (ret) : NULL;
}
+
+/**
+ * ide_frame_get_position:
+ * @self: a #IdeFrame
+ *
+ * Gets the position in the grid of a frame.
+ *
+ * Returns: (transfer full): a new #IdePanelPosition
+ */
+IdePanelPosition *
+ide_frame_get_position (IdeFrame *self)
+{
+ IdePanelPosition *ret;
+ PanelGrid *grid;
+ guint n_columns;
+
+ g_return_val_if_fail (IDE_IS_FRAME (self), NULL);
+
+ /* Frames are always in the center grid */
+ ret = ide_panel_position_new ();
+ ide_panel_position_set_edge (ret, PANEL_DOCK_POSITION_CENTER);
+
+ /* Implausible but handle it anyway */
+ grid = PANEL_GRID (gtk_widget_get_ancestor (GTK_WIDGET (self), PANEL_TYPE_GRID));
+ if (grid == NULL)
+ return ret;
+
+ n_columns = panel_grid_get_n_columns (grid);
+
+ for (guint c = 0; c < n_columns; c++)
+ {
+ PanelGridColumn *grid_column = panel_grid_get_column (grid, c);
+ guint n_rows = panel_grid_column_get_n_rows (grid_column);
+
+ for (guint r = 0; r < n_rows; r++)
+ {
+ PanelFrame *frame = panel_grid_column_get_row (grid_column, r);
+
+ if (frame == PANEL_FRAME (self))
+ {
+ ide_panel_position_set_column (ret, c);
+ ide_panel_position_set_row (ret, r);
+ return ret;
+ }
+ }
+ }
+
+ g_critical ("Failed to locate frame within grid");
+
+ return ret;
+}
diff --git a/src/libide/gui/ide-frame.h b/src/libide/gui/ide-frame.h
index 69bc349a8..ea2721779 100644
--- a/src/libide/gui/ide-frame.h
+++ b/src/libide/gui/ide-frame.h
@@ -27,6 +27,7 @@
#include <libpanel.h>
#include "ide-page.h"
+#include "ide-panel-position.h"
G_BEGIN_DECLS
@@ -36,6 +37,8 @@ IDE_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (IdeFrame, ide_frame, IDE, FRAME, PanelFrame)
IDE_AVAILABLE_IN_ALL
-GtkWidget *ide_frame_new (void);
+GtkWidget *ide_frame_new (void);
+IDE_AVAILABLE_IN_ALL
+IdePanelPosition *ide_frame_get_position (IdeFrame *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]