canvasframework 0.5.31 → 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 -86
  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,27 +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
- // CONVERTIR les positions relatives en positions absolues
56
- // Les x, y passés sont relatifs à la Card
57
- child.x = this.x + child.x;
58
- child.y = this.y + child.y;
59
-
60
- // Stocker la position relative originale
56
+ // NE PAS CONVERTIR - garder relatif
61
57
  this.childPositions.set(child, {
62
- x: child.x - this.x,
63
- y: child.y - this.y
58
+ x: child.x,
59
+ y: child.y
64
60
  });
65
61
 
66
- // Si autoLayout est activé, organiser automatiquement
67
62
  if (this.autoLayout) {
68
- this.layout();
63
+ this.layout();
69
64
  }
70
65
 
66
+ // PAS de conversion child.x = this.x + relativeX !
67
+
71
68
  return child;
72
- }
69
+ }
73
70
 
74
71
  /**
75
72
  * Supprime un enfant
@@ -103,72 +100,56 @@ class Card extends Component {
103
100
  if (this.children.length === 0 || !this.autoLayout) return;
104
101
 
105
102
  if (this.direction === 'column') {
106
- let currentY = this.padding;
107
-
108
- for (let i = 0; i < this.children.length; i++) {
109
- const child = this.children[i];
110
-
111
- // Calculer la position X selon l'alignement
112
- let childX = this.padding;
113
- if (this.align === 'center') {
114
- childX = (this.width - child.width) / 2;
115
- } else if (this.align === 'end') {
116
- childX = this.width - child.width - this.padding;
117
- } else if (this.align === 'stretch') {
118
- childX = this.padding;
119
- child.width = this.width - (this.padding * 2);
120
- }
121
-
122
- // Positionner l'enfant RELATIVEMENT à la Card
123
- child.x = this.x + childX;
124
- child.y = this.y + currentY;
125
-
126
- // Stocker la position relative
127
- this.childPositions.set(child, { x: childX, y: currentY });
103
+ let currentY = this.padding;
128
104
 
129
- // Mettre à jour la position Y pour l'enfant suivant
130
- currentY += child.height;
131
-
132
- // Ajouter le gap seulement si ce n'est pas le dernier enfant
133
- if (i < this.children.length - 1) {
134
- currentY += this.gap;
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
+ }
135
125
  }
136
- }
137
126
  } else {
138
- // Direction 'row'
139
- let currentX = this.padding;
140
-
141
- for (let i = 0; i < this.children.length; i++) {
142
- const child = this.children[i];
127
+ // Direction 'row' - même logique
128
+ let currentX = this.padding;
143
129
 
144
- // Calculer la position Y selon l'alignement
145
- let childY = this.padding;
146
- if (this.align === 'center') {
147
- childY = (this.height - child.height) / 2;
148
- } else if (this.align === 'end') {
149
- childY = this.height - child.height - this.padding;
150
- } else if (this.align === 'stretch') {
151
- childY = this.padding;
152
- child.height = this.height - (this.padding * 2);
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
+ }
153
150
  }
154
-
155
- // Positionner l'enfant RELATIVEMENT à la Card
156
- child.x = this.x + currentX;
157
- child.y = this.y + childY;
158
-
159
- // Stocker la position relative
160
- this.childPositions.set(child, { x: currentX, y: childY });
161
-
162
- // Mettre à jour la position X pour l'enfant suivant
163
- currentX += child.width;
164
-
165
- // Ajouter le gap seulement si ce n'est pas le dernier enfant
166
- if (i < this.children.length - 1) {
167
- currentX += this.gap;
168
- }
169
- }
170
151
  }
171
- }
152
+ }
172
153
 
173
154
  /**
174
155
  * Met à jour la position de la carte et ajuste les enfants
@@ -276,28 +257,32 @@ class Card extends Component {
276
257
 
277
258
  // Dessiner l'ombre si elevation > 0
278
259
  if (this.elevation > 0) {
279
- this.drawShadow(ctx);
260
+ this.drawShadow(ctx);
280
261
  }
281
262
 
282
- // Dessiner le fond de la carte
263
+ // Dessiner le fond de la carte (en position absolue)
283
264
  if (this.bgColor !== 'transparent') {
284
- ctx.fillStyle = this.bgColor;
285
- if (this.borderRadius > 0) {
286
- ctx.beginPath();
287
- this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
288
- ctx.fill();
289
- } else {
290
- ctx.fillRect(this.x, this.y, this.width, this.height);
291
- }
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
+ }
292
273
  }
293
274
 
294
- // Dessiner les enfants
275
+ // 🔴 DESSINER LES ENFANTS AVEC TRANSLATE (coordonnées relatives)
276
+ ctx.save();
277
+ ctx.translate(this.x, this.y);
278
+
295
279
  for (let child of this.children) {
296
- if (child.visible) child.draw(ctx);
280
+ if (child.visible) child.draw(ctx);
297
281
  }
298
282
 
299
283
  ctx.restore();
300
- }
284
+ ctx.restore();
285
+ }
301
286
 
302
287
  /**
303
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.31",
3
+ "version": "0.5.33",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/beyons/CanvasFramework.git"