Skip to content

Commit

Permalink
Bugfix: dimension validation did not account for screen rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
sidoh committed Apr 19, 2020
1 parent 6a7c90f commit 5f036f0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions web/src/templates/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,17 +574,17 @@ export default function createSchema({
selectedFields,
allBitmaps,
allFormatters,
rotation
rotation,
}) {
const uniqueTypes = Array.from(new Set(selectedFields.map(x => x[0])));
const uniqueTypes = Array.from(new Set(selectedFields.map((x) => x[0])));

// If screen is rotated 90 or 270 deg, x and y bounds are flipped.
const xMax = (rotation % 2 == 0) ? screenMetadata.width : screenMetadata.height;
const yMax = (rotation % 2 == 0) ? screenMetadata.height : screenMetadata.width;
const xMax = rotation % 2 == 0 ? screenMetadata.width : screenMetadata.height;
const yMax = rotation % 2 == 0 ? screenMetadata.height : screenMetadata.width;

let enabledFields = {};

uniqueTypes.forEach(x => {
uniqueTypes.forEach((x) => {
const typeFields = FieldTypeDefinitions[x];

if (!enabledFields.properties) {
Expand All @@ -596,7 +596,7 @@ export default function createSchema({

enabledFields = {
type: "object",
properties: Object.fromEntries(overlappingFields)
properties: Object.fromEntries(overlappingFields),
};
}
});
Expand All @@ -605,25 +605,26 @@ export default function createSchema({
...enabledFields,
definitions: {
...Definitions,
...createColorDefinition({ colorStr: screenMetadata.colors }),
horizontalPosition: {
type: "integer",
minimum: 0,
maximum: xMax
maximum: xMax,
},
verticalPosition: {
type: "integer",
minimum: 0,
maximum: yMax
maximum: yMax,
},
storedBitmap: {
type: "string",
enum: allBitmaps
enum: allBitmaps,
},
storedFormatter: {
title: "Formatter",
type: "string",
enum: allFormatters
}
}
enum: allFormatters,
},
},
};
}

0 comments on commit 5f036f0

Please sign in to comment.