Skip to content

Commit

Permalink
Merge pull request regl-project#528 from benjamind/delarre/nested-dyn…
Browse files Browse the repository at this point in the history
…amic-types

Nested dynamic types
  • Loading branch information
rreusser authored Sep 12, 2019
2 parents 2f9fe61 + 5372146 commit 0cf38ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions example/typescript/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ const draw = regl<Uniforms, Attributes, Props>({
enable: false
},

scissor: {
enable: true,
box: ({ tick, viewportWidth, viewportHeight }) => {
const SCISSOR_TIME = 500;
const percent = (tick % SCISSOR_TIME) / SCISSOR_TIME;
const scaleFactor = (percent >= 0.5 ? 1 - percent : percent) * 2.0;
return {
x: (viewportWidth / 2) * scaleFactor,
y: (viewportHeight / 2) * scaleFactor,
width: viewportWidth - viewportWidth * scaleFactor,
height: viewportHeight - viewportHeight * scaleFactor
};
}
},

count: 3
})

Expand Down
5 changes: 4 additions & 1 deletion regl.d.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ declare namespace REGL {
DynamicVariable<Type> |
DynamicVariableFn<Type, Context, Props>;

type MaybeNestedDynamic<Type, Context extends REGL.DefaultContext, Props extends {}> =
{ [K in keyof Type]: MaybeDynamic<Type[K], Context, Props> };

interface ClearOptions {
/**
* RGBA values (range 0-1) to use when the color buffer is cleared. Initial value: [0, 0, 0, 0].
Expand Down Expand Up @@ -604,7 +607,7 @@ declare namespace REGL {

/* Scissor */

scissor?: MaybeDynamic<REGL.ScissorOptions, ParentContext & OwnContext, Props>;
scissor?: MaybeNestedDynamic<REGL.ScissorOptions, ParentContext & OwnContext, Props>;

/* Viewport */

Expand Down

0 comments on commit 0cf38ff

Please sign in to comment.