canvasframework 0.3.29 → 0.4.0

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.
@@ -170,7 +170,7 @@ class AndroidDatePickerDialog extends Component {
170
170
  ctx.shadowColor = 'transparent';
171
171
 
172
172
  // Header coloré
173
- ctx.fillStyle = '#6200EE';
173
+ ctx.fillStyle = this.headerBgColor;
174
174
  ctx.beginPath();
175
175
  this.roundRect(ctx, dialogX, dialogY, this.dialogWidth, this.headerHeight, 4);
176
176
  ctx.rect(dialogX, dialogY + this.headerHeight - 4, this.dialogWidth, 4);
@@ -191,7 +191,7 @@ class AndroidDatePickerDialog extends Component {
191
191
  const selectedMonth = monthNames[this.selectedDate.getMonth()];
192
192
  const selectedDayNum = this.selectedDate.getDate();
193
193
 
194
- ctx.fillStyle = '#000000';
194
+ ctx.fillStyle = '#ffffff';
195
195
  ctx.font = 'bold 32px Roboto, sans-serif';
196
196
  ctx.textBaseline = 'middle';
197
197
  ctx.fillText(`${selectedDay}, ${selectedMonth} ${selectedDayNum}`,
@@ -196,6 +196,11 @@ class CanvasFramework {
196
196
 
197
197
  this.components = [];
198
198
  this.theme = lightTheme; // thème par défaut
199
+ // ✅ AJOUTER ICI :
200
+ this._cachedMaxScroll = 0;
201
+ this._maxScrollDirty = true;
202
+ this.resizeTimeout = null;
203
+
199
204
  //this.applyThemeFromSystem();
200
205
  this.state = {};
201
206
  // NOUVELLE OPTION: choisir entre Canvas 2D et WebGL
@@ -1231,13 +1236,18 @@ class CanvasFramework {
1231
1236
  }
1232
1237
 
1233
1238
  getMaxScroll() {
1239
+ if (!this._maxScrollDirty) return this._cachedMaxScroll;
1240
+
1234
1241
  let maxY = 0;
1235
1242
  for (const comp of this.components) {
1236
1243
  if (this.isFixedComponent(comp) || !comp.visible) continue;
1237
1244
  const bottom = comp.y + comp.height;
1238
1245
  if (bottom > maxY) maxY = bottom;
1239
1246
  }
1240
- return Math.max(0, maxY - this.height + 50);
1247
+
1248
+ this._cachedMaxScroll = Math.max(0, maxY - this.height + 50);
1249
+ this._maxScrollDirty = false;
1250
+ return this._cachedMaxScroll;
1241
1251
  }
1242
1252
 
1243
1253
  /*getMaxScroll() {
@@ -1251,32 +1261,38 @@ class CanvasFramework {
1251
1261
  }*/
1252
1262
 
1253
1263
  handleResize() {
1254
- // Pour WebGL, NE PAS redimensionner automatiquement
1255
- if (!this.useWebGL) {
1256
- this.width = window.innerWidth;
1257
- this.height = window.innerHeight;
1258
- this.setupCanvas();
1264
+ if (this.resizeTimeout) clearTimeout(this.resizeTimeout); // AJOUTER
1265
+
1266
+ this.resizeTimeout = setTimeout(() => { // ✅ AJOUTER
1267
+ if (!this.useWebGL) {
1268
+ this.width = window.innerWidth;
1269
+ this.height = window.innerHeight;
1270
+ this.setupCanvas();
1259
1271
 
1260
- for (const comp of this.components) {
1261
- if (comp._resize) {
1262
- comp._resize(this.width, this.height);
1272
+ for (const comp of this.components) {
1273
+ if (comp._resize) {
1274
+ comp._resize(this.width, this.height);
1275
+ }
1263
1276
  }
1277
+ this._maxScrollDirty = true; // ✅ AJOUTER
1264
1278
  }
1265
- }
1279
+ }, 150); // ✅ AJOUTER (throttle 150ms)
1266
1280
  }
1267
1281
 
1268
1282
  add(component) {
1269
1283
  this.components.push(component);
1270
- component._mount();
1284
+ component._mount();
1285
+ this._maxScrollDirty = true; // ✅ AJOUTER CETTE LIGNE
1271
1286
  return component;
1272
1287
  }
1273
1288
 
1274
1289
  remove(component) {
1275
1290
  const index = this.components.indexOf(component);
1276
1291
  if (index > -1) {
1277
- component._unmount();
1278
- this.components.splice(index, 1);
1279
- }
1292
+ component._unmount();
1293
+ this.components.splice(index, 1);
1294
+ this._maxScrollDirty = true; // ✅ AJOUTER CETTE LIGNE
1295
+ }
1280
1296
  }
1281
1297
 
1282
1298
  markComponentDirty(component) {
@@ -1497,14 +1513,20 @@ class CanvasFramework {
1497
1513
  }
1498
1514
 
1499
1515
  // Scrollable
1500
- this.ctx.save();
1501
- this.ctx.translate(0, this.scrollOffset);
1502
- for (let comp of scrollableComponents) {
1503
- if (comp.visible) {
1504
- comp.draw(this.ctx);
1505
- }
1506
- }
1507
- this.ctx.restore();
1516
+ this.ctx.save();
1517
+ this.ctx.translate(0, this.scrollOffset);
1518
+ for (let comp of scrollableComponents) {
1519
+ if (comp.visible) {
1520
+ // ✅ Viewport culling : ne dessiner que ce qui est visible
1521
+ const screenY = comp.y + this.scrollOffset;
1522
+ const isInViewport = screenY + comp.height >= -100 && screenY <= this.height + 100;
1523
+
1524
+ if (isInViewport) {
1525
+ comp.draw(this.ctx);
1526
+ }
1527
+ }
1528
+ }
1529
+ this.ctx.restore();
1508
1530
 
1509
1531
  // Fixed
1510
1532
  for (let comp of fixedComponents) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasframework",
3
- "version": "0.3.29",
3
+ "version": "0.4.0",
4
4
  "description": "Canvas-based cross-platform UI framework (Material & Cupertino)",
5
5
  "type": "module",
6
6
  "main": "./index.js",