Connect Start Button through Angular
This commit is contained in:
parent
843dad6cbb
commit
96a5bd0cec
3 changed files with 14 additions and 8 deletions
|
@ -5,11 +5,13 @@ import 'package:rules_of_living/src/App.dart';
|
||||||
|
|
||||||
@Component(
|
@Component(
|
||||||
selector: 'my-app',
|
selector: 'my-app',
|
||||||
|
templateUrl: "app_component.html"
|
||||||
)
|
)
|
||||||
class AppComponent implements OnInit {
|
class AppComponent implements OnInit {
|
||||||
var name = "World";
|
var name = "World";
|
||||||
|
|
||||||
App engine;
|
App engine;
|
||||||
|
String buttonRunText = "Start";
|
||||||
|
|
||||||
@ViewChild("caCanvas")
|
@ViewChild("caCanvas")
|
||||||
html.CanvasElement canvas;
|
html.CanvasElement canvas;
|
||||||
|
@ -26,4 +28,14 @@ class AppComponent implements OnInit {
|
||||||
engine.process(now);
|
engine.process(now);
|
||||||
html.window.animationFrame.then(animFrame);
|
html.window.animationFrame.then(animFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onStartClicked() {
|
||||||
|
bool isRunning = !engine.running;
|
||||||
|
engine.running = isRunning;
|
||||||
|
|
||||||
|
switch (isRunning) {
|
||||||
|
case true: buttonRunText = "Stop"; break;
|
||||||
|
case false: buttonRunText = "Start"; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<canvas #caCanvas width="500" height="500"></canvas>
|
<canvas #caCanvas width="500" height="500"></canvas>
|
||||||
</div>
|
</div>
|
||||||
<div id="controls">
|
<div id="controls">
|
||||||
<button id="run" >Run</button>
|
<button id="run" (click)="onStartClicked()">{{buttonRunText}}</button>
|
||||||
<button id="step">Step</button>
|
<button id="step">Step</button>
|
||||||
<button id="reset">Reset</button>
|
<button id="reset">Reset</button>
|
||||||
<button id="random">Random</button>
|
<button id="random">Random</button>
|
||||||
|
|
|
@ -25,12 +25,6 @@ class App {
|
||||||
|
|
||||||
App(this.canvas) {
|
App(this.canvas) {
|
||||||
_elapsed.start();
|
_elapsed.start();
|
||||||
var runBtn = html.querySelector("#run");
|
|
||||||
runBtn.onClick.forEach((html.MouseEvent mouse) {
|
|
||||||
running = !running;
|
|
||||||
if(running) runBtn.innerHtml = "Stop";
|
|
||||||
if(!running) runBtn.innerHtml = "Start";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void process(num now) {
|
void process(num now) {
|
||||||
|
@ -56,7 +50,7 @@ class App {
|
||||||
|
|
||||||
void update() {
|
void update() {
|
||||||
// print("updating");
|
// print("updating");
|
||||||
if (running) grid.update();
|
if (running == true) grid.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue