Skip to content
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
41 changes: 30 additions & 11 deletions src/ui/widgets/BoolButton/boolButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ const BoolButtonProps = {
enabled: BoolPropOpt,
font: FontPropOpt,
textAlign: ChoicePropOpt(["left", "center", "right"]),
textAlignV: ChoicePropOpt(["top", "center", "bottom"])
textAlignV: ChoicePropOpt(["top", "center", "bottom"]),
onImage: StringPropOpt,
offImage: StringPropOpt
};

const Button = styled(MuiButton)({
Expand Down Expand Up @@ -102,7 +104,9 @@ export const BoolButtonComponent = (
labelsFromPv = false,
enabled = true,
textAlign = "center",
textAlignV = "center"
textAlignV = "center",
onImage,
offImage
} = newProps as BoolButtonComponentProps;
const {
value,
Expand Down Expand Up @@ -132,6 +136,7 @@ export const BoolButtonComponent = (
const [label, setLabel] = useState(showBooleanLabel ? offLabel : "");
const doubleValue = dTypeGetDoubleValue(value);
const [ledColor, setLedColor] = useState(style?.customColors?.offColor);
const [imageFileName, setImageFileName] = useState(offImage);

// Establish LED style
const ledDiameter = showLed ? getDimensions(size.width, size.height) : 0;
Expand All @@ -143,9 +148,11 @@ export const BoolButtonComponent = (
useEffect(() => {
if (doubleValue === onState) {
if (showBooleanLabel) setLabel(onLabel);
setImageFileName(onImage);
setLedColor(style?.customColors?.onColor);
} else if (doubleValue === offState) {
if (showBooleanLabel) setLabel(offLabel);
setImageFileName(offImage);
setLedColor(style?.customColors?.offColor);
}
}, [
Expand All @@ -156,7 +163,9 @@ export const BoolButtonComponent = (
style?.customColors?.onColor,
offState,
offLabel,
showBooleanLabel
showBooleanLabel,
onImage,
offImage
]);

function handleClick() {
Expand Down Expand Up @@ -194,19 +203,29 @@ export const BoolButtonComponent = (
}
}}
startIcon={
showLed ? (
<div
style={{ width: `${ledDiameter}px`, height: `${ledDiameter}px` }}
>
<div
style={{ width: `${ledDiameter}px`, height: `${ledDiameter}px` }}
>
{imageFileName ? (
<img
src={imageFileName}
alt=""
style={{
objectFit: "contain",
height: "100%",
width: "100%"
}}
/>
) : showLed ? (
<LedComponent
pvData={pvData}
onColor={newColor(style?.customColors?.onColor)}
offColor={newColor(style?.customColors?.offColor)}
/>
</div>
) : (
<></>
)
) : (
<></>
)}
</div>
}
>
{label}
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/EmbeddedDisplay/bobParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ export const BOB_SIMPLE_PARSERS: ParserDict = {
tabHeight: ["tab_height", bobParseNumber],
tabSpacing: ["tab_spacing", bobParseNumber],
activeTab: ["active_tab", bobParseNumber],
editable: ["editable", opiParseBoolean]
editable: ["editable", opiParseBoolean],
onImage: ["on_image", opiParseString],
offImage: ["off_image", opiParseString]
};

export const BOB_COMPLEX_PARSERS: ComplexParserDict = {
Expand Down
Loading