Skip to content

Commit 25f7b82

Browse files
Make LEDs square
1 parent 8bfaf7b commit 25f7b82

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

src/ui/widgets/ByteMonitor/byteMonitor.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe("<ByteMonitorComponent />", (): void => {
5454
startBit: 8,
5555
numBits: 16,
5656
horizontal: false,
57-
squareLed: true,
57+
square: true,
5858
bitReverse: true,
5959
effect3d: false,
6060
onColor: Color.fromRgba(200, 200, 200),

src/ui/widgets/ByteMonitor/byteMonitor.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const ByteMonitorProps = {
2222
startBit: IntPropOpt,
2323
horizontal: BoolPropOpt,
2424
bitReverse: BoolPropOpt,
25-
squareLed: BoolPropOpt,
25+
square: BoolPropOpt,
2626
ledBorder: IntPropOpt,
2727
ledBorderColor: ColorPropOpt,
2828
effect3d: BoolPropOpt
@@ -49,8 +49,8 @@ export const ByteMonitorComponent = (
4949
onColor = Color.fromRgba(0, 255, 0),
5050
offColor = Color.fromRgba(0, 100, 0),
5151
ledBorder = 2,
52-
ledBorderColor = Color.fromRgba(150, 150, 150), // dark grey
53-
squareLed = false,
52+
ledBorderColor = Color.fromRgba(50, 50, 50, 178), // dark grey
53+
square = false,
5454
effect3d = false,
5555
width = WIDGET_DEFAULT_SIZES["byte_monitor"][0],
5656
height = WIDGET_DEFAULT_SIZES["byte_monitor"][1]
@@ -73,7 +73,7 @@ export const ByteMonitorComponent = (
7373
height,
7474
border,
7575
horizontal,
76-
squareLed
76+
square
7777
);
7878
const ledArray: Array<JSX.Element> = [];
7979
dataValues.forEach((data: number, idx: number) => {
@@ -94,7 +94,7 @@ export const ByteMonitorComponent = (
9494
style["borderColor"] = ledBorderColor.toString();
9595
style["borderWidth"] = `${borderWidth}px`;
9696
// Set shape as square or circular
97-
if (squareLed) {
97+
if (square) {
9898
style.width = `${bitWidth + borderWidth}px`;
9999
style.height = `${bitHeight + borderWidth}px`;
100100
} else {
@@ -113,7 +113,7 @@ export const ByteMonitorComponent = (
113113
style["backgroundImage"] = `radial-gradient(circle at top left, white, ${
114114
data ? onColor?.toString() : offColor?.toString()
115115
})`;
116-
if (!squareLed) {
116+
if (!square) {
117117
style["borderColor"] = "transparent";
118118
style["backgroundImage"] +=
119119
", radial-gradient(circle at top left, black,white)";

src/ui/widgets/EmbeddedDisplay/bobParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ const BOB_SIMPLE_PARSERS: ParserDict = {
421421
imageFile: ["file", opiParseString],
422422
points: ["points", bobParsePoints],
423423
resize: ["resize", bobParseResizing],
424-
squareLed: ["square", opiParseBoolean],
424+
square: ["square", opiParseBoolean],
425425
formatType: ["format", bobParseFormatType],
426426
stretchToFit: ["stretch_image", opiParseBoolean],
427427
macros: ["macros", opiParseMacros],

src/ui/widgets/EmbeddedDisplay/opiParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ export const OPI_SIMPLE_PARSERS: ParserDict = {
706706
ledBorder: ["led_border", opiParseNumber],
707707
ledBorderColor: ["led_border_color", opiParseColor],
708708
bitReverse: ["bitReverse", opiParseBoolean],
709+
square: ["square", opiParseBoolean],
709710
squareLed: ["square_led", opiParseBoolean],
710711
squareButton: ["square_button", opiParseBoolean],
711712
effect3d: ["effect_3d", opiParseBoolean],

src/ui/widgets/LED/led.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.Led {
22
width: 11px;
33
height: 11px;
4-
border-radius: 50%;
54
background-color: #00ee00;
65
}
76

src/ui/widgets/LED/led.test.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,24 @@ describe("width property is used", (): void => {
8686
// Width in CS-Studio doesn't quite match width in the browser,
8787
// so whatever is input has 5 subtracted from it, this makes it
8888
// look more like CS-Studio
89-
expect(renderedLed.props.style.width).toBe("5px");
90-
expect(renderedLed.props.style.height).toBe("15px");
89+
expect(renderedLed.props.style.width).toBe("10px");
90+
expect(renderedLed.props.style.height).toBe("20px");
9191
});
9292
});
9393

9494
describe("height property is used", (): void => {
9595
it("height changes the size of the LED", (): void => {
96-
const renderedLed = renderLed({ ...DEFAULT_PROPS, height: 10 });
96+
const renderedLed = renderLed({
97+
...DEFAULT_PROPS,
98+
height: 10,
99+
square: true
100+
});
97101

98102
// Width in CS-Studio doesn't quite match width in the browser,
99103
// so whatever is input has 5 subtracted from it, this makes it
100104
// look more like CS-Studio
101-
expect(renderedLed.props.style.width).toBe("15px");
102-
expect(renderedLed.props.style.height).toBe("5px");
105+
expect(renderedLed.props.style.width).toBe("20px");
106+
expect(renderedLed.props.style.height).toBe("10px");
107+
expect(renderedLed.props.style.borderRadius).toBe("0%");
103108
});
104109
});

src/ui/widgets/LED/led.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export const LedProps = {
2525
offColor: ColorPropOpt,
2626
lineColor: ColorPropOpt,
2727
alarmSensitive: BoolPropOpt,
28-
bit: IntPropOpt
28+
bit: IntPropOpt,
29+
square: BoolPropOpt
2930
};
3031

3132
export type LedComponentProps = InferWidgetProps<typeof LedProps> & PVComponent;
@@ -45,7 +46,8 @@ export const LedComponent = (props: LedComponentProps): JSX.Element => {
4546
width = WIDGET_DEFAULT_SIZES["led"][0],
4647
height = WIDGET_DEFAULT_SIZES["led"][1],
4748
alarmSensitive = false,
48-
bit = -1
49+
bit = -1,
50+
square = false
4951
} = props;
5052

5153
const { value } = getPvValueAndName(pvData);
@@ -65,11 +67,12 @@ export const LedComponent = (props: LedComponentProps): JSX.Element => {
6567
}
6668
style["backgroundColor"] = ledOn ? onColor?.toString() : offColor?.toString();
6769
style["border"] = `2px solid ${lineColor.toString()}`;
70+
style["borderRadius"] = square ? "0%" : "50%";
6871

6972
// make sizes similar to size in CS-Studio, five taken
7073
// away from default in css file too
71-
style.width = `${width - 5}px`;
72-
style.height = `${height - 5}px`;
74+
style.width = `${width}px`;
75+
style.height = `${height}px`;
7376

7477
let className = classes.Led;
7578
if (alarmSensitive) {

0 commit comments

Comments
 (0)