Skip to content

Commit

Permalink
Merge pull request #2045 from xodio/tweak-cpp-helpbox
Browse files Browse the repository at this point in the history
Add information about constants in C++ Cheatsheet (sidebar)
  • Loading branch information
brusherru authored Sep 23, 2020
2 parents 83eae10 + 701cc4b commit 36c8593
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
21 changes: 21 additions & 0 deletions packages/xod-client/src/core/styles/components/CppPatchDocs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 26 additions & 6 deletions packages/xod-client/src/editor/components/CppPatchDocs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) ? (
<span className="constant-notice">
<Icon name="warning" /> Must be defined as
<code>
<span className="keyword">static constexpr </span>
<span className="type">typeof_{getPinLabel(pin)} </span>
<span className="variable">{formatPinLabel(pin)} </span>
=
</code>
</span>
) : null;

const CppPatchDocs = ({ patch }) => {
const [inputPins, outputPins] = R.compose(
R.map(R.sort(R.ascend(XP.getPinOrder))),
Expand All @@ -24,9 +47,7 @@ const CppPatchDocs = ({ patch }) => {
<ul>
{inputPins.map(pin => (
<li key={XP.getPinKey(pin)}>
<span className="pin-label">
input_{cppEscape(XP.getPinLabel(pin))}
</span>
<span className="pin-label">{formatPinLabel(pin)}</span>
<span className={`pin-type ${XP.getPinType(pin)}`}>
{XP.getPinType(pin)}
</span>
Expand All @@ -41,12 +62,11 @@ const CppPatchDocs = ({ patch }) => {
<ul>
{outputPins.map(pin => (
<li key={XP.getPinKey(pin)}>
<span className="pin-label">
output_{cppEscape(XP.getPinLabel(pin))}
</span>
<span className="pin-label">{formatPinLabel(pin)}</span>
<span className={`pin-type ${XP.getPinType(pin)}`}>
{XP.getPinType(pin)}
</span>
{formatConstantOutputNotice(pin)}
</li>
))}
</ul>
Expand Down
5 changes: 5 additions & 0 deletions packages/xod-project/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

0 comments on commit 36c8593

Please sign in to comment.