[gnome-builder/wip/gtk4-port: 782/1774] libide/tree: add interface for popup positioning
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 782/1774] libide/tree: add interface for popup positioning
- Date: Mon, 11 Jul 2022 22:31:23 +0000 (UTC)
commit 2e234e024074c756a034652d25aba21e95bfcad2
Author: Christian Hergert <chergert redhat com>
Date: Wed Apr 27 16:28:48 2022 -0700
libide/tree: add interface for popup positioning
We can implement this in the workspace so we can position dynamic popovers
from things like treeviews.
src/libide/tree/ide-popover-positioner.c | 56 ++++++++++++++++++++++++++++++++
src/libide/tree/ide-popover-positioner.h | 50 ++++++++++++++++++++++++++++
src/libide/tree/ide-tree.h | 1 +
src/libide/tree/libide-tree.h | 11 +++----
src/libide/tree/meson.build | 2 ++
5 files changed, 114 insertions(+), 6 deletions(-)
---
diff --git a/src/libide/tree/ide-popover-positioner.c b/src/libide/tree/ide-popover-positioner.c
new file mode 100644
index 000000000..637061f5c
--- /dev/null
+++ b/src/libide/tree/ide-popover-positioner.c
@@ -0,0 +1,56 @@
+/* ide-popover-positioner.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-popover-positioner"
+
+#include "config.h"
+
+#include "ide-popover-positioner.h"
+
+G_DEFINE_INTERFACE (IdePopoverPositioner, ide_popover_positioner, GTK_TYPE_WIDGET)
+
+static void
+ide_popover_positioner_default_init (IdePopoverPositionerInterface *iface)
+{
+}
+
+void
+ide_popover_positioner_present (IdePopoverPositioner *self,
+ GtkPopover *popover,
+ GtkWidget *relative_to,
+ const GdkRectangle *pointing_at)
+{
+ GdkRectangle empty;
+
+ g_return_if_fail (IDE_IS_POPOVER_POSITIONER (self));
+ g_return_if_fail (GTK_IS_POPOVER (popover));
+ g_return_if_fail (GTK_IS_WIDGET (relative_to));
+
+ if (pointing_at == NULL)
+ {
+ empty.x = 0;
+ empty.y = 0;
+ empty.width = gtk_widget_get_width (relative_to);
+ empty.height = gtk_widget_get_height (relative_to);
+ pointing_at = ∅
+ }
+
+ IDE_POPOVER_POSITIONER_GET_IFACE (self)->present (self, popover, relative_to, pointing_at);
+}
diff --git a/src/libide/tree/ide-popover-positioner.h b/src/libide/tree/ide-popover-positioner.h
new file mode 100644
index 000000000..ac76e4a4e
--- /dev/null
+++ b/src/libide/tree/ide-popover-positioner.h
@@ -0,0 +1,50 @@
+/* ide-popover-positioner.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_POPOVER_POSITIONER (ide_popover_positioner_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_INTERFACE (IdePopoverPositioner, ide_popover_positioner, IDE, POPOVER_POSITIONER, GtkWidget)
+
+struct _IdePopoverPositionerInterface
+{
+ GTypeInterface parent_iface;
+
+ void (*present) (IdePopoverPositioner *self,
+ GtkPopover *popover,
+ GtkWidget *relative_to,
+ const GdkRectangle *pointing_to);
+};
+
+IDE_AVAILABLE_IN_ALL
+void ide_popover_positioner_present (IdePopoverPositioner *self,
+ GtkPopover *popover,
+ GtkWidget *relative_to,
+ const GdkRectangle *pointing_to);
+
+G_END_DECLS
diff --git a/src/libide/tree/ide-tree.h b/src/libide/tree/ide-tree.h
index ef4f045e4..c9e3d8a51 100644
--- a/src/libide/tree/ide-tree.h
+++ b/src/libide/tree/ide-tree.h
@@ -21,6 +21,7 @@
#pragma once
#include <gtk/gtk.h>
+
#include <libide-core.h>
#include "ide-tree-node.h"
diff --git a/src/libide/tree/libide-tree.h b/src/libide/tree/libide-tree.h
index 515828d11..be4915a14 100644
--- a/src/libide/tree/libide-tree.h
+++ b/src/libide/tree/libide-tree.h
@@ -25,12 +25,11 @@
G_BEGIN_DECLS
#define IDE_TREE_INSIDE
-
-#include "ide-tree.h"
-#include "ide-tree-addin.h"
-#include "ide-tree-model.h"
-#include "ide-tree-node.h"
-
+# include "ide-popover-positioner.h"
+# include "ide-tree.h"
+# include "ide-tree-addin.h"
+# include "ide-tree-model.h"
+# include "ide-tree-node.h"
#undef IDE_TREE_INSIDE
G_END_DECLS
diff --git a/src/libide/tree/meson.build b/src/libide/tree/meson.build
index 5a591106c..d0a99b73d 100644
--- a/src/libide/tree/meson.build
+++ b/src/libide/tree/meson.build
@@ -6,6 +6,7 @@ libide_include_directories += include_directories('.')
#
libide_tree_public_headers = [
+ 'ide-popover-positioner.h',
'ide-tree.h',
'ide-tree-addin.h',
'ide-tree-model.h',
@@ -20,6 +21,7 @@ install_headers(libide_tree_public_headers, subdir: libide_tree_header_subdir)
#
libide_tree_public_sources = [
+ 'ide-popover-positioner.c',
'ide-tree.c',
'ide-tree-addin.c',
'ide-tree-model.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]