Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information about constants in C++ Cheatsheet (sidebar) #2045

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
=
Comment on lines +23 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This explanation looks silly to me. An attempt to teach a particular nuance in very limited space. I think this should be omitted here and explained in other places: in the docs and (at some moment) in the auto-generated C++ template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea about the auto-generated C++ template sounds cool and I thought that's an awesome way. But now I think it's not so easy to implement. For example, what if C++ implementation already "touched", but only after that User added output-port?

About detailed explanation, in the docs, I totally agree. However, this is a rare case, I think when we create some nodes with the constant output. So I suppose that User will not use such snippet often and it might bring some pain to remember how to do it or go to the documentation page, instead of just copy-pasting the snippet.

So I propose to leave it as is.
At least for some time. Or until we bring some new snippets and "click-to-place" mechanism :)

</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)
);