canvasframework 0.5.23 → 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.
- package/components/Card.js +101 -119
- package/package.json +1 -1
package/components/Card.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import Component from '../core/Component.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
|
-
* Carte avec ombre et
|
|
4
|
+
* Carte avec système de layout, ombre et bordures arrondies
|
|
4
5
|
* @class
|
|
5
6
|
* @extends Component
|
|
6
|
-
* @property {Component[]} children - Enfants
|
|
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 {
|
|
12
|
-
* @property {boolean}
|
|
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,134 +20,122 @@ 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
|
|
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.
|
|
32
|
-
|
|
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
|
|
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
|
|
|
54
57
|
/**
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
58
|
+
* Organise les enfants selon le layout
|
|
59
|
+
* @private
|
|
57
60
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
ctx.clip();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Children - dessinés relativement à la Card
|
|
88
|
-
for (let child of this.children) {
|
|
89
|
-
if (child.visible) {
|
|
90
|
-
// *** FIX : Utiliser ctx.translate au lieu de modifier child.x/y ***
|
|
91
|
-
ctx.save();
|
|
92
|
-
ctx.translate(this.x + this.padding, this.y + this.padding);
|
|
93
|
-
|
|
94
|
-
// Dessiner l'enfant (ses coordonnées sont déjà relatives)
|
|
95
|
-
child.draw(ctx);
|
|
96
|
-
|
|
97
|
-
ctx.restore();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
ctx.restore();
|
|
102
|
-
}
|
|
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
|
+
}
|
|
103
87
|
|
|
104
88
|
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
89
|
+
* Dessine la carte et ses enfants
|
|
90
|
+
* @param {CanvasRenderingContext2D} ctx - Contexte de dessin
|
|
91
|
+
*/
|
|
92
|
+
draw(ctx) {
|
|
93
|
+
ctx.save();
|
|
94
|
+
|
|
95
|
+
// Ombre (elevation)
|
|
96
|
+
if (this.elevation > 0) {
|
|
97
|
+
ctx.shadowColor = 'rgba(0, 0, 0, 0.15)';
|
|
98
|
+
ctx.shadowBlur = this.elevation * 3;
|
|
99
|
+
ctx.shadowOffsetY = this.elevation;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Background
|
|
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
|
+
}
|
|
113
|
+
|
|
114
|
+
// Réinitialiser l'ombre
|
|
115
|
+
ctx.shadowColor = 'transparent';
|
|
116
|
+
ctx.shadowBlur = 0;
|
|
117
|
+
ctx.shadowOffsetY = 0;
|
|
118
|
+
|
|
119
|
+
// Clipping (optionnel)
|
|
120
|
+
if (this.clipContent && this.borderRadius > 0) {
|
|
121
|
+
ctx.beginPath();
|
|
122
|
+
this.roundRect(ctx, this.x, this.y, this.width, this.height, this.borderRadius);
|
|
123
|
+
ctx.clip();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Children - coordonnées relatives à la Card
|
|
127
|
+
ctx.save();
|
|
128
|
+
ctx.translate(this.x, this.y);
|
|
129
|
+
|
|
130
|
+
for (let child of this.children) {
|
|
131
|
+
if (child.visible) {
|
|
132
|
+
child.draw(ctx);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
ctx.restore();
|
|
137
|
+
ctx.restore();
|
|
138
|
+
}
|
|
148
139
|
|
|
149
140
|
/**
|
|
150
141
|
* Dessine un rectangle avec coins arrondis
|
|
@@ -169,7 +160,7 @@ class Card extends Component {
|
|
|
169
160
|
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
170
161
|
ctx.closePath();
|
|
171
162
|
}
|
|
172
|
-
|
|
163
|
+
|
|
173
164
|
/**
|
|
174
165
|
* Vérifie si un point est dans les limites
|
|
175
166
|
* @param {number} x - Coordonnée X
|
|
@@ -182,15 +173,6 @@ class Card extends Component {
|
|
|
182
173
|
y >= this.y &&
|
|
183
174
|
y <= this.y + this.height;
|
|
184
175
|
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Gère le clic sur la carte
|
|
188
|
-
* @private
|
|
189
|
-
*/
|
|
190
|
-
onClick() {
|
|
191
|
-
// La Card elle-même peut avoir un onClick, mais on veut aussi vérifier les enfants
|
|
192
|
-
// Cette logique est gérée dans le CanvasFramework modifié ci-dessous
|
|
193
|
-
}
|
|
194
176
|
}
|
|
195
177
|
|
|
196
178
|
export default Card;
|