[libhandy/wip/haecker-felix/flap-widget] Refactoring
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/wip/haecker-felix/flap-widget] Refactoring
- Date: Tue, 17 Nov 2020 11:12:52 +0000 (UTC)
commit c3e712f09d29300afbdd78c0628696a4b973f413
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Nov 17 15:55:30 2020 +0500
Refactoring
src/hdy-flap.c | 68 ++++++++++++++++++++++++++++------------------------------
1 file changed, 33 insertions(+), 35 deletions(-)
---
diff --git a/src/hdy-flap.c b/src/hdy-flap.c
index 616f4ba0..00309ec4 100644
--- a/src/hdy-flap.c
+++ b/src/hdy-flap.c
@@ -84,7 +84,8 @@ update_swipe_tracker (HdyFlap *self)
reverse = !reverse;
hdy_swipe_tracker_set_reversed (self->tracker, reverse);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (self->tracker), self->orientation);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (self->tracker),
+ self->orientation);
}
static void
@@ -181,16 +182,6 @@ adjust_for_overlay (HdyFlap *self,
return (gint) round (value * progress);
}
-static GtkPackType
-adjust_for_text_direction (HdyFlap *self,
- GtkPackType pack_type)
-{
- if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
- return (pack_type == GTK_PACK_START) ? GTK_PACK_END : GTK_PACK_START;
-
- return pack_type;
-}
-
static void
begin_swipe_cb (HdySwipeTracker *tracker,
HdyNavigationDirection direction,
@@ -286,22 +277,23 @@ 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 = widget_alloc->x;
gint flap_y = widget_alloc->y;
+ gint flap_size = get_flap_size (self, widget_alloc, self->orientation);
if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
-
- if (self->flap_position == adjust_for_text_direction (self, GTK_PACK_START))
- flap_x -= (gint) round (get_flap_size (self, widget_alloc, GTK_ORIENTATION_HORIZONTAL) * (1 -
self->reveal_progress));
+ if (self->flap_position == start_or_end)
+ flap_x -= (gint) round (flap_size * (1 - self->reveal_progress));
else
- flap_x = widget_alloc->width - (gint) round (get_flap_size (self, widget_alloc,
GTK_ORIENTATION_HORIZONTAL) * self->reveal_progress);
- }
-
- if (self->orientation == GTK_ORIENTATION_VERTICAL) {
+ flap_x = widget_alloc->width - (gint) round (flap_size * self->reveal_progress);
+ } else {
if (self->flap_position == GTK_PACK_START)
- flap_y -= (gint) round (get_flap_size (self, widget_alloc, GTK_ORIENTATION_VERTICAL) * (1 -
self->reveal_progress));
+ flap_y -= (gint) round (flap_size * (1 - self->reveal_progress));
else
- flap_y = widget_alloc->height - (gint) round (get_flap_size (self, widget_alloc,
GTK_ORIENTATION_VERTICAL) * self->reveal_progress);
+ flap_y = widget_alloc->height - (gint) round (flap_size * self->reveal_progress);
}
gtk_widget_set_child_visible (self->flap, self->reveal_progress > 0);
@@ -320,13 +312,16 @@ allocate_flap (HdyFlap *self,
static void
allocate_content (HdyFlap *self,
- GtkAllocation *widget_alloc)
+ GtkAllocation *alloc)
{
GtkWidget *content = gtk_bin_get_child (GTK_BIN (self));
+ 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;
- GtkAllocation alloc;
+ GtkAllocation child_alloc;
if (self->flap) {
gtk_widget_get_preferred_size (self->flap, &flap_min, &flap_nat);
@@ -337,33 +332,33 @@ allocate_content (HdyFlap *self,
gtk_widget_get_preferred_size (content, &content_min, &content_nat);
- content_x = widget_alloc->x;
- content_y = widget_alloc->y;
+ content_x = alloc->x;
+ content_y = alloc->y;
if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
gint min = content_min.width + flap_min.width;
if (self->fold_policy == HDY_FLAP_FOLD_POLICY_AUTO)
- set_folded (self, widget_alloc->width <= min);
+ set_folded (self, alloc->width <= min);
- if (self->flap_position == adjust_for_text_direction (self, GTK_PACK_START))
- content_x += adjust_for_overlay (self, get_flap_size (self, widget_alloc, GTK_ORIENTATION_HORIZONTAL));
+ if (self->flap_position == start_or_end)
+ content_x += adjust_for_overlay (self, get_flap_size (self, alloc, self->orientation));
} else {
gint min = content_min.height + flap_min.height;
if (self->fold_policy == HDY_FLAP_FOLD_POLICY_AUTO)
- set_folded (self, widget_alloc->height <= min);
+ set_folded (self, alloc->height <= min);
if (self->flap_position == GTK_PACK_START)
- content_y += adjust_for_overlay (self, get_flap_size (self, widget_alloc, GTK_ORIENTATION_VERTICAL));
+ content_y += adjust_for_overlay (self, get_flap_size (self, alloc, self->orientation));
}
- alloc.x = content_x;
- alloc.y = content_y;
- alloc.width = get_content_size (self, widget_alloc, GTK_ORIENTATION_HORIZONTAL);
- alloc.height = get_content_size (self, widget_alloc, GTK_ORIENTATION_VERTICAL);
+ child_alloc.x = content_x;
+ child_alloc.y = content_y;
+ child_alloc.width = get_content_size (self, alloc, GTK_ORIENTATION_HORIZONTAL);
+ child_alloc.height = get_content_size (self, alloc, GTK_ORIENTATION_VERTICAL);
- gtk_widget_size_allocate (content, &alloc);
+ gtk_widget_size_allocate (content, &child_alloc);
}
static void
@@ -496,6 +491,9 @@ 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;
@@ -516,7 +514,7 @@ hdy_flap_draw (GtkWidget *widget,
} else {
gint flap_width = gtk_widget_get_allocated_width (self->flap);
- if (self->flap_position == adjust_for_text_direction (self, GTK_PACK_START)) {
+ if (self->flap_position == start_or_end) {
shadow_direction = GTK_PAN_DIRECTION_LEFT;
shadow_x = flap_width * self->reveal_progress;
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]