11/*
2- #define DEBUG
32 */
3+ #define DEBUG
44
55#include "vipsdisp.h"
66
77/* Duration of the GtkPaned enter/leave animations
88 */
99#define PANED_DURATION (0.5)
1010
11- /* The initial position of the GtkPaned separator. When revealed, the
12- * child needs to be visible even on the smallest displays. We don't want
13- * users to just see the separator on the far right of the window, since it
14- * might not be obvious what it is.
15- */
16- #define INITIAL_PANED_POSITION (200)
17-
1811struct _Animatedpane
1912{
2013 GtkWidget parent_instance ;
2114
2215 GtkWidget * paned ;
2316
24- // the state we expose via properties
17+ // right hand pane is visible
2518 gboolean revealed ;
19+
20+ // distance of the divider from the RIGHT edge of the window
2621 int position ;
2722
2823 // animation state.
@@ -113,12 +108,18 @@ animatedpaned_set_child_visibility( Animatedpane *animatedpane,
113108 gtk_widget_show ( child );
114109 else
115110 gtk_widget_hide ( child );
111+
116112}
117113
118114static void
119115animatedpaned_set_child_position ( Animatedpane * animatedpane , int position )
120116{
121- gtk_paned_set_position ( GTK_PANED ( animatedpane -> paned ), position );
117+ // our position is distance from the right edge -- we must swap this
118+ int widget_width = gtk_widget_get_width ( GTK_WIDGET ( animatedpane ) );
119+ int paned_position = widget_width - position ;
120+
121+ gtk_paned_set_position ( GTK_PANED ( animatedpane -> paned ),
122+ paned_position );
122123}
123124
124125/* From clutter-easing.c, based on Robert Penner's infamous easing equations,
@@ -144,9 +145,9 @@ animatedpane_animate_tick( GtkWidget *widget, GdkFrameClock *frame_clock,
144145 gint64 dt = animatedpane -> last_frame_time > 0 ?
145146 frame_time - animatedpane -> last_frame_time :
146147 0 ;
148+ animatedpane -> last_frame_time = frame_time ;
147149
148150 animatedpane -> elapsed += (double ) dt / G_TIME_SPAN_SECOND ;
149- animatedpane -> last_frame_time = frame_time ;
150151
151152 t = ease_out_cubic ( animatedpane -> elapsed / PANED_DURATION );
152153
@@ -189,16 +190,10 @@ animatedpaned_set_revealed( Animatedpane *animatedpane, gboolean revealed )
189190 animatedpane -> elapsed = 0.0 ;
190191 animatedpane -> is_animating = TRUE;
191192
192- if ( revealed ) {
193- animatedpane -> start =
194- gtk_widget_get_width ( GTK_WIDGET ( animatedpane ) );
195- animatedpane -> stop = animatedpane -> position ;
196- }
197- else {
198- animatedpane -> start = animatedpane -> position ;
199- animatedpane -> stop =
200- gtk_widget_get_width ( GTK_WIDGET ( animatedpane ) );
201- }
193+ animatedpane -> start = animatedpane -> position ;
194+ animatedpane -> stop = 0 ;
195+ if ( revealed )
196+ VIPS_SWAP ( int , animatedpane -> start , animatedpane -> stop );
202197
203198 animatedpaned_set_child_position ( animatedpane ,
204199 animatedpane -> start );
@@ -208,10 +203,9 @@ animatedpaned_set_revealed( Animatedpane *animatedpane, gboolean revealed )
208203
209204 gtk_widget_add_tick_callback ( GTK_WIDGET ( animatedpane ),
210205 animatedpane_animate_tick , NULL , NULL );
211- }
212- else {
213- animatedpaned_set_child_visibility ( animatedpane , revealed );
214206 }
207+ else
208+ animatedpaned_set_child_visibility ( animatedpane , revealed );
215209 }
216210}
217211
@@ -257,12 +251,14 @@ animatedpane_set_property( GObject *object,
257251}
258252#endif /*DEBUG*/
259253
260- // no need to implement set_position, the notify callback from the paned
261- // will do it
262-
263254 if ( prop_id == PROP_REVEALED )
264255 animatedpaned_set_revealed ( animatedpane ,
265256 g_value_get_boolean ( value ) );
257+ else if ( prop_id == PROP_POSITION ) {
258+ animatedpane -> position = g_value_get_int ( value );
259+ animatedpaned_set_child_position ( animatedpane ,
260+ animatedpane -> position );
261+ }
266262 else if ( prop_id < PROP_REVEALED )
267263 g_object_set_property ( G_OBJECT ( animatedpane -> paned ),
268264 prop_names [prop_id ], value );
@@ -313,12 +309,18 @@ animatedpane_position_notify( GtkWidget *paned,
313309 if ( animatedpane -> revealed &&
314310 !animatedpane -> is_animating ) {
315311 // FIXME ... could get from pspec?
316- animatedpane -> position = gtk_paned_get_position ( GTK_PANED ( paned ) );
312+ int paned_position = gtk_paned_get_position ( GTK_PANED ( paned ) );
313+
314+ // our position is distance from the right edge -- we must swap this
315+ int widget_width = gtk_widget_get_width ( GTK_WIDGET ( animatedpane ) );
316+ int position = widget_width - paned_position ;
317317
318318#ifdef DEBUG
319- printf ( "animatedpane_position_notify: new position %d\n" ,
320- animatedpane -> position );
319+ printf ( "animatedpane_position_notify: new position %d\n" , position );
321320#endif /* DEBUG */
321+
322+ if ( animatedpane -> position != position )
323+ g_object_set ( animatedpane , "position" , position , NULL );
322324 }
323325}
324326
@@ -329,7 +331,8 @@ animatedpane_init( Animatedpane *animatedpane )
329331 printf ( "animatedpane_init:\n" );
330332#endif /*DEBUG*/
331333
332- animatedpane -> position = INITIAL_PANED_POSITION ;
334+ // distance of the divider from the RIGHT edge of the window
335+ animatedpane -> position = 500 ;
333336
334337 // it'd be nice to create our gtkpaned in animatedpane.ui, but we need
335338 // this pointer during builder
0 commit comments