Skip to content

Commit

Permalink
refactor: introduce EnumRecord ensuring iterable and length-property (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
timkurvers authored Apr 9, 2024
1 parent e592aa6 commit 84bea0a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/ui/components/UIRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import DrawLayerType from '../DrawLayerType';
import Screen from '../../gfx/Screen';
import ScreenLayer from '../../gfx/ScreenLayer';
import { EdgeRect } from '../../math';
import { LinkedList, NDCtoDDCWidth, NDCtoDDCHeight } from '../../utils';
import { EnumRecord, LinkedList, NDCtoDDCWidth, NDCtoDDCHeight } from '../../utils';

import Frame, { FrameFlag } from './simple/Frame';
import FramePointType from './abstract/FramePointType';
Expand All @@ -16,7 +16,7 @@ class UIRoot extends LayoutFrame {
frame: Frame | null,
anchor: FramePointType
};
strata: Record<FrameStrataType, FrameStrata> & Iterable<FrameStrata>;
strata: EnumRecord<FrameStrataType, FrameStrata>;
frames: LinkedList<Frame>;
destroyedFrames: LinkedList<Frame>;
screenLayer: ScreenLayer;
Expand Down Expand Up @@ -112,7 +112,7 @@ class UIRoot extends LayoutFrame {
onLayerUpdate(elapsedSecs: number) {
// TODO: Clean-up destroyed frames

console.log('root pre-render', this);
console.log('root pre-render');

LayoutFrame.resizePending();

Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/abstract/FrameStrataLevel.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import DrawLayerType from '../../DrawLayerType';
import Frame from '../simple/Frame';
import RenderBatch from '../../rendering/RenderBatch';
import { LinkedList } from '../../../utils';
import { EnumRecord, LinkedList } from '../../../utils';

class FrameStrataLevel {
index: number;
pendingFrames: LinkedList<Frame>;
frames: LinkedList<Frame>;
pendingFrame?: Frame;
batches: Record<DrawLayerType, RenderBatch> & Iterable<RenderBatch>;
batches: EnumRecord<DrawLayerType, RenderBatch>;
batchDirty: number;
renderList: LinkedList<RenderBatch>;

Expand Down
3 changes: 2 additions & 1 deletion src/ui/components/abstract/LayoutFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
areClose,
} from '../../../math';
import {
EnumRecord,
LinkedList,
LinkedListLink,
LinkedListNode,
Expand Down Expand Up @@ -59,7 +60,7 @@ class LayoutFrame {
resizeCounter: number;
_resizePendingLink?: LinkedListLink<LayoutFrame>;

points: Record<FramePointType, FramePoint | null> & Iterable<FramePoint | null>;
points: EnumRecord<FramePointType, FramePoint | null>;

constructor() {
this.layoutFlags = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/ui/components/simple/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ScriptRegion from '../abstract/ScriptRegion';
import UIContext from '../../UIContext';
import XMLNode from '../../XMLNode';
import {
EnumRecord,
LinkedList,
LinkedListLink,
LinkedListNode,
Expand Down Expand Up @@ -53,7 +54,7 @@ class Frame extends ScriptRegion {
strataType: FrameStrataType;
level: number;

layersEnabled: Record<DrawLayerType, boolean> & Iterable<boolean>;
layersEnabled: EnumRecord<DrawLayerType, boolean>;
backdrop: Backdrop | null;

regions: LinkedList<Region>;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type EnumRecord<E extends string | number | symbol, V> = Record<E, V> & Iterable<V> & { length: number };

// See: https://github.com/microsoft/TypeScript/issues/5863#issuecomment-1336204919
export type ThisConstructor<
T extends { prototype: unknown } = { prototype: unknown },
Expand Down

0 comments on commit 84bea0a

Please sign in to comment.