77 * Copyright (C) 2026 brummer <brummer@web.de>
88 */
99
10+ /****************************************************************
11+ SizeGroup.h - a vertical animated size group
12+ with drag and drop support for libxputty
13+ ****************************************************************/
14+
1015
1116#pragma once
1217#include "xwidgets.h"
@@ -73,16 +78,18 @@ static inline void vsg_destroy(VerticalSizeGroup* g) {
7378
7479static inline void vsg_init (VerticalSizeGroup * g ,
7580 Widget_t * parent ,int sx ,int sy ,int spacingY ,int * glowY ) {
76- memset (g ,0 ,sizeof (* g ));
77- g -> parent = parent ;
78- g -> startX = sx ;
79- g -> startY = sy ;
80- g -> spacingY = spacingY ;
81- g -> glowY = glowY ;
82- g -> animateOnAdd = 1 ;
83- g -> newIndex = 1 ;
81+ memset (g ,0 ,sizeof (* g )); // clear the SizeGroup
82+ g -> parent = parent ; // the parent window
83+ g -> startX = sx ; // the upper left corner
84+ g -> startY = sy ; // the upper vertical point
85+ g -> spacingY = spacingY ; // spacing behind elements
86+ g -> glowY = glowY ; // drop indicator
87+ g -> animateOnAdd = 1 ; // switch animation on/off
88+ g -> newIndex = 1 ; // the drop index
89+ g -> wmy = sy ; // the current position from a dragged window
8490}
8591
92+ // call from a GUI timeout loop (60fps)
8693static inline void vsg_update (VerticalSizeGroup * g ,float dt ) {
8794 if (!g -> tweensActive ) return ;
8895 Display * dpy = g -> parent -> app -> dpy ;
@@ -92,7 +99,7 @@ static inline void vsg_update(VerticalSizeGroup* g,float dt) {
9299 VSTween * t = & g -> tweens [i ];
93100 if (t -> t >=1 ) continue ;
94101
95- t -> t += dt * 12.0f ;
102+ t -> t += dt / 0.083335f ; // 60fps
96103 if (t -> t > 1 ) t -> t = 1 ;
97104
98105 float s = t -> t * t -> t * (3 - 2 * t -> t );
@@ -103,6 +110,7 @@ static inline void vsg_update(VerticalSizeGroup* g,float dt) {
103110 g -> tweensActive = active ;
104111}
105112
113+ // prepare entries for animation/ positioning
106114static inline void vsg_relayout (VerticalSizeGroup * g ) {
107115 Display * dpy = g -> parent -> app -> dpy ;
108116 g -> tweenCount = 0 ;
@@ -138,6 +146,7 @@ static inline void vsg_relayout(VerticalSizeGroup* g) {
138146 }
139147}
140148
149+ // add element to the size-group
141150static inline void vsg_add (VerticalSizeGroup * g ,Widget_t * w ) {
142151 if (g -> entryCount + 1 > g -> entryCap ) {
143152 g -> entryCap = g -> entryCap ? g -> entryCap * 2 : 8 ;
@@ -148,8 +157,8 @@ static inline void vsg_add(VerticalSizeGroup* g,Widget_t* w) {
148157 vsg_relayout (g );
149158}
150159
160+ // find index of a element in the size-group
151161static inline int vsg_findDragIndex (VerticalSizeGroup * g , Widget_t * w ) {
152- /* find current index */
153162 for (int i = 0 ;i < g -> entryCount ;i ++ ) {
154163 if (g -> entries [i ] == w ) {
155164 g -> oldIndex = i ;
@@ -159,6 +168,7 @@ static inline int vsg_findDragIndex(VerticalSizeGroup* g, Widget_t* w) {
159168 return -1 ;
160169}
161170
171+ // find new index of a moved element
162172static inline int vsg_findDropIndex (VerticalSizeGroup * g ) {
163173 int best = 0 ;
164174 int bestDist = 1e9 ;
@@ -180,12 +190,14 @@ static inline int vsg_findDropIndex(VerticalSizeGroup* g) {
180190 return best ;
181191}
182192
193+ // register a element for dragging
183194static inline void vsg_beginDrag (VerticalSizeGroup * g ,Widget_t * w ,int my ) {
184195 g -> dragWidget = w ;
185196 g -> dragOffsetY = my ;
186197 os_raise_widget (w );
187198}
188199
200+ // while move the element
189201static inline void vsg_dragMove (VerticalSizeGroup * g ,int my ) {
190202 if (!g -> dragWidget ) return ;
191203
@@ -195,7 +207,7 @@ static inline void vsg_dragMove(VerticalSizeGroup* g,int my) {
195207 g -> dragWidget -> scale .init_x ,
196208 g -> wmy );
197209
198- /* find current index */
210+ // find current index
199211 for (int i = 0 ;i < g -> entryCount ;i ++ ) {
200212 if (g -> entries [i ] == g -> dragWidget ) {
201213 g -> oldIndex = i ;
@@ -208,7 +220,7 @@ static inline void vsg_dragMove(VerticalSizeGroup* g,int my) {
208220 expose_widget (g -> parent );
209221}
210222
211-
223+ // insert dropped element in size-group at new index
212224static inline void vsg_endDrag (VerticalSizeGroup * g ) {
213225 if (!g -> dragWidget ) return ;
214226
@@ -230,5 +242,4 @@ static inline void vsg_endDrag(VerticalSizeGroup* g) {
230242 g -> dragWidget = NULL ;
231243 * g -> glowY = -1 ;
232244 expose_widget (g -> parent );
233- //fprintf(stderr, "newIndex %i\n", g->newIndex);
234245}
0 commit comments