canvasframework 0.5.40 → 0.5.42
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.
- package/components/AppBar.js +107 -249
- package/components/BottomNavigationBar.js +143 -378
- package/components/Cards.js +232 -0
- package/components/FileUpload.js +225 -248
- package/core/CanvasFramework.js +4 -3
- package/core/UIBuilder.js +2 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/components/Card.js +0 -534
package/components/Card.js
DELETED
|
@@ -1,534 +0,0 @@
|
|
|
1
|
-
import Component from '../core/Component.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Container avec système de layout et effet d'élévation
|
|
5
|
-
* @class
|
|
6
|
-
* @extends Component
|
|
7
|
-
* @property {Component[]} children - Enfants
|
|
8
|
-
* @property {number} padding - Padding interne
|
|
9
|
-
* @property {number} gap - Espacement constant entre enfants
|
|
10
|
-
* @property {string} direction - Direction ('column' ou 'row')
|
|
11
|
-
* @property {string} align - Alignement ('start', 'center', 'end', 'stretch')
|
|
12
|
-
* @property {string} bgColor - Couleur de fond
|
|
13
|
-
* @property {number} borderRadius - Rayon des coins
|
|
14
|
-
* @property {number} elevation - Niveau d'élévation (ombres)
|
|
15
|
-
* @property {boolean} autoLayout - Active le layout automatique
|
|
16
|
-
*/
|
|
17
|
-
class Card extends Component {
|
|
18
|
-
/**
|
|
19
|
-
* Crée une instance de Card
|
|
20
|
-
* @param {CanvasFramework} framework - Framework parent
|
|
21
|
-
* @param {Object} [options={}] - Options de configuration
|
|
22
|
-
* @param {number} [options.padding=0] - Padding interne
|
|
23
|
-
* @param {number} [options.gap=0] - Espacement constant entre enfants
|
|
24
|
-
* @param {string} [options.direction='column'] - Direction
|
|
25
|
-
* @param {string} [options.align='start'] - Alignement
|
|
26
|
-
* @param {string} [options.bgColor='transparent'] - Couleur de fond
|
|
27
|
-
* @param {number} [options.borderRadius=0] - Rayon des coins
|
|
28
|
-
* @param {number} [options.elevation=0] - Niveau d'élévation (0-5)
|
|
29
|
-
* @param {boolean} [options.autoLayout=true] - Active le layout automatique
|
|
30
|
-
*/
|
|
31
|
-
constructor(framework, options = {}) {
|
|
32
|
-
super(framework, options);
|
|
33
|
-
this.children = [];
|
|
34
|
-
this.padding = options.padding || 0;
|
|
35
|
-
this.gap = options.gap || 0;
|
|
36
|
-
this.direction = options.direction || 'column';
|
|
37
|
-
this.align = options.align || 'start';
|
|
38
|
-
this.bgColor = options.bgColor || 'transparent';
|
|
39
|
-
this.borderRadius = options.borderRadius || 0;
|
|
40
|
-
this.elevation = options.elevation || 0;
|
|
41
|
-
this.autoLayout = options.autoLayout !== undefined ? options.autoLayout : true;
|
|
42
|
-
|
|
43
|
-
// Stocker les positions relatives des enfants
|
|
44
|
-
this.childPositions = new Map();
|
|
45
|
-
|
|
46
|
-
// NOUVEAU: Flag pour forcer les positions absolues
|
|
47
|
-
this._positionsCorrected = false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Ajoute un enfant (position relative convertie en absolue)
|
|
52
|
-
* @param {Component} child - Composant enfant
|
|
53
|
-
* @returns {Component} L'enfant ajouté
|
|
54
|
-
*/
|
|
55
|
-
add(child) {
|
|
56
|
-
this.children.push(child);
|
|
57
|
-
|
|
58
|
-
// SOLUTION: Stocker les coordonnées relatives AVANT conversion
|
|
59
|
-
const relativeX = child.x || 0;
|
|
60
|
-
const relativeY = child.y || 0;
|
|
61
|
-
|
|
62
|
-
// Stocker la position relative originale
|
|
63
|
-
this.childPositions.set(child, {
|
|
64
|
-
x: relativeX,
|
|
65
|
-
y: relativeY
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// CONVERTIR IMMÉDIATEMENT en positions absolues
|
|
69
|
-
child.x = this.x + relativeX;
|
|
70
|
-
child.y = this.y + relativeY;
|
|
71
|
-
|
|
72
|
-
// Si autoLayout est activé, organiser automatiquement
|
|
73
|
-
if (this.autoLayout) {
|
|
74
|
-
// Utiliser setTimeout pour éviter les conflits avec Vite Hot Reload
|
|
75
|
-
setTimeout(() => this.layout(), 0);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return child;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Organise les enfants selon le layout
|
|
83
|
-
* @private
|
|
84
|
-
*/
|
|
85
|
-
layout() {
|
|
86
|
-
if (this.children.length === 0 || !this.autoLayout) return;
|
|
87
|
-
|
|
88
|
-
if (this.direction === 'column') {
|
|
89
|
-
let currentY = this.padding;
|
|
90
|
-
|
|
91
|
-
for (let i = 0; i < this.children.length; i++) {
|
|
92
|
-
const child = this.children[i];
|
|
93
|
-
|
|
94
|
-
// Calculer la position X selon l'alignement
|
|
95
|
-
let childX = this.padding;
|
|
96
|
-
if (this.align === 'center') {
|
|
97
|
-
childX = (this.width - child.width) / 2;
|
|
98
|
-
} else if (this.align === 'end') {
|
|
99
|
-
childX = this.width - child.width - this.padding;
|
|
100
|
-
} else if (this.align === 'stretch') {
|
|
101
|
-
childX = this.padding;
|
|
102
|
-
child.width = this.width - (this.padding * 2);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Positionner l'enfant en COORDONNÉES ABSOLUES
|
|
106
|
-
child.x = this.x + childX;
|
|
107
|
-
child.y = this.y + currentY;
|
|
108
|
-
|
|
109
|
-
// Stocker la position relative
|
|
110
|
-
this.childPositions.set(child, { x: childX, y: currentY });
|
|
111
|
-
|
|
112
|
-
// Mettre à jour la position Y pour l'enfant suivant
|
|
113
|
-
currentY += child.height;
|
|
114
|
-
|
|
115
|
-
// Ajouter le gap seulement si ce n'est pas le dernier enfant
|
|
116
|
-
if (i < this.children.length - 1) {
|
|
117
|
-
currentY += this.gap;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
// Direction 'row'
|
|
122
|
-
let currentX = this.padding;
|
|
123
|
-
|
|
124
|
-
for (let i = 0; i < this.children.length; i++) {
|
|
125
|
-
const child = this.children[i];
|
|
126
|
-
|
|
127
|
-
// Calculer la position Y selon l'alignement
|
|
128
|
-
let childY = this.padding;
|
|
129
|
-
if (this.align === 'center') {
|
|
130
|
-
childY = (this.height - child.height) / 2;
|
|
131
|
-
} else if (this.align === 'end') {
|
|
132
|
-
childY = this.height - child.height - this.padding;
|
|
133
|
-
} else if (this.align === 'stretch') {
|
|
134
|
-
childY = this.padding;
|
|
135
|
-
child.height = this.height - (this.padding * 2);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Positionner l'enfant en COORDONNÉES ABSOLUES
|
|
139
|
-
child.x = this.x + currentX;
|
|
140
|
-
child.y = this.y + childY;
|
|
141
|
-
|
|
142
|
-
// Stocker la position relative
|
|
143
|
-
this.childPositions.set(child, { x: currentX, y: childY });
|
|
144
|
-
|
|
145
|
-
// Mettre à jour la position X pour l'enfant suivant
|
|
146
|
-
currentX += child.width;
|
|
147
|
-
|
|
148
|
-
// Ajouter le gap seulement si ce n'est pas le dernier enfant
|
|
149
|
-
if (i < this.children.length - 1) {
|
|
150
|
-
currentX += this.gap;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Marquer que les positions sont corrigées
|
|
156
|
-
this._positionsCorrected = true;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Dessine la carte et ses enfants
|
|
161
|
-
* @param {CanvasRenderingContext2D} ctx - Contexte de dessin
|
|
162
|
-
*/
|
|
163
|
-
draw(ctx) {
|
|
164
|
-
ctx.save();
|
|
165
|
-
|
|
166
|
-
// SOLUTION: Vérifier et corriger les positions AVANT de dessiner
|
|
167
|
-
// Ceci garantit que les enfants sont en coordonnées absolues
|
|
168
|
-
if (this._positionsCorrected) {
|
|
169
|
-
this._ensureAbsolutePositions();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Dessiner l'ombre si elevation > 0
|
|
173
|
-
if (this.elevation > 0) {
|
|
174
|
-
this.drawShadow(ctx);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Dessiner le fond de la carte
|
|
178
|
-
if (this.bgColor !== 'transparent') {
|
|
179
|
-
ctx.fillStyle = this.bgColor;
|
|
180
|
-
if (this.borderRadius > 0) {
|
|
181
|
-
ctx.beginPath();
|
|
182
|
-
this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
|
|
183
|
-
ctx.fill();
|
|
184
|
-
} else {
|
|
185
|
-
ctx.fillRect(this.x, this.y, this.width, this.height);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Dessiner les enfants
|
|
190
|
-
for (let child of this.children) {
|
|
191
|
-
if (child.visible) child.draw(ctx);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
ctx.restore();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* S'assure que tous les enfants ont des coordonnées absolues
|
|
199
|
-
* @private
|
|
200
|
-
*/
|
|
201
|
-
_ensureAbsolutePositions() {
|
|
202
|
-
for (let child of this.children) {
|
|
203
|
-
const relativePos = this.childPositions.get(child);
|
|
204
|
-
if (relativePos) {
|
|
205
|
-
// Recalculer la position absolue basée sur la position de la carte
|
|
206
|
-
const expectedX = this.x + relativePos.x;
|
|
207
|
-
const expectedY = this.y + relativePos.y;
|
|
208
|
-
|
|
209
|
-
// Corriger si nécessaire (important pour Vite Hot Reload)
|
|
210
|
-
if (Math.abs(child.x - expectedX) > 1 || Math.abs(child.y - expectedY) > 1) {
|
|
211
|
-
child.x = expectedX;
|
|
212
|
-
child.y = expectedY;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Met à jour la position de la carte et ajuste les enfants
|
|
220
|
-
* @param {number} x - Nouvelle position X
|
|
221
|
-
* @param {number} y - Nouvelle position Y
|
|
222
|
-
*/
|
|
223
|
-
setPosition(x, y) {
|
|
224
|
-
const deltaX = x - this.x;
|
|
225
|
-
const deltaY = y - this.y;
|
|
226
|
-
|
|
227
|
-
super.setPosition(x, y);
|
|
228
|
-
|
|
229
|
-
// Déplacer tous les enfants avec la carte
|
|
230
|
-
for (let child of this.children) {
|
|
231
|
-
child.x += deltaX;
|
|
232
|
-
child.y += deltaY;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Mettre à jour les positions relatives stockées
|
|
236
|
-
this._updateRelativePositions();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Met à jour les positions relatives stockées
|
|
241
|
-
* @private
|
|
242
|
-
*/
|
|
243
|
-
_updateRelativePositions() {
|
|
244
|
-
for (let [child, pos] of this.childPositions.entries()) {
|
|
245
|
-
// Les positions relatives ne changent pas quand la carte bouge
|
|
246
|
-
// On garde juste la référence
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Supprime un enfant
|
|
252
|
-
* @param {Component} child - Composant enfant à supprimer
|
|
253
|
-
* @returns {boolean} True si l'enfant a été supprimé
|
|
254
|
-
*/
|
|
255
|
-
remove(child) {
|
|
256
|
-
const index = this.children.indexOf(child);
|
|
257
|
-
if (index > -1) {
|
|
258
|
-
this.children.splice(index, 1);
|
|
259
|
-
this.childPositions.delete(child);
|
|
260
|
-
if (this.autoLayout) this.layout();
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Supprime tous les enfants
|
|
268
|
-
*/
|
|
269
|
-
clear() {
|
|
270
|
-
this.children = [];
|
|
271
|
-
this.childPositions.clear();
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Définit la position d'un enfant dans le système de coordonnées de la Card
|
|
276
|
-
* @param {Component} child - L'enfant à positionner
|
|
277
|
-
* @param {number} relativeX - Position X relative à la Card
|
|
278
|
-
* @param {number} relativeY - Position Y relative à la Card
|
|
279
|
-
*/
|
|
280
|
-
setChildPosition(child, relativeX, relativeY) {
|
|
281
|
-
if (this.children.includes(child)) {
|
|
282
|
-
// Définir en coordonnées absolues
|
|
283
|
-
child.x = this.x + relativeX;
|
|
284
|
-
child.y = this.y + relativeY;
|
|
285
|
-
this.childPositions.set(child, { x: relativeX, y: relativeY });
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Active/désactive le layout automatique
|
|
291
|
-
* @param {boolean} enabled - True pour activer le layout automatique
|
|
292
|
-
*/
|
|
293
|
-
setAutoLayout(enabled) {
|
|
294
|
-
this.autoLayout = enabled;
|
|
295
|
-
if (enabled) this.layout();
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Force un recalcul du layout
|
|
300
|
-
*/
|
|
301
|
-
updateLayout() {
|
|
302
|
-
this.layout();
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Génère les paramètres d'ombre selon le niveau d'élévation
|
|
307
|
-
* @param {number} elevation - Niveau d'élévation (0-5)
|
|
308
|
-
* @returns {Object} Configuration de l'ombre
|
|
309
|
-
* @private
|
|
310
|
-
*/
|
|
311
|
-
getShadowConfig(elevation) {
|
|
312
|
-
const shadows = [
|
|
313
|
-
{ blur: 0, offsetY: 0, color: 'transparent', spread: 0 },
|
|
314
|
-
{ blur: 2, offsetY: 1, color: 'rgba(0,0,0,0.12)', spread: 0 },
|
|
315
|
-
{ blur: 3, offsetY: 1, color: 'rgba(0,0,0,0.14)', spread: 0 },
|
|
316
|
-
{ blur: 4, offsetY: 2, color: 'rgba(0,0,0,0.16)', spread: 0 },
|
|
317
|
-
{ blur: 6, offsetY: 3, color: 'rgba(0,0,0,0.18)', spread: 0 },
|
|
318
|
-
{ blur: 8, offsetY: 4, color: 'rgba(0,0,0,0.20)', spread: 0 },
|
|
319
|
-
];
|
|
320
|
-
|
|
321
|
-
return shadows[Math.min(elevation, shadows.length - 1)];
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Dessine l'effet d'ombre selon l'élévation
|
|
326
|
-
* @param {CanvasRenderingContext2D} ctx - Contexte de dessin
|
|
327
|
-
* @private
|
|
328
|
-
*/
|
|
329
|
-
drawShadow(ctx) {
|
|
330
|
-
if (this.elevation <= 0) return;
|
|
331
|
-
|
|
332
|
-
const shadow = this.getShadowConfig(this.elevation);
|
|
333
|
-
|
|
334
|
-
ctx.save();
|
|
335
|
-
|
|
336
|
-
ctx.shadowColor = shadow.color;
|
|
337
|
-
ctx.shadowBlur = shadow.blur;
|
|
338
|
-
ctx.shadowOffsetX = 0;
|
|
339
|
-
ctx.shadowOffsetY = shadow.offsetY;
|
|
340
|
-
|
|
341
|
-
if (this.borderRadius > 0) {
|
|
342
|
-
ctx.beginPath();
|
|
343
|
-
this.roundRect(ctx, this.x, this.y + shadow.offsetY, this.width, this.height, this.borderRadius);
|
|
344
|
-
ctx.fillStyle = this.bgColor === 'transparent' ? 'white' : this.bgColor;
|
|
345
|
-
ctx.fill();
|
|
346
|
-
} else {
|
|
347
|
-
ctx.fillStyle = this.bgColor === 'transparent' ? 'white' : this.bgColor;
|
|
348
|
-
ctx.fillRect(this.x, this.y + shadow.offsetY, this.width, this.height);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
ctx.restore();
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Dessine un rectangle avec coins arrondis
|
|
356
|
-
* @param {CanvasRenderingContext2D} ctx - Contexte de dessin
|
|
357
|
-
* @param {number} x - Position X
|
|
358
|
-
* @param {number} y - Position Y
|
|
359
|
-
* @param {number} width - Largeur
|
|
360
|
-
* @param {number} height - Hauteur
|
|
361
|
-
* @param {number} radius - Rayon des coins
|
|
362
|
-
* @private
|
|
363
|
-
*/
|
|
364
|
-
roundRect(ctx, x, y, width, height, radius) {
|
|
365
|
-
if (radius === 0) {
|
|
366
|
-
ctx.rect(x, y, width, height);
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
ctx.beginPath();
|
|
371
|
-
ctx.moveTo(x + radius, y);
|
|
372
|
-
ctx.lineTo(x + width - radius, y);
|
|
373
|
-
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
374
|
-
ctx.lineTo(x + width, y + height - radius);
|
|
375
|
-
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
376
|
-
ctx.lineTo(x + radius, y + height);
|
|
377
|
-
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
378
|
-
ctx.lineTo(x, y + radius);
|
|
379
|
-
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
380
|
-
ctx.closePath();
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Vérifie si un point est dans les limites
|
|
385
|
-
* @param {number} x - Coordonnée X
|
|
386
|
-
* @param {number} y - Coordonnée Y
|
|
387
|
-
* @returns {boolean} True si le point est dans la vue
|
|
388
|
-
*/
|
|
389
|
-
isPointInside(x, y) {
|
|
390
|
-
return x >= this.x &&
|
|
391
|
-
x <= this.x + this.width &&
|
|
392
|
-
y >= this.y &&
|
|
393
|
-
y <= this.y + this.height;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Définit le niveau d'élévation
|
|
398
|
-
* @param {number} elevation - Nouveau niveau d'élévation (0-5)
|
|
399
|
-
*/
|
|
400
|
-
setElevation(elevation) {
|
|
401
|
-
this.elevation = Math.max(0, Math.min(elevation, 5));
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Augmente le niveau d'élévation
|
|
406
|
-
*/
|
|
407
|
-
raise() {
|
|
408
|
-
this.setElevation(this.elevation + 1);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Réduit le niveau d'élévation
|
|
413
|
-
*/
|
|
414
|
-
lower() {
|
|
415
|
-
this.setElevation(this.elevation - 1);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Définit l'espacement entre enfants
|
|
420
|
-
* @param {number} gap - Nouvel espacement
|
|
421
|
-
*/
|
|
422
|
-
setGap(gap) {
|
|
423
|
-
this.gap = Math.max(0, gap);
|
|
424
|
-
if (this.autoLayout) this.layout();
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Définit le padding
|
|
429
|
-
* @param {number} padding - Nouveau padding
|
|
430
|
-
*/
|
|
431
|
-
setPadding(padding) {
|
|
432
|
-
this.padding = Math.max(0, padding);
|
|
433
|
-
if (this.autoLayout) this.layout();
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Définit la direction du layout
|
|
438
|
-
* @param {string} direction - 'column' ou 'row'
|
|
439
|
-
*/
|
|
440
|
-
setDirection(direction) {
|
|
441
|
-
if (direction === 'column' || direction === 'row') {
|
|
442
|
-
this.direction = direction;
|
|
443
|
-
if (this.autoLayout) this.layout();
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Définit l'alignement
|
|
449
|
-
* @param {string} align - 'start', 'center', 'end' ou 'stretch'
|
|
450
|
-
*/
|
|
451
|
-
setAlign(align) {
|
|
452
|
-
if (['start', 'center', 'end', 'stretch'].includes(align)) {
|
|
453
|
-
this.align = align;
|
|
454
|
-
if (this.autoLayout) this.layout();
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Calcule la hauteur totale nécessaire pour contenir tous les enfants
|
|
460
|
-
* @returns {number} Hauteur totale nécessaire
|
|
461
|
-
*/
|
|
462
|
-
getTotalHeight() {
|
|
463
|
-
if (this.children.length === 0) return 0;
|
|
464
|
-
|
|
465
|
-
if (this.direction === 'column') {
|
|
466
|
-
const totalChildrenHeight = this.children.reduce((sum, child) => sum + child.height, 0);
|
|
467
|
-
const totalGapHeight = this.gap * Math.max(0, this.children.length - 1);
|
|
468
|
-
return totalChildrenHeight + totalGapHeight + (this.padding * 2);
|
|
469
|
-
}
|
|
470
|
-
return this.height;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Calcule la largeur totale nécessaire pour contenir tous les enfants
|
|
475
|
-
* @returns {number} Largeur totale nécessaire
|
|
476
|
-
*/
|
|
477
|
-
getTotalWidth() {
|
|
478
|
-
if (this.children.length === 0) return 0;
|
|
479
|
-
|
|
480
|
-
if (this.direction === 'row') {
|
|
481
|
-
const totalChildrenWidth = this.children.reduce((sum, child) => sum + child.width, 0);
|
|
482
|
-
const totalGapWidth = this.gap * Math.max(0, this.children.length - 1);
|
|
483
|
-
return totalChildrenWidth + totalGapWidth + (this.padding * 2);
|
|
484
|
-
}
|
|
485
|
-
return this.width;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Ajuste automatiquement la hauteur de la carte pour contenir tous les enfants
|
|
490
|
-
*/
|
|
491
|
-
fitHeight() {
|
|
492
|
-
if (this.direction === 'column') {
|
|
493
|
-
this.height = this.getTotalHeight();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* Ajuste automatiquement la largeur de la carte pour contenir tous les enfants
|
|
499
|
-
*/
|
|
500
|
-
fitWidth() {
|
|
501
|
-
if (this.direction === 'row') {
|
|
502
|
-
this.width = this.getTotalWidth();
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Ajuste automatiquement les dimensions de la carte pour contenir tous les enfants
|
|
508
|
-
*/
|
|
509
|
-
fitSize() {
|
|
510
|
-
this.fitWidth();
|
|
511
|
-
this.fitHeight();
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Met à jour les dimensions et relayout si autoLayout est activé
|
|
516
|
-
* @param {number} width - Nouvelle largeur
|
|
517
|
-
* @param {number} height - Nouvelle hauteur
|
|
518
|
-
*/
|
|
519
|
-
setSize(width, height) {
|
|
520
|
-
super.setSize(width, height);
|
|
521
|
-
if (this.autoLayout) this.layout();
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Obtient la position relative d'un enfant
|
|
526
|
-
* @param {Component} child - L'enfant
|
|
527
|
-
* @returns {Object|null} Position relative {x, y} ou null si non trouvé
|
|
528
|
-
*/
|
|
529
|
-
getChildPosition(child) {
|
|
530
|
-
return this.childPositions.get(child) || null;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
export default Card;
|