Skip to content

Commit 5e45110

Browse files
Hannes KruseHannes Kruse
authored andcommitted
Merge branch 'feature/value_modification' into develop
2 parents 5df81be + 8327512 commit 5e45110

File tree

4 files changed

+82
-18
lines changed

4 files changed

+82
-18
lines changed

src/lib/menu/checkbox.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import ColorFactory from "../../utlis/color-factory";
44
import {Path, Rectangle, Size} from "paper";
55
import {ZERO_POINT as CENTER} from "../constants";
66

7+
/**
8+
* A Checkbox is either selected or not
9+
*/
710
export default class Checkbox extends MenuItem {
11+
public readonly TYPE = 'checkbox';
12+
813
/**
914
* Selection Flag
1015
*/
@@ -21,14 +26,27 @@ export default class Checkbox extends MenuItem {
2126
}
2227
}
2328

29+
/**
30+
* Set the checkbox state to deselected
31+
*/
2432
public deselect(): void {
2533
this.itemSelected = false;
2634
}
2735

36+
/**
37+
* Set the checkbox state to selected
38+
*/
2839
public select(): void {
2940
this.itemSelected = true;
3041
}
3142

43+
/**
44+
* True if checkbox is selected
45+
*/
46+
public isSelected(): boolean {
47+
return this.itemSelected === true;
48+
}
49+
3250
/**
3351
* @see setGeometryColorSelected
3452
*/

src/lib/menu/menu-parser.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class MenuParser {
1010
/**
1111
* List of already used menu item ids
1212
*/
13-
private itemIds: Map<string, MenuItem> = new Map<string, MenuItem>();
13+
private _itemIds: Map<string, MenuItem> = new Map<string, MenuItem>();
1414

1515
/**
1616
* Parses a JSON Structure to Menu Items
@@ -39,6 +39,7 @@ export default class MenuParser {
3939
item = new Crankslider(structure.id, structure.direction, structure.text, structure.icon);
4040
break;
4141

42+
case 'slider':
4243
case 'ribbonslider':
4344
item = new Ribbonslider(structure.id, structure.direction, structure.text, structure.icon);
4445
break;
@@ -47,6 +48,7 @@ export default class MenuParser {
4748
item = new Checkbox(structure.id, structure.direction, structure.text, structure.icon);
4849
break;
4950

51+
case 'radiogroup':
5052
case 'radio-group':
5153
item = new RadioGroup(structure.id, structure.direction, structure.text, structure.icon);
5254
break;
@@ -60,7 +62,7 @@ export default class MenuParser {
6062
MenuParser.checkAngles(item);
6163
}
6264

63-
this.itemIds.set(structure.id, item);
65+
this._itemIds.set(structure.id, item);
6466

6567
structure.children && structure.children.forEach((child): void => {
6668
this.parse(child, item);
@@ -73,15 +75,22 @@ export default class MenuParser {
7375
return item;
7476
}
7577

78+
/**
79+
* Parsed menu structure accessible through the item id
80+
*/
81+
public get map(): Map<string, MenuItem> {
82+
return this._itemIds;
83+
}
84+
7685
/**
7786
* Checks if an item id is already in use by another item.
7887
* Writes a warning to the console
7988
*
8089
* @param {string} itemId
8190
*/
8291
private checkIds(itemId: string): void {
83-
if (this.itemIds.has(itemId)) {
84-
const item = this.itemIds.get(itemId) as MenuItem;
92+
if (this._itemIds.has(itemId)) {
93+
const item = this._itemIds.get(itemId) as MenuItem;
8594
console.warn(`Menu Item ID '${itemId}' already in use by Menu Item '${item.itemId}' with Parent '${(item.parent as MenuItem).itemId}'.`);
8695
}
8796
}

src/lib/menu/radio-group.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,41 @@ import MenuItem from "./menu-item";
22
import Checkbox from "./checkbox";
33
import {ItemState, MenuItemEventType} from "../enums";
44

5+
/**
6+
* A Radio group contains >=2 Checkboxes of which only one can be active at a given time
7+
*/
58
export default class RadioGroup extends MenuItem {
9+
public readonly TYPE = 'radiogroup';
10+
11+
/**
12+
* Selects a single child from the radio group
13+
*
14+
* @param {string} itemId
15+
*/
16+
public select(itemId: string) {
17+
const toSelect = <Checkbox | undefined>this.getChildren().find(item => {
18+
return item.itemId === itemId;
19+
});
20+
21+
if (typeof toSelect === "undefined") {
22+
return;
23+
}
24+
25+
this.deselectChildren();
26+
toSelect.select();
27+
}
28+
29+
/**
30+
* Deselect all children to ensure only one is active
31+
*
32+
* @inheritDoc
33+
*/
634
protected changeActive(): void {
735
if (this.state !== ItemState.ACTIVE) {
836
return;
937
}
1038

11-
(<Checkbox[]>this.getChildren()).forEach(child => {
12-
child.deselect();
13-
});
39+
this.deselectChildren();
1440

1541
this.activeChild = this.getNearestChild(this.angleToReferencePoint(this.menu.inputPosition));
1642

@@ -23,10 +49,19 @@ export default class RadioGroup extends MenuItem {
2349
this.event(MenuItemEventType.HOVER_SELECTION, this.activeChild);
2450
} else {
2551
this.activeChild.state = ItemState.SELECTED;
26-
(this.activeChild as Checkbox).select();
52+
(<Checkbox>this.activeChild).select();
2753
}
2854
}
2955

3056
this.root.redraw();
3157
}
58+
59+
/**
60+
* Set checkbox state to deselect
61+
*/
62+
private deselectChildren(): void {
63+
(<Checkbox[]>this.getChildren()).forEach(child => {
64+
child.deselect();
65+
});
66+
}
3267
}

src/lib/menu/ribbonslider.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import Arc from "../../utlis/arc";
2121
import {precision, roundNumber} from "../../utlis/numbers";
2222

2323
export default class Ribbonslider extends MenuItem {
24+
public readonly TYPE = 'ribbonslider';
25+
2426
/**
2527
* Group holding
2628
* - Ribbon
@@ -156,7 +158,7 @@ export default class Ribbonslider extends MenuItem {
156158
* @param value number Slider value
157159
* @see {throttledTextUpdate}
158160
*/
159-
private set value(value: number) {
161+
public set value(value: number) {
160162
if (this._value === value) {
161163
return;
162164
}
@@ -166,6 +168,15 @@ export default class Ribbonslider extends MenuItem {
166168
this.throttledTextUpdate('' + value);
167169
}
168170

171+
/**
172+
* Accessor
173+
*
174+
* @see {_value}
175+
*/
176+
public get value(): number {
177+
return this._value;
178+
}
179+
169180
/**
170181
* Accessor
171182
*
@@ -231,15 +242,6 @@ export default class Ribbonslider extends MenuItem {
231242
return this._ribbonMaskGroup;
232243
}
233244

234-
/**
235-
* Accessor
236-
*
237-
* @see {_value}
238-
*/
239-
private get value(): number {
240-
return this._value;
241-
}
242-
243245
/**
244246
* Moves the Ribbon to a given position of a slider value
245247
* @param value

0 commit comments

Comments
 (0)