canvasframework 0.5.28 → 0.5.29

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 +23 -23
  2. package/package.json +1 -1
@@ -8,12 +8,11 @@ import Component from '../core/Component.js';
8
8
  * @property {number} padding - Padding interne
9
9
  * @property {number} gap - Espacement constant entre enfants
10
10
  * @property {string} direction - Direction ('column' ou 'row')
11
- * @property {string} align - Alignement ('start', 'center', 'end')
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
15
  * @property {boolean} autoLayout - Active le layout automatique
16
- * @property {Map} childPositions - Positions relatives des enfants
17
16
  */
18
17
  class Card extends Component {
19
18
  /**
@@ -46,21 +45,27 @@ class Card extends Component {
46
45
  }
47
46
 
48
47
  /**
49
- * Ajoute un enfant
48
+ * Ajoute un enfant (position relative convertie en absolue)
50
49
  * @param {Component} child - Composant enfant
51
50
  * @returns {Component} L'enfant ajouté
52
51
  */
53
52
  add(child) {
54
53
  this.children.push(child);
55
54
 
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
61
+ this.childPositions.set(child, {
62
+ x: child.x - this.x,
63
+ y: child.y - this.y
64
+ });
65
+
56
66
  // Si autoLayout est activé, organiser automatiquement
57
67
  if (this.autoLayout) {
58
68
  this.layout();
59
- } else {
60
- // En mode manuel, calculer et stocker la position relative
61
- const relativeX = child.x - this.x;
62
- const relativeY = child.y - this.y;
63
- this.childPositions.set(child, { x: relativeX, y: relativeY });
64
69
  }
65
70
 
66
71
  return child;
@@ -88,7 +93,6 @@ class Card extends Component {
88
93
  clear() {
89
94
  this.children = [];
90
95
  this.childPositions.clear();
91
- if (this.autoLayout) this.layout();
92
96
  }
93
97
 
94
98
  /**
@@ -110,6 +114,9 @@ class Card extends Component {
110
114
  childX = (this.width - child.width) / 2;
111
115
  } else if (this.align === 'end') {
112
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);
113
120
  }
114
121
 
115
122
  // Positionner l'enfant RELATIVEMENT à la Card
@@ -140,6 +147,9 @@ class Card extends Component {
140
147
  childY = (this.height - child.height) / 2;
141
148
  } else if (this.align === 'end') {
142
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);
143
153
  }
144
154
 
145
155
  // Positionner l'enfant RELATIVEMENT à la Card
@@ -281,13 +291,6 @@ class Card extends Component {
281
291
  }
282
292
  }
283
293
 
284
- // Appliquer le clipping si borderRadius > 0
285
- if (this.borderRadius > 0) {
286
- ctx.beginPath();
287
- this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
288
- ctx.clip();
289
- }
290
-
291
294
  // Dessiner les enfants
292
295
  for (let child of this.children) {
293
296
  if (child.visible) child.draw(ctx);
@@ -391,10 +394,10 @@ class Card extends Component {
391
394
 
392
395
  /**
393
396
  * Définit l'alignement
394
- * @param {string} align - 'start', 'center', 'end'
397
+ * @param {string} align - 'start', 'center', 'end' ou 'stretch'
395
398
  */
396
399
  setAlign(align) {
397
- if (['start', 'center', 'end'].includes(align)) {
400
+ if (['start', 'center', 'end', 'stretch'].includes(align)) {
398
401
  this.align = align;
399
402
  if (this.autoLayout) this.layout();
400
403
  }
@@ -452,11 +455,8 @@ class Card extends Component {
452
455
  * Ajuste automatiquement les dimensions de la carte pour contenir tous les enfants
453
456
  */
454
457
  fitSize() {
455
- if (this.direction === 'column') {
456
- this.height = this.getTotalHeight();
457
- } else if (this.direction === 'row') {
458
- this.width = this.getTotalWidth();
459
- }
458
+ this.fitWidth();
459
+ this.fitHeight();
460
460
  }
461
461
 
462
462
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.5.28",
3
+ "version": "0.5.29",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/beyons/CanvasFramework.git"