|
| 1 | +import "Srl/Console"; |
| 2 | +import "Apm"; |
| 3 | +Apm.importFile("Alusus/WebPlatform"); |
| 4 | +use Srl; |
| 5 | +use WebPlatform; |
| 6 | + |
| 7 | +//============================================================================== |
| 8 | +// Backend |
| 9 | + |
| 10 | +@assetsRoute def assetsRoute: "Assets/"; |
| 11 | + |
| 12 | +//============================================================================== |
| 13 | +// Frontend |
| 14 | + |
| 15 | +@uiEndpoint["/"] |
| 16 | +@title["WebPlatform Example - CheckBox"] |
| 17 | +func main { |
| 18 | + def statusText: SrdRef[Text]; |
| 19 | + |
| 20 | + // Build the view |
| 21 | + Window.instance.style.{ |
| 22 | + padding = Length4.pt(20); |
| 23 | + margin = Length4.pt(0); |
| 24 | + }; |
| 25 | + Window.instance.setView(Box({}).{ |
| 26 | + style.{ |
| 27 | + display = Display.FLEX; |
| 28 | + layout = Layout.COLUMN; |
| 29 | + gap = Length.pt(10); |
| 30 | + }; |
| 31 | + addChildren({ |
| 32 | + Text(String("CheckBox Test")).{ |
| 33 | + style.{ |
| 34 | + fontSize = Length.pt(24.0); |
| 35 | + fontWeight = 700; |
| 36 | + margin = Length4.pt(0, 0, 20, 0); |
| 37 | + }; |
| 38 | + }, |
| 39 | + |
| 40 | + Text(String("Select your preferences:")).{ |
| 41 | + style.{ |
| 42 | + fontSize = Length.pt(18.0); |
| 43 | + margin = Length4.pt(0, 0, 10, 0); |
| 44 | + }; |
| 45 | + }, |
| 46 | + |
| 47 | + // CheckBox options |
| 48 | + Box({}).{ |
| 49 | + style.{ |
| 50 | + display = Display.FLEX; |
| 51 | + layout = Layout.COLUMN; |
| 52 | + gap = Length.pt(8); |
| 53 | + margin = Length4.pt(0, 0, 0, 20); |
| 54 | + }; |
| 55 | + addChildren({ |
| 56 | + Box({}).{ |
| 57 | + style.{ |
| 58 | + display = Display.FLEX; |
| 59 | + layout = Layout.ROW; |
| 60 | + gap = Length.pt(8); |
| 61 | + align = Align.CENTER; |
| 62 | + }; |
| 63 | + addChildren({ |
| 64 | + CheckBox(String("newsletter"), true).{ |
| 65 | + onChanged.connect(closure (statusText: by_ref)&(widget: ref[CheckBox], payload: ref[Int]) { |
| 66 | + if widget.checked { |
| 67 | + statusText.setText(String("Newsletter: Subscribed")); |
| 68 | + } else { |
| 69 | + statusText.setText(String("Newsletter: Unsubscribed")); |
| 70 | + } |
| 71 | + }); |
| 72 | + }, |
| 73 | + Text(String("Subscribe to newsletter")); |
| 74 | + }); |
| 75 | + }, |
| 76 | + |
| 77 | + Box({}).{ |
| 78 | + style.{ |
| 79 | + display = Display.FLEX; |
| 80 | + layout = Layout.ROW; |
| 81 | + gap = Length.pt(8); |
| 82 | + align = Align.CENTER; |
| 83 | + }; |
| 84 | + addChildren({ |
| 85 | + CheckBox(String("updates")).{ |
| 86 | + onChanged.connect(closure (statusText: by_ref)&(widget: ref[CheckBox], payload: ref[Int]) { |
| 87 | + if widget.checked { |
| 88 | + statusText.setText(String("Updates: Enabled")); |
| 89 | + } else { |
| 90 | + statusText.setText(String("Updates: Disabled")); |
| 91 | + } |
| 92 | + }); |
| 93 | + }, |
| 94 | + Text(String("Receive updates")); |
| 95 | + }); |
| 96 | + }, |
| 97 | + |
| 98 | + Box({}).{ |
| 99 | + style.{ |
| 100 | + display = Display.FLEX; |
| 101 | + layout = Layout.ROW; |
| 102 | + gap = Length.pt(8); |
| 103 | + align = Align.CENTER; |
| 104 | + }; |
| 105 | + addChildren({ |
| 106 | + CheckBox(String("notifications")).{ |
| 107 | + onChanged.connect(closure (statusText: by_ref)&(widget: ref[CheckBox], payload: ref[Int]) { |
| 108 | + if widget.checked { |
| 109 | + statusText.setText(String("Notifications: Enabled")); |
| 110 | + } else { |
| 111 | + statusText.setText(String("Notifications: Disabled")); |
| 112 | + } |
| 113 | + }); |
| 114 | + }, |
| 115 | + Text(String("Enable notifications")); |
| 116 | + }); |
| 117 | + } |
| 118 | + }); |
| 119 | + }, |
| 120 | + |
| 121 | + Text(String("Newsletter: Subscribed")).{ |
| 122 | + statusText = this; |
| 123 | + style.{ |
| 124 | + fontSize = Length.pt(16.0); |
| 125 | + margin = Length4.pt(20, 0, 0, 0); |
| 126 | + fontWeight = FontWeight.BOLD; |
| 127 | + }; |
| 128 | + } |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | + runEventLoop(); |
| 133 | +} |
| 134 | + |
| 135 | +function startMyServer() { |
| 136 | + Console.print("Starting server on port 8010...\nURL: http://localhost:8010/\n"); |
| 137 | + buildAndRunServer(Array[CharsPtr]({ "listening_ports", "8010", "static_file_max_age", "0" })); |
| 138 | +} |
| 139 | + |
| 140 | +startMyServer(); |
0 commit comments