Skip to content

Commit c2f7ab4

Browse files
committed
blocks
1 parent bb1bd3e commit c2f7ab4

1 file changed

Lines changed: 99 additions & 14 deletions

File tree

guiComponents.ts

Lines changed: 99 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,25 @@ namespace microgui {
3131
* See getLeftAndTop in GUIComponentAbstract for how this is calculated.
3232
*/
3333

34-
//% block="Alignment" weight=100, color=#FF5733
34+
//% emitAsConstant color=#FF5733
3535
export const enum GUIComponentAlignment {
36+
//% block="TOP"
3637
TOP,
38+
//% block="LEFT"
3739
LEFT,
40+
//% block="RIGHT"
3841
RIGHT,
42+
//% block="BOT"
3943
BOT,
44+
//% block="CENTRE"
4045
CENTRE,
46+
//% block="TOP RIGHT"
4147
TOP_RIGHT,
48+
//% block="TOP LEFT"
4249
TOP_LEFT,
50+
//% block="BOT RIGHT"
4351
BOT_RIGHT,
52+
//% block="BOT LEFT"
4453
BOT_LEFT
4554
}
4655

@@ -309,12 +318,26 @@ namespace microgui {
309318
}
310319

311320

321+
//% block = "createTextBox" weight=50
322+
//% blockSetVariable=textBox
323+
export function createTextBox(isActive: boolean): TextBox {
324+
return new TextBox({
325+
alignment: GUIComponentAlignment.CENTRE,
326+
isActive,
327+
title: "Title",
328+
text: "Text",
329+
xScaling: 1.0,
330+
yScaling: 1.0,
331+
colour: 3,
332+
border: true,
333+
showBackground: true
334+
})
335+
}
336+
312337
/**
313338
* Component that contains a Title + a chunk of text.
314339
*/
315-
316-
317-
//% block="Text Box" weight=50, color=#F0A500
340+
//% autoCreate=microgui.createTextBox color=#5F7FF0
318341
export class TextBox extends GUIComponentAbstract {
319342
private title: string;
320343
private maxCharactersPerLine: number;
@@ -847,7 +870,27 @@ namespace microgui {
847870
// }
848871

849872

850-
//% block="Text Button" weight=50, color=#007777
873+
//% block="Create a text button | with text $text on click $callback || at x $x at y $y with colour $colour with text colour $textColour"
874+
//% blockSetVariable=textBtn
875+
export function createTextBtn(
876+
text: string,
877+
callback: () => void,
878+
x?: number,
879+
y?: number,
880+
colour?: number,
881+
textColour?: number
882+
): TextButton {
883+
return new TextButton({
884+
text,
885+
callback,
886+
x,
887+
y,
888+
colour,
889+
textColour
890+
});
891+
}
892+
893+
//% color=#007777
851894
export class TextButton {
852895
public bounds: Bounds;
853896
private shadowBounds: Bounds;
@@ -863,7 +906,7 @@ namespace microgui {
863906
text: string,
864907
callback: () => void,
865908
x?: number,
866-
y?: number
909+
y?: number,
867910
colour?: number,
868911
textColour?: number
869912
}) {
@@ -922,7 +965,39 @@ namespace microgui {
922965
}
923966

924967

925-
//% block="Text Button Collection" weight=50, color=#F077B3
968+
//% block="Create a text button collection | with alignment $alignment is active $isActive with buttons $textBtns || is hidden $isHidden with x offset $xOffset with y offset $yOffset with xScaling $xScaling with yScaling $yScaling with colour $colour has a border $border with title $title with text $text shows the background $showBackground"
969+
//% textBtns.defl = "createTextBtn"
970+
//% blockSetVariable=textBtnCollection
971+
export function createTextBtnCollection(
972+
alignment: GUIComponentAlignment,
973+
isActive: boolean,
974+
textBtns: TextButton[],
975+
isHidden?: boolean,
976+
xOffset?: number,
977+
yOffset?: number,
978+
xScaling?: number,
979+
yScaling?: number,
980+
colour?: number,
981+
border?: boolean,
982+
title?: string,
983+
text?: string[]
984+
): TextButtonCollection {
985+
return new TextButtonCollection({
986+
alignment,
987+
isActive,
988+
textBtns,
989+
isHidden,
990+
xOffset,
991+
yOffset,
992+
xScaling,
993+
yScaling,
994+
colour,
995+
border,
996+
title,
997+
text
998+
});
999+
}
1000+
9261001
export class TextButtonCollection extends GUIComponentAbstract {
9271002
private title: string;
9281003
private textBtns: TextButton[];
@@ -1072,8 +1147,6 @@ namespace microgui {
10721147
}
10731148
}
10741149
}
1075-
1076-
10771150
//% block="Radio Button" weight=50, color=#28edB3
10781151
export class RadioButton {
10791152
public text: string;
@@ -1286,21 +1359,34 @@ namespace microgui {
12861359
}
12871360

12881361

1362+
1363+
//% block="Create a component scene | on app $app with background colour $colour with components $components"
1364+
//% textBtns.defl = ""
1365+
//% blockSetVariable=componentScene
1366+
export function createComponentScene(
1367+
app: AppInterface,
1368+
colour?: number,
1369+
components?: GUIComponentAbstract[]
1370+
): GUIComponentScene {
1371+
return new GUIComponentScene({
1372+
app,
1373+
colour,
1374+
components
1375+
});
1376+
}
1377+
12891378
/**
12901379
* Holds other components,
12911380
* One component is active at a time
12921381
*/
1293-
1294-
//% block="Component Scene" weight=50, color=#40BF24
1382+
//% color=#40BF24
12951383
export class GUIComponentScene extends Scene {
12961384
private components: GUIComponentAbstract[];
12971385
private currentComponentID: number;
12981386

12991387
constructor(opts: {
13001388
app: AppInterface,
13011389
colour?: number,
1302-
next?: (arg0: any[]) => void,
1303-
back?: (arg0: any[]) => void,
13041390
components?: GUIComponentAbstract[]
13051391
}) {
13061392
super(opts.app)
@@ -1381,7 +1467,6 @@ namespace microgui {
13811467
this.components[this.currentComponentID].draw()
13821468
}
13831469
}
1384-
13851470
//% block="Button Collection" weight=50, color=#F5F575
13861471
export class ButtonCollection extends GUIComponentAbstract {
13871472
private btns: Button[][];

0 commit comments

Comments
 (0)