canvasframework 0.5.22 → 0.5.24

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 +75 -90
  2. package/package.json +1 -1
@@ -1,15 +1,18 @@
1
1
  import Component from '../core/Component.js';
2
+
2
3
  /**
3
- * Carte avec ombre et contenu
4
+ * Carte avec système de layout, ombre et bordures arrondies
4
5
  * @class
5
6
  * @extends Component
6
- * @property {Component[]} children - Enfants de la carte
7
+ * @property {Component[]} children - Enfants
7
8
  * @property {number} padding - Padding interne
9
+ * @property {number} gap - Espacement entre enfants
10
+ * @property {string} direction - Direction ('column' ou 'row')
11
+ * @property {string} align - Alignement ('start', 'center', 'end')
8
12
  * @property {string} bgColor - Couleur de fond
9
- * @property {number} elevation - Élévation (ombre)
10
13
  * @property {number} borderRadius - Rayon des coins
11
- * @property {boolean} clipContent - Clip le contenu
12
- * @property {boolean} clickableChildren - Active les clics sur les enfants
14
+ * @property {number} elevation - Élévation (ombre)
15
+ * @property {boolean} clipContent - Clip le contenu aux bordures
13
16
  */
14
17
  class Card extends Component {
15
18
  /**
@@ -17,40 +20,71 @@ class Card extends Component {
17
20
  * @param {CanvasFramework} framework - Framework parent
18
21
  * @param {Object} [options={}] - Options de configuration
19
22
  * @param {number} [options.padding=16] - Padding interne
23
+ * @param {number} [options.gap=0] - Espacement entre enfants
24
+ * @param {string} [options.direction='column'] - Direction
25
+ * @param {string} [options.align='start'] - Alignement
20
26
  * @param {string} [options.bgColor='#FFFFFF'] - Couleur de fond
21
- * @param {number} [options.elevation=2] - Élévation (ombre)
22
27
  * @param {number} [options.borderRadius] - Rayon des coins (auto selon platform)
28
+ * @param {number} [options.elevation=2] - Élévation (ombre)
23
29
  * @param {boolean} [options.clipContent=true] - Clip le contenu
24
- * @param {boolean} [options.clickableChildren=true] - Active les clics enfants
25
30
  */
26
31
  constructor(framework, options = {}) {
27
32
  super(framework, options);
28
33
  this.children = [];
29
- this.padding = options.padding || 16;
34
+ this.padding = options.padding !== undefined ? options.padding : 16;
35
+ this.gap = options.gap || 0;
36
+ this.direction = options.direction || 'column'; // 'column' ou 'row'
37
+ this.align = options.align || 'start'; // 'start', 'center', 'end'
30
38
  this.bgColor = options.bgColor || '#FFFFFF';
31
- this.elevation = options.elevation || 2;
32
- this.borderRadius = options.borderRadius || (framework.platform === 'material' ? 4 : 12);
39
+ this.borderRadius = options.borderRadius !== undefined
40
+ ? options.borderRadius
41
+ : (framework.platform === 'material' ? 4 : 12);
42
+ this.elevation = options.elevation !== undefined ? options.elevation : 2;
33
43
  this.clipContent = options.clipContent !== false;
34
- this.clickableChildren = options.clickableChildren !== false; // NOUVEAU: activer/désactiver les enfants cliquables
35
44
  }
36
45
 
37
46
  /**
38
- * Ajoute un enfant à la carte
47
+ * Ajoute un enfant
39
48
  * @param {Component} child - Composant enfant
40
49
  * @returns {Component} L'enfant ajouté
41
50
  */
42
51
  add(child) {
43
- // Ajuster les coordonnées de l'enfant pour qu'elles soient relatives à la Card
44
- child.x = child.x || 0;
45
- child.y = child.y || 0;
46
52
  this.children.push(child);
47
-
48
- // Marquer l'enfant comme appartenant à cette Card
49
- child.parentCard = this;
50
-
53
+ this.layout();
51
54
  return child;
52
55
  }
53
56
 
57
+ /**
58
+ * Organise les enfants selon le layout
59
+ * @private
60
+ */
61
+ layout() {
62
+ let currentX = this.padding;
63
+ let currentY = this.padding;
64
+
65
+ for (let child of this.children) {
66
+ if (this.direction === 'column') {
67
+ child.x = currentX;
68
+ child.y = currentY;
69
+ if (this.align === 'center') {
70
+ child.x = (this.width - child.width) / 2;
71
+ } else if (this.align === 'end') {
72
+ child.x = this.width - child.width - this.padding;
73
+ }
74
+ currentY += child.height + this.gap;
75
+ } else {
76
+ child.x = currentX;
77
+ child.y = currentY;
78
+ if (this.align === 'center') {
79
+ child.y = (this.height - child.height) / 2;
80
+ } else if (this.align === 'end') {
81
+ child.y = this.height - child.height - this.padding;
82
+ }
83
+ currentX += child.width + this.gap;
84
+ }
85
+ }
86
+ }
87
+
54
88
  /**
55
89
  * Dessine la carte et ses enfants
56
90
  * @param {CanvasRenderingContext2D} ctx - Contexte de dessin
@@ -58,7 +92,7 @@ class Card extends Component {
58
92
  draw(ctx) {
59
93
  ctx.save();
60
94
 
61
- // Ombre
95
+ // Ombre (elevation)
62
96
  if (this.elevation > 0) {
63
97
  ctx.shadowColor = 'rgba(0, 0, 0, 0.15)';
64
98
  ctx.shadowBlur = this.elevation * 3;
@@ -66,81 +100,41 @@ class Card extends Component {
66
100
  }
67
101
 
68
102
  // Background
69
- ctx.fillStyle = this.bgColor;
70
- ctx.beginPath();
71
- this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
72
- ctx.fill();
103
+ if (this.bgColor !== 'transparent') {
104
+ ctx.fillStyle = this.bgColor;
105
+ if (this.borderRadius > 0) {
106
+ ctx.beginPath();
107
+ this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
108
+ ctx.fill();
109
+ } else {
110
+ ctx.fillRect(this.x, this.y, this.width, this.height);
111
+ }
112
+ }
73
113
 
114
+ // Réinitialiser l'ombre
74
115
  ctx.shadowColor = 'transparent';
116
+ ctx.shadowBlur = 0;
117
+ ctx.shadowOffsetY = 0;
75
118
 
76
- // Clipping pour empêcher le contenu de déborder
77
- if (this.clipContent) {
119
+ // Clipping (optionnel)
120
+ if (this.clipContent && this.borderRadius > 0) {
78
121
  ctx.beginPath();
79
122
  this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
80
123
  ctx.clip();
81
124
  }
82
125
 
83
- // Children - dessinés relativement à la Card
126
+ // Children - coordonnées relatives à la Card
127
+ ctx.save();
128
+ ctx.translate(this.x, this.y);
129
+
84
130
  for (let child of this.children) {
85
131
  if (child.visible) {
86
- // Sauvegarder les coordonnées originales
87
- const originalX = child.x;
88
- const originalY = child.y;
89
-
90
- // Ajuster les coordonnées pour être relatives à la Card
91
- child.x = this.x + this.padding + originalX;
92
- child.y = this.y + this.padding + originalY;
93
-
94
- // Dessiner l'enfant
95
132
  child.draw(ctx);
96
-
97
- // Restaurer les coordonnées originales
98
- child.x = originalX;
99
- child.y = originalY;
100
133
  }
101
134
  }
102
135
 
103
136
  ctx.restore();
104
- }
105
-
106
- /**
107
- * Vérifie les clics sur les enfants
108
- * @param {number} x - Coordonnée X
109
- * @param {number} y - Coordonnée Y
110
- * @returns {boolean} True si un enfant a été cliqué
111
- * @private
112
- */
113
- checkChildClick(x, y) {
114
- // Ajuster y avec le scrollOffset
115
- const adjustedY = y - this.framework.scrollOffset;
116
-
117
- // Vérifier chaque enfant
118
- for (let i = this.children.length - 1; i >= 0; i--) {
119
- const child = this.children[i];
120
-
121
- // Calculer les coordonnées absolues de l'enfant
122
- const childX = this.x + this.padding + child.x;
123
- const childY = this.y + this.padding + child.y;
124
-
125
- // Vérifier si le clic est dans l'enfant
126
- if (child.visible &&
127
- adjustedY >= childY &&
128
- adjustedY <= childY + child.height &&
129
- x >= childX &&
130
- x <= childX + child.width) {
131
-
132
- // Si l'enfant a un onClick ou onPress, le déclencher
133
- if (child.onClick) {
134
- child.onClick();
135
- return true;
136
- } else if (child.onPress) {
137
- child.onPress(x, adjustedY);
138
- return true;
139
- }
140
- }
141
- }
142
-
143
- return false;
137
+ ctx.restore();
144
138
  }
145
139
 
146
140
  /**
@@ -166,7 +160,7 @@ class Card extends Component {
166
160
  ctx.quadraticCurveTo(x, y, x + radius, y);
167
161
  ctx.closePath();
168
162
  }
169
-
163
+
170
164
  /**
171
165
  * Vérifie si un point est dans les limites
172
166
  * @param {number} x - Coordonnée X
@@ -179,15 +173,6 @@ class Card extends Component {
179
173
  y >= this.y &&
180
174
  y <= this.y + this.height;
181
175
  }
182
-
183
- /**
184
- * Gère le clic sur la carte
185
- * @private
186
- */
187
- onClick() {
188
- // La Card elle-même peut avoir un onClick, mais on veut aussi vérifier les enfants
189
- // Cette logique est gérée dans le CanvasFramework modifié ci-dessous
190
- }
191
176
  }
192
177
 
193
178
  export default Card;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.5.22",
3
+ "version": "0.5.24",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/beyons/CanvasFramework.git"