56 lines
1.3 KiB
Dart
56 lines
1.3 KiB
Dart
// 🧩 대시보드 타일의 격자 위치/크기(1x1 ~ 4x4)를 표현하는 값 객체.
|
|||
|
|
// 전체 배치 캔버스는 가로 6칸 × 세로 4칸으로 고정한다.
|
||
|
|
const int kGridCols = 6;
|
||
|
|
const int kGridRows = 4;
|
||
|
|
const int kMinTileSize = 1;
|
||
|
|
const int kMaxTileSize = 4;
|
||
|
|
|
||
|
|
class TileRect {
|
||
|
|
final int x;
|
||
|
|
final int y;
|
||
|
|
final int w;
|
||
|
|
final int h;
|
||
|
|
|
||
|
|
const TileRect({
|
||
|
|
required this.x,
|
||
|
|
required this.y,
|
||
|
|
required this.w,
|
||
|
|
required this.h,
|
||
|
|
});
|
||
|
|
|
||
|
|
factory TileRect.fromJson(Map<String, dynamic> json) => TileRect(
|
||
|
|
x: (json['x'] as num).toInt(),
|
||
|
|
y: (json['y'] as num).toInt(),
|
||
|
|
w: (json['w'] as num).toInt(),
|
||
|
|
h: (json['h'] as num).toInt(),
|
||
|
|
);
|
||
|
|
|
||
|
|
Map<String, dynamic> toJson(String id) => {
|
||
|
|
'id': id,
|
||
|
|
'x': x,
|
||
|
|
'y': y,
|
||
|
|
'w': w,
|
||
|
|
'h': h,
|
||
|
|
};
|
||
|
|
|
||
|
|
TileRect copyWith({int? x, int? y, int? w, int? h}) =>
|
||
|
|
TileRect(x: x ?? this.x, y: y ?? this.y, w: w ?? this.w, h: h ?? this.h);
|
||
|
|
|
||
|
|
bool overlaps(TileRect other) {
|
||
|
|
return x < other.x + other.w &&
|
||
|
|
x + w > other.x &&
|
||
|
|
y < other.y + other.h &&
|
||
|
|
y + h > other.y;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool get isWithinCanvas =>
|
||
|
|
x >= 0 &&
|
||
|
|
y >= 0 &&
|
||
|
|
x + w <= kGridCols &&
|
||
|
|
y + h <= kGridRows &&
|
||
|
|
w >= kMinTileSize &&
|
||
|
|
h >= kMinTileSize &&
|
||
|
|
w <= kMaxTileSize &&
|
||
|
|
h <= kMaxTileSize;
|
||
|
|
}
|