Skip to content

Commit

Permalink
Merge pull request #58 from dls-controls/add-graphics-widget-macros
Browse files Browse the repository at this point in the history
Add graphics widget macros
  • Loading branch information
abigailalexander authored Jun 14, 2024
2 parents 595882c + 8d3290f commit a7ea7ef
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/ui/hooks/useMacros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ export function useMacros<P extends MacroProps>(props: P): AnyProps {
const globalMacros = useSelector(
(state: CsState): MacroMap => state.globalMacros
);
// In Phoebus, some components e.g. Shape have a macros field
const propMacros = props.macros;
const allMacros = {
...globalMacros, // lower priority
...displayMacros, // higher priority
// Temporary special case for pv_name in macros.
pvName: props.pvName?.name || "",
pv_name: props.pvName?.name || ""
pv_name: props.pvName?.name || "",
...propMacros
};
return recursiveResolve(props, allMacros);
}
4 changes: 3 additions & 1 deletion src/ui/widgets/Arc/arc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {
BoolPropOpt,
InferWidgetProps,
ColorPropOpt,
IntPropOpt
IntPropOpt,
MacrosPropOpt
} from "../propTypes";
import classes from "./arc.module.css";
import { Color } from "../../../types";
import { WIDGET_DEFAULT_SIZES } from "../EmbeddedDisplay/bobParser";

const ArcProps = {
macros: MacrosPropOpt,
width: IntPropOpt,
height: IntPropOpt,
backgroundColor: ColorPropOpt,
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/Ellipse/ellipse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
InferWidgetProps,
BorderPropOpt,
ColorPropOpt,
IntPropOpt
IntPropOpt,
MacrosPropOpt
} from "../propTypes";
import { Color } from "../../../types/color";
import classes from "./ellipse.module.css";
Expand All @@ -23,6 +24,7 @@ export type FillOptions = {
};

export const EllipseProps = {
macros: MacrosPropOpt,
gradient: BoolPropOpt,
bgGradientColor: ColorPropOpt,
fgGradientColor: ColorPropOpt,
Expand Down
3 changes: 2 additions & 1 deletion src/ui/widgets/EmbeddedDisplay/bobParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ export function parseBob(
resize: ["resize", bobParseResizing],
squareLed: ["square", opiParseBoolean],
formatType: ["format", bobParseFormatType],
stretchToFit: ["stretch_image", opiParseBoolean]
stretchToFit: ["stretch_image", opiParseBoolean],
macros: ["macros", opiParseMacros]
};

const complexParsers = {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/EmbeddedDisplay/opiParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const opiParseRules = (
const pvs = pvArray.map((pv: ElementCompact) => {
return {
pvName: opiParsePvName(pv, defaultProtocol),
trigger: pv._attributes?.trig === "true"
trigger: isOpiFile ? pv._attributes?.trig === "true" : true
};
});
const expArray = toArray(ruleElement.exp);
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/Image/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
BoolPropOpt,
StringPropOpt,
FloatPropOpt,
FuncPropOpt
FuncPropOpt,
MacrosPropOpt
} from "../propTypes";
import { registerWidget } from "../register";

const ImageProps = {
imageFile: StringProp,
macros: MacrosPropOpt,
alt: StringPropOpt,
stretchToFit: BoolPropOpt,
fitToWidth: BoolPropOpt,
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/Label/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
FontPropOpt,
ColorPropOpt,
BorderPropOpt,
FloatPropOpt
FloatPropOpt,
MacrosPropOpt
} from "../propTypes";

const LabelProps = {
macros: MacrosPropOpt,
text: StringPropOpt,
visible: BoolPropOpt,
transparent: BoolPropOpt,
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/Line/line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
ColorPropOpt,
BoolPropOpt,
FloatProp,
PointsProp
PointsProp,
MacrosPropOpt
} from "../propTypes";
import { registerWidget } from "../register";
import { Color } from "../../../types/color";
Expand All @@ -19,6 +20,7 @@ const LineProps = {
width: FloatProp,
height: FloatProp,
points: PointsProp,
macros: MacrosPropOpt,
lineWidth: FloatPropOpt,
backgroundColor: ColorPropOpt,
visible: BoolPropOpt,
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/Polygon/polygon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
ColorPropOpt,
IntPropOpt,
BoolPropOpt,
PointsPropOpt
PointsPropOpt,
MacrosPropOpt
} from "../propTypes";
import { Point } from "../../../types/points";
import { Color } from "../../../types";
import { WIDGET_DEFAULT_SIZES } from "../EmbeddedDisplay/bobParser";

const PolygonProps = {
macros: MacrosPropOpt,
height: IntPropOpt,
width: IntPropOpt,
border: BorderPropOpt,
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/Shape/shape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
ColorPropOpt,
PvPropOpt,
IntPropOpt,
StringOrNumPropOpt
StringOrNumPropOpt,
MacrosPropOpt
} from "../propTypes";
import { Border, Color } from "../../../types";
import { WIDGET_DEFAULT_SIZES } from "../EmbeddedDisplay/bobParser";

const ShapeProps = {
pvName: PvPropOpt,
macros: MacrosPropOpt,
width: StringOrNumPropOpt,
height: StringOrNumPropOpt,
shapeTransform: StringPropOpt,
Expand Down

0 comments on commit a7ea7ef

Please sign in to comment.