[libhandy/wip/haecker-felix/flap-widget] Swipe area
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/wip/haecker-felix/flap-widget] Swipe area
- Date: Tue, 17 Nov 2020 22:40:06 +0000 (UTC)
commit 1c07230c1492a868c1509ba7011284a8216fd66e
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Nov 18 03:39:49 2020 +0500
Swipe area
src/hdy-flap.c | 70 ++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 54 insertions(+), 16 deletions(-)
---
diff --git a/src/hdy-flap.c b/src/hdy-flap.c
index 17b8fa0e..18f57545 100644
--- a/src/hdy-flap.c
+++ b/src/hdy-flap.c
@@ -32,6 +32,8 @@
* in a #HdyFlap widget.
*/
+#define HDY_SWIPE_BORDER 16
+
struct _HdyFlap
{
GtkContainer parent_instance;
@@ -311,14 +313,15 @@ static void
allocate_flap (HdyFlap *self,
GtkAllocation *widget_alloc)
{
- GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (self));
- gboolean is_rtl = direction == GTK_TEXT_DIR_RTL;
- GtkPackType start_or_end = is_rtl ? GTK_PACK_END : GTK_PACK_START;
gint flap_x = 0;
gint flap_y = 0;
gint flap_size = get_flap_size (self, widget_alloc, self->orientation);
if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
+ GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (self));
+ gboolean is_rtl = direction == GTK_TEXT_DIR_RTL;
+ GtkPackType start_or_end = is_rtl ? GTK_PACK_END : GTK_PACK_START;
+
if (self->flap_position == start_or_end)
flap_x = (gint) round (flap_size * (self->reveal_progress - 1));
else
@@ -348,9 +351,6 @@ static void
allocate_content (HdyFlap *self,
GtkAllocation *alloc)
{
- GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (self));
- gboolean is_rtl = direction == GTK_TEXT_DIR_RTL;
- GtkPackType start_or_end = is_rtl ? GTK_PACK_END : GTK_PACK_START;
gint content_x = 0, content_y = 0;
GtkRequisition flap_min, flap_nat;
GtkRequisition content_min, content_nat;
@@ -369,6 +369,9 @@ allocate_content (HdyFlap *self,
content_y = 0;
if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
+ GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (self));
+ gboolean is_rtl = direction == GTK_TEXT_DIR_RTL;
+ GtkPackType start_or_end = is_rtl ? GTK_PACK_END : GTK_PACK_START;
gint min = content_min.width + flap_min.width;
if (self->fold_policy == HDY_FLAP_FOLD_POLICY_AUTO)
@@ -526,9 +529,6 @@ hdy_flap_draw (GtkWidget *widget,
cairo_t *cr)
{
HdyFlap *self = HDY_FLAP (widget);
- GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (self));
- gboolean is_rtl = direction == GTK_TEXT_DIR_RTL;
- GtkPackType start_or_end = is_rtl ? GTK_PACK_END : GTK_PACK_START;
gint width, height;
gint shadow_x = 0, shadow_y = 0;
GtkPanDirection shadow_direction;
@@ -547,6 +547,9 @@ hdy_flap_draw (GtkWidget *widget,
shadow_y = -flap_height * self->reveal_progress;
}
} else {
+ GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (self));
+ gboolean is_rtl = direction == GTK_TEXT_DIR_RTL;
+ GtkPackType start_or_end = is_rtl ? GTK_PACK_END : GTK_PACK_START;
gint flap_width = gtk_widget_get_allocated_width (self->flap);
if (self->flap_position == start_or_end) {
@@ -1008,7 +1011,7 @@ hdy_flap_get_cancel_progress (HdySwipeable *swipeable)
return round (self->reveal_progress);
}
-/*
+
static void
hdy_flap_get_swipe_area (HdySwipeable *swipeable,
HdyNavigationDirection navigation_direction,
@@ -1016,19 +1019,54 @@ hdy_flap_get_swipe_area (HdySwipeable *swipeable,
GdkRectangle *rect)
{
HdyFlap *self = HDY_FLAP (swipeable);
+ GtkAllocation alloc;
gint width, height;
+ rect->x = 0;
+ rect->y = 0;
+
if (!self->flap) {
- rect->x = 0;
- rect->y = 0;
rect->width = 0;
rect->height = 0;
+
+ return;
}
- rect->width = gtk_widget_get_allocated_width (self->flap);
- rect->height = gtk_widget_get_allocated_height (self->flap);
+ width = gtk_widget_get_allocated_width (GTK_WIDGET (self));
+ height = gtk_widget_get_allocated_height (GTK_WIDGET (self));
+
+ gtk_widget_get_allocation (self->flap, &alloc);
+
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
+ GtkTextDirection direction = gtk_widget_get_direction (GTK_WIDGET (self));
+ gboolean is_rtl = direction == GTK_TEXT_DIR_RTL;
+ GtkPackType start_or_end = is_rtl ? GTK_PACK_END : GTK_PACK_START;
+
+ if (self->flap_position == start_or_end) {
+ rect->x = 0;
+ rect->width = MAX (alloc.x + alloc.width, HDY_SWIPE_BORDER);
+ } else {
+ rect->x = MIN (alloc.x, width - HDY_SWIPE_BORDER);
+ rect->width = width - rect->x;
+ g_print ("A %d %d\n", rect->x, rect->width);
+ }
+
+ rect->y = alloc.y;
+ rect->height = alloc.height;
+ } else {
+ if (self->flap_position == GTK_PACK_START) {
+ rect->y = 0;
+ rect->height = MAX (alloc.y + alloc.height, HDY_SWIPE_BORDER);
+ } else {
+ rect->y = MIN (alloc.y, height - HDY_SWIPE_BORDER);
+ rect->height = height - rect->y;
+ }
+
+ rect->x = alloc.x;
+ rect->width = alloc.width;
+ }
}
-*/
+
static void
hdy_flap_swipeable_init (HdySwipeableInterface *iface)
{
@@ -1038,7 +1076,7 @@ hdy_flap_swipeable_init (HdySwipeableInterface *iface)
iface->get_snap_points = hdy_flap_get_snap_points;
iface->get_progress = hdy_flap_get_progress;
iface->get_cancel_progress = hdy_flap_get_cancel_progress;
-// iface->get_swipe_area = hdy_flap_get_swipe_area;
+ iface->get_swipe_area = hdy_flap_get_swipe_area;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]