canvasframework 0.5.32 → 0.5.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/components/Card.js +71 -88
  2. package/package.json +1 -1
@@ -39,7 +39,8 @@ class Card extends Component {
39
39
  this.borderRadius = options.borderRadius || 0;
40
40
  this.elevation = options.elevation || 0;
41
41
  this.autoLayout = options.autoLayout !== undefined ? options.autoLayout : true;
42
-
42
+ // 🔴 AJOUTER CETTE LIGNE
43
+ this.clickableChildren = true;
43
44
  // Stocker les positions relatives des enfants
44
45
  this.childPositions = new Map();
45
46
  }
@@ -49,29 +50,23 @@ class Card extends Component {
49
50
  * @param {Component} child - Composant enfant
50
51
  * @returns {Component} L'enfant ajouté
51
52
  */
52
- add(child) {
53
+ add(child) {
53
54
  this.children.push(child);
54
55
 
55
- // Stocker la position relative originale
56
- const relativeX = child.x;
57
- const relativeY = child.y;
58
-
56
+ // NE PAS CONVERTIR - garder relatif
59
57
  this.childPositions.set(child, {
60
- x: relativeX,
61
- y: relativeY
58
+ x: child.x,
59
+ y: child.y
62
60
  });
63
61
 
64
- // CONVERTIR seulement si autoLayout est activé
65
62
  if (this.autoLayout) {
66
- this.layout(); // layout() fera la conversion
67
- } else {
68
- // Si autoLayout est désactivé, convertir manuellement
69
- child.x = this.x + relativeX;
70
- child.y = this.y + relativeY;
63
+ this.layout();
71
64
  }
72
65
 
66
+ // PAS de conversion child.x = this.x + relativeX !
67
+
73
68
  return child;
74
- }
69
+ }
75
70
 
76
71
  /**
77
72
  * Supprime un enfant
@@ -105,72 +100,56 @@ class Card extends Component {
105
100
  if (this.children.length === 0 || !this.autoLayout) return;
106
101
 
107
102
  if (this.direction === 'column') {
108
- let currentY = this.padding;
109
-
110
- for (let i = 0; i < this.children.length; i++) {
111
- const child = this.children[i];
103
+ let currentY = this.padding;
112
104
 
113
- // Calculer la position X selon l'alignement
114
- let childX = this.padding;
115
- if (this.align === 'center') {
116
- childX = (this.width - child.width) / 2;
117
- } else if (this.align === 'end') {
118
- childX = this.width - child.width - this.padding;
119
- } else if (this.align === 'stretch') {
120
- childX = this.padding;
121
- child.width = this.width - (this.padding * 2);
105
+ for (let i = 0; i < this.children.length; i++) {
106
+ const child = this.children[i];
107
+
108
+ let childX = this.padding;
109
+ if (this.align === 'center') {
110
+ childX = (this.width - child.width) / 2;
111
+ } else if (this.align === 'end') {
112
+ childX = this.width - child.width - this.padding;
113
+ }
114
+
115
+ // GARDER RELATIF (ne pas ajouter this.x et this.y)
116
+ child.x = childX;
117
+ child.y = currentY;
118
+
119
+ this.childPositions.set(child, { x: childX, y: currentY });
120
+
121
+ currentY += child.height;
122
+ if (i < this.children.length - 1) {
123
+ currentY += this.gap;
124
+ }
122
125
  }
123
-
124
- // Positionner l'enfant RELATIVEMENT à la Card
125
- child.x = this.x + childX;
126
- child.y = this.y + currentY;
127
-
128
- // Stocker la position relative
129
- this.childPositions.set(child, { x: childX, y: currentY });
130
-
131
- // Mettre à jour la position Y pour l'enfant suivant
132
- currentY += child.height;
133
-
134
- // Ajouter le gap seulement si ce n'est pas le dernier enfant
135
- if (i < this.children.length - 1) {
136
- currentY += this.gap;
137
- }
138
- }
139
126
  } else {
140
- // Direction 'row'
141
- let currentX = this.padding;
142
-
143
- for (let i = 0; i < this.children.length; i++) {
144
- const child = this.children[i];
145
-
146
- // Calculer la position Y selon l'alignement
147
- let childY = this.padding;
148
- if (this.align === 'center') {
149
- childY = (this.height - child.height) / 2;
150
- } else if (this.align === 'end') {
151
- childY = this.height - child.height - this.padding;
152
- } else if (this.align === 'stretch') {
153
- childY = this.padding;
154
- child.height = this.height - (this.padding * 2);
155
- }
156
-
157
- // Positionner l'enfant RELATIVEMENT à la Card
158
- child.x = this.x + currentX;
159
- child.y = this.y + childY;
160
-
161
- // Stocker la position relative
162
- this.childPositions.set(child, { x: currentX, y: childY });
127
+ // Direction 'row' - même logique
128
+ let currentX = this.padding;
163
129
 
164
- // Mettre à jour la position X pour l'enfant suivant
165
- currentX += child.width;
166
-
167
- // Ajouter le gap seulement si ce n'est pas le dernier enfant
168
- if (i < this.children.length - 1) {
169
- currentX += this.gap;
130
+ for (let i = 0; i < this.children.length; i++) {
131
+ const child = this.children[i];
132
+
133
+ let childY = this.padding;
134
+ if (this.align === 'center') {
135
+ childY = (this.height - child.height) / 2;
136
+ } else if (this.align === 'end') {
137
+ childY = this.height - child.height - this.padding;
138
+ }
139
+
140
+ // GARDER RELATIF
141
+ child.x = currentX;
142
+ child.y = childY;
143
+
144
+ this.childPositions.set(child, { x: currentX, y: childY });
145
+
146
+ currentX += child.width;
147
+ if (i < this.children.length - 1) {
148
+ currentX += this.gap;
149
+ }
170
150
  }
171
- }
172
151
  }
173
- }
152
+ }
174
153
 
175
154
  /**
176
155
  * Met à jour la position de la carte et ajuste les enfants
@@ -278,28 +257,32 @@ class Card extends Component {
278
257
 
279
258
  // Dessiner l'ombre si elevation > 0
280
259
  if (this.elevation > 0) {
281
- this.drawShadow(ctx);
260
+ this.drawShadow(ctx);
282
261
  }
283
262
 
284
- // Dessiner le fond de la carte
263
+ // Dessiner le fond de la carte (en position absolue)
285
264
  if (this.bgColor !== 'transparent') {
286
- ctx.fillStyle = this.bgColor;
287
- if (this.borderRadius > 0) {
288
- ctx.beginPath();
289
- this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
290
- ctx.fill();
291
- } else {
292
- ctx.fillRect(this.x, this.y, this.width, this.height);
293
- }
265
+ ctx.fillStyle = this.bgColor;
266
+ if (this.borderRadius > 0) {
267
+ ctx.beginPath();
268
+ this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
269
+ ctx.fill();
270
+ } else {
271
+ ctx.fillRect(this.x, this.y, this.width, this.height);
272
+ }
294
273
  }
295
274
 
296
- // Dessiner les enfants
275
+ // 🔴 DESSINER LES ENFANTS AVEC TRANSLATE (coordonnées relatives)
276
+ ctx.save();
277
+ ctx.translate(this.x, this.y);
278
+
297
279
  for (let child of this.children) {
298
- if (child.visible) child.draw(ctx);
280
+ if (child.visible) child.draw(ctx);
299
281
  }
300
282
 
301
283
  ctx.restore();
302
- }
284
+ ctx.restore();
285
+ }
303
286
 
304
287
  /**
305
288
  * Dessine un rectangle avec coins arrondis
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.5.32",
3
+ "version": "0.5.33",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/beyons/CanvasFramework.git"