canvasframework 0.5.26 → 0.5.27

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 +66 -46
  2. package/package.json +1 -1
@@ -6,13 +6,12 @@ import Component from '../core/Component.js';
6
6
  * @extends Component
7
7
  * @property {Component[]} children - Enfants
8
8
  * @property {number} padding - Padding interne
9
- * @property {number} gap - Espacement constant entre enfants
9
+ * @property {number} gap - Espacement constant entre enfants SEULEMENT
10
10
  * @property {string} direction - Direction ('column' ou 'row')
11
11
  * @property {string} align - Alignement ('start', 'center', 'end', 'stretch')
12
12
  * @property {string} bgColor - Couleur de fond
13
13
  * @property {number} borderRadius - Rayon des coins
14
14
  * @property {number} elevation - Niveau d'élévation (ombres)
15
- * @property {boolean} autoHeight - Ajuste automatiquement la hauteur selon le contenu
16
15
  */
17
16
  class Card extends Component {
18
17
  /**
@@ -20,25 +19,23 @@ class Card extends Component {
20
19
  * @param {CanvasFramework} framework - Framework parent
21
20
  * @param {Object} [options={}] - Options de configuration
22
21
  * @param {number} [options.padding=0] - Padding interne
23
- * @param {number} [options.gap=0] - Espacement constant entre enfants
22
+ * @param {number} [options.gap=0] - Espacement constant entre enfants SEULEMENT
24
23
  * @param {string} [options.direction='column'] - Direction
25
24
  * @param {string} [options.align='start'] - Alignement
26
25
  * @param {string} [options.bgColor='transparent'] - Couleur de fond
27
26
  * @param {number} [options.borderRadius=0] - Rayon des coins
28
27
  * @param {number} [options.elevation=0] - Niveau d'élévation (0-5)
29
- * @param {boolean} [options.autoHeight=false] - Ajuste automatiquement la hauteur
30
28
  */
31
29
  constructor(framework, options = {}) {
32
30
  super(framework, options);
33
31
  this.children = [];
34
32
  this.padding = options.padding || 0;
35
- this.gap = options.gap || 0; // Espacement constant entre chaque enfant
33
+ this.gap = options.gap || 0; // Espacement UNIQUEMENT entre enfants
36
34
  this.direction = options.direction || 'column';
37
35
  this.align = options.align || 'start';
38
36
  this.bgColor = options.bgColor || 'transparent';
39
37
  this.borderRadius = options.borderRadius || 0;
40
38
  this.elevation = options.elevation || 0;
41
- this.autoHeight = options.autoHeight || false;
42
39
  }
43
40
 
44
41
  /**
@@ -82,15 +79,13 @@ class Card extends Component {
82
79
  layout() {
83
80
  if (this.children.length === 0) return;
84
81
 
85
- let currentX = this.x + this.padding;
86
- let currentY = this.y + this.padding;
87
-
88
82
  if (this.direction === 'column') {
83
+ let currentY = this.y + this.padding;
84
+
89
85
  for (let i = 0; i < this.children.length; i++) {
90
86
  const child = this.children[i];
91
87
 
92
- // Positionner l'enfant
93
- child.x = currentX;
88
+ // Positionner l'enfant sans tenir compte de ses marges internes
94
89
  child.y = currentY;
95
90
 
96
91
  // Gérer l'alignement horizontal
@@ -101,32 +96,28 @@ class Card extends Component {
101
96
  } else if (this.align === 'stretch') {
102
97
  child.x = this.x + this.padding;
103
98
  child.width = this.width - (this.padding * 2);
99
+ } else {
100
+ // Alignement 'start' par défaut
101
+ child.x = this.x + this.padding;
104
102
  }
105
103
 
106
104
  // Mettre à jour la position Y pour l'enfant suivant
107
- // Toujours le même espacement (gap) entre chaque enfant
108
- currentY += child.height + this.gap;
109
- }
110
-
111
- // Ajuster la hauteur automatiquement si autoHeight est activé
112
- if (this.autoHeight) {
113
- const totalChildrenHeight = this.children.reduce((sum, child) => sum + child.height, 0);
114
- const totalGapHeight = this.gap * Math.max(0, this.children.length - 1);
115
- const neededHeight = totalChildrenHeight + totalGapHeight + (this.padding * 2);
105
+ // UNIQUEMENT avec le gap spécifié, rien d'autre
106
+ currentY += child.height;
116
107
 
117
- if (neededHeight !== this.height) {
118
- this.height = neededHeight;
119
- // Notifier un changement de dimensions
120
- if (this.onResize) this.onResize(this.width, this.height);
108
+ // Ajouter le gap seulement si ce n'est pas le dernier enfant
109
+ if (i < this.children.length - 1) {
110
+ currentY += this.gap;
121
111
  }
122
112
  }
123
113
  } else {
124
- // Direction 'row' (logique similaire pour l'alignement horizontal)
114
+ // Direction 'row'
115
+ let currentX = this.x + this.padding;
116
+
125
117
  for (let i = 0; i < this.children.length; i++) {
126
118
  const child = this.children[i];
127
119
 
128
120
  child.x = currentX;
129
- child.y = currentY;
130
121
 
131
122
  // Gérer l'alignement vertical
132
123
  if (this.align === 'center') {
@@ -136,22 +127,16 @@ class Card extends Component {
136
127
  } else if (this.align === 'stretch') {
137
128
  child.y = this.y + this.padding;
138
129
  child.height = this.height - (this.padding * 2);
130
+ } else {
131
+ child.y = this.y + this.padding;
139
132
  }
140
133
 
141
- // Espacement constant entre chaque enfant
142
- currentX += child.width + this.gap;
143
- }
144
-
145
- // Ajuster la largeur automatiquement si autoHeight est activé (pour row)
146
- if (this.autoHeight) {
147
- const totalChildrenWidth = this.children.reduce((sum, child) => sum + child.width, 0);
148
- const totalGapWidth = this.gap * Math.max(0, this.children.length - 1);
149
- const neededWidth = totalChildrenWidth + totalGapWidth + (this.padding * 2);
134
+ // Mettre à jour la position X pour l'enfant suivant
135
+ currentX += child.width;
150
136
 
151
- if (neededWidth !== this.width) {
152
- this.width = neededWidth;
153
- // Notifier un changement de dimensions
154
- if (this.onResize) this.onResize(this.width, this.height);
137
+ // Ajouter le gap seulement si ce n'est pas le dernier enfant
138
+ if (i < this.children.length - 1) {
139
+ currentX += this.gap;
155
140
  }
156
141
  }
157
142
  }
@@ -230,13 +215,6 @@ class Card extends Component {
230
215
  }
231
216
  }
232
217
 
233
- // Appliquer le clipping pour le borderRadius (empêche les débordements)
234
- if (this.borderRadius > 0) {
235
- ctx.beginPath();
236
- this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
237
- ctx.clip();
238
- }
239
-
240
218
  // Dessiner les enfants
241
219
  for (let child of this.children) {
242
220
  if (child.visible) child.draw(ctx);
@@ -376,6 +354,48 @@ class Card extends Component {
376
354
  this.layout();
377
355
  }
378
356
  }
357
+
358
+ /**
359
+ * Calcule la hauteur totale nécessaire pour contenir tous les enfants
360
+ * @returns {number} Hauteur totale nécessaire
361
+ */
362
+ getTotalHeight() {
363
+ if (this.children.length === 0) return 0;
364
+
365
+ const totalChildrenHeight = this.children.reduce((sum, child) => sum + child.height, 0);
366
+ const totalGapHeight = this.gap * Math.max(0, this.children.length - 1);
367
+ return totalChildrenHeight + totalGapHeight + (this.padding * 2);
368
+ }
369
+
370
+ /**
371
+ * Calcule la largeur totale nécessaire pour contenir tous les enfants
372
+ * @returns {number} Largeur totale nécessaire
373
+ */
374
+ getTotalWidth() {
375
+ if (this.children.length === 0) return 0;
376
+
377
+ const totalChildrenWidth = this.children.reduce((sum, child) => sum + child.width, 0);
378
+ const totalGapWidth = this.gap * Math.max(0, this.children.length - 1);
379
+ return totalChildrenWidth + totalGapWidth + (this.padding * 2);
380
+ }
381
+
382
+ /**
383
+ * Ajuste automatiquement la hauteur de la carte pour contenir tous les enfants
384
+ */
385
+ fitHeight() {
386
+ if (this.direction === 'column') {
387
+ this.height = this.getTotalHeight();
388
+ }
389
+ }
390
+
391
+ /**
392
+ * Ajuste automatiquement la largeur de la carte pour contenir tous les enfants
393
+ */
394
+ fitWidth() {
395
+ if (this.direction === 'row') {
396
+ this.width = this.getTotalWidth();
397
+ }
398
+ }
379
399
  }
380
400
 
381
401
  export default Card;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.5.26",
3
+ "version": "0.5.27",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/beyons/CanvasFramework.git"