From 99ebd038918cbb7404c0188b976d7f5a3b4717c9 Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Mon, 21 Sep 2020 21:05:32 +0300 Subject: [PATCH 1/2] tweak(xod-project): add and import utility function `isConstantType` into xod-project --- packages/xod-project/src/utils.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/xod-project/src/utils.js b/packages/xod-project/src/utils.js index f03ce04a7..99f0fc70a 100644 --- a/packages/xod-project/src/utils.js +++ b/packages/xod-project/src/utils.js @@ -253,3 +253,8 @@ export const isValidLiteral = def( 'isValidLiteral :: DataValue -> Boolean', R.pipe(getTypeFromLiteral, Either.isRight) ); + +export const isConstantType = def( + 'isConstantType :: DataType -> Boolean', + isAmong(CONST.CONSTANT_PIN_TYPES) +); From 701cc4b9deabe79c754a3168be9a94476a37c1f1 Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Mon, 21 Sep 2020 21:07:25 +0300 Subject: [PATCH 2/2] tweak(xod-client): show constants in C++ Cheatshet and also show a warning message for output constants with code example --- .../core/styles/components/CppPatchDocs.scss | 21 ++++++++++++ .../src/editor/components/CppPatchDocs.jsx | 32 +++++++++++++++---- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/packages/xod-client/src/core/styles/components/CppPatchDocs.scss b/packages/xod-client/src/core/styles/components/CppPatchDocs.scss index 131cd2ce9..2105eea16 100644 --- a/packages/xod-client/src/core/styles/components/CppPatchDocs.scss +++ b/packages/xod-client/src/core/styles/components/CppPatchDocs.scss @@ -44,6 +44,27 @@ &.port { color: $color-datatype-port } } + .constant-notice { + display: block; + margin-top: .5em; + font-size: $font-size-s; + + .fa { margin-left: 1px; } + + code { + display: block; + padding: 0.4em; + background: $coal; + border-radius: 2px; + + font-size: $font-size-m; + + .keyword { color: #E67CDC; } + .type { color: $apricot-light; } + .variable { color: $blueberry; } + } + } + a { color: $color-canvas-selected; cursor: pointer; diff --git a/packages/xod-client/src/editor/components/CppPatchDocs.jsx b/packages/xod-client/src/editor/components/CppPatchDocs.jsx index d36331ad7..0100bc8b3 100644 --- a/packages/xod-client/src/editor/components/CppPatchDocs.jsx +++ b/packages/xod-client/src/editor/components/CppPatchDocs.jsx @@ -7,6 +7,29 @@ import Icon from 'react-fa'; import { getUtmSiteUrl } from '../../utils/urls'; +const getPinLabel = R.compose(cppEscape, XP.getPinLabel); + +const formatPinLabel = pin => + [ + XP.isConstantType(pin.type) ? 'constant_' : '', + XP.getPinDirection(pin), + '_', + getPinLabel(pin), + ].join(''); + +const formatConstantOutputNotice = pin => + XP.isConstantType(pin.type) ? ( + + Must be defined as + + static constexpr + typeof_{getPinLabel(pin)} + {formatPinLabel(pin)} + = + + + ) : null; + const CppPatchDocs = ({ patch }) => { const [inputPins, outputPins] = R.compose( R.map(R.sort(R.ascend(XP.getPinOrder))), @@ -24,9 +47,7 @@ const CppPatchDocs = ({ patch }) => {