From 43bdf9352dbed72b0eb7dd995ef47327e93f8ab8 Mon Sep 17 00:00:00 2001 From: Pasha Stetsenko Date: Sat, 8 Jan 2022 19:07:57 -0800 Subject: [PATCH 1/3] feat(sandbox): Added top menu with control buttons --- analysis_options.yaml | 6 ++-- sandbox/lib/main.dart | 47 +++++++++++++++++++++++++-- sandbox/lib/presets.dart | 4 +-- sandbox/lib/widgets/left_menu.dart | 2 +- sandbox/lib/widgets/scene_widget.dart | 14 ++++++++ sandbox/lib/widgets/top_menu.dart | 34 +++++++++++++++++++ 6 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 sandbox/lib/widgets/top_menu.dart diff --git a/analysis_options.yaml b/analysis_options.yaml index b3c2d75..f7f5824 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,5 +1,5 @@ include: package:flame_lint/analysis_options.yaml -analyzer: - exclude: - - sandbox/** +#analyzer: +# exclude: +# - sandbox/** diff --git a/sandbox/lib/main.dart b/sandbox/lib/main.dart index e6ea822..90d28ea 100644 --- a/sandbox/lib/main.dart +++ b/sandbox/lib/main.dart @@ -4,12 +4,28 @@ import 'presets.dart'; import 'scene.dart'; import 'widgets/left_menu.dart'; import 'widgets/scene_widget.dart'; +import 'widgets/top_menu.dart'; void main() { runApp( MaterialApp( title: 'Radiance sandbox', - theme: ThemeData.dark(), + theme: ThemeData( + brightness: Brightness.dark, + textButtonTheme: TextButtonThemeData( + style: ButtonStyle( + minimumSize: MaterialStateProperty.all(const Size(30, 30)), + padding: MaterialStateProperty.all(const EdgeInsets.all(5)), + foregroundColor: MaterialStateProperty.resolveWith( + (Set states) => + states.contains(MaterialState.disabled) + ? const Color(0xFF5F5F5F) + : const Color(0xFFBBBBBB), + ), + overlayColor: MaterialStateProperty.all(const Color(0xFF555555)), + ), + ), + ), home: const _MyApp(), ), ); @@ -23,8 +39,28 @@ class _MyApp extends StatefulWidget { } class SandboxState extends State<_MyApp> { + SandboxState() { + currentScene = kPresets[currentPreset](); + } + int currentPreset = 0; - Scene get currentScene => kPresets[currentPreset]; + EngineState engineState = EngineState.running; + late Scene currentScene; + + void startEngine() { + setState(() => engineState = EngineState.running); + } + + void pauseEngine() { + setState(() => engineState = EngineState.paused); + } + + void stopEngine() { + setState(() { + engineState = EngineState.stopped; + currentScene = kPresets[currentPreset](); + }); + } @override Widget build(BuildContext context) { @@ -49,6 +85,7 @@ class SandboxState extends State<_MyApp> { Container( constraints: const BoxConstraints.expand(height: 40), color: Theme.of(context).cardColor, + child: TopMenu(this), ), // Main canvas area Expanded( @@ -81,3 +118,9 @@ class SandboxState extends State<_MyApp> { ); } } + +enum EngineState { + running, + paused, + stopped, +} diff --git a/sandbox/lib/presets.dart b/sandbox/lib/presets.dart index 9d3baa5..d3e57d1 100644 --- a/sandbox/lib/presets.dart +++ b/sandbox/lib/presets.dart @@ -5,8 +5,8 @@ import 'entities/max_acceleration_entity.dart'; import 'entities/static_target_entity.dart'; import 'scene.dart'; -final kPresets = [ - _seek(), +final kPresets = [ + _seek, ]; Scene _seek() { diff --git a/sandbox/lib/widgets/left_menu.dart b/sandbox/lib/widgets/left_menu.dart index f3eedcd..9ca0ff0 100644 --- a/sandbox/lib/widgets/left_menu.dart +++ b/sandbox/lib/widgets/left_menu.dart @@ -74,7 +74,7 @@ class _ListItemState extends State<_ListItem> { child: Padding( padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 4), child: Text( - kPresets[widget.index].name, + widget.app.currentScene.name, style: isCurrent ? styleWhenCurrent : null, ), ), diff --git a/sandbox/lib/widgets/scene_widget.dart b/sandbox/lib/widgets/scene_widget.dart index a593de3..124a44f 100644 --- a/sandbox/lib/widgets/scene_widget.dart +++ b/sandbox/lib/widgets/scene_widget.dart @@ -16,6 +16,7 @@ class SceneWidget extends StatefulWidget { class _SceneWidgetState extends State { Ticker? ticker; Duration currentTime = Duration.zero; + EngineState currentState = EngineState.running; double dt = 0.0; void _handleTick(Duration time) { @@ -26,6 +27,16 @@ class _SceneWidgetState extends State { }); } + void _handleStateChange() { + if (widget.app.engineState == EngineState.running) { + ticker?.start(); + } else { + ticker?.stop(); + currentTime = Duration.zero; + } + currentState = widget.app.engineState; + } + @override void initState() { super.initState(); @@ -40,6 +51,9 @@ class _SceneWidgetState extends State { @override Widget build(BuildContext context) { + if (currentState != widget.app.engineState) { + _handleStateChange(); + } return Align( child: AspectRatio( aspectRatio: 100 / 80, diff --git a/sandbox/lib/widgets/top_menu.dart b/sandbox/lib/widgets/top_menu.dart new file mode 100644 index 0000000..9e358a4 --- /dev/null +++ b/sandbox/lib/widgets/top_menu.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; +import '../main.dart'; + +class TopMenu extends StatelessWidget { + const TopMenu(this.app); + + final SandboxState app; + + @override + Widget build(BuildContext context) { + final canPause = app.engineState == EngineState.running; + final canStop = app.engineState != EngineState.stopped; + return Padding( + padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 10), + child: Row( + children: [ + TextButton( + onPressed: canPause ? _handlePause : _handleStart, + child: + Icon(canPause ? Icons.pause_rounded : Icons.play_arrow_rounded), + ), + TextButton( + onPressed: canStop ? _handleStop : null, + child: const Icon(Icons.stop_rounded), + ), + ], + ), + ); + } + + void _handleStart() => app.startEngine(); + void _handlePause() => app.pauseEngine(); + void _handleStop() => app.stopEngine(); +} From 448c0291f2cf7a35a6e84b7fc6f3481e4fd8e682 Mon Sep 17 00:00:00 2001 From: Pasha Stetsenko Date: Sat, 8 Jan 2022 19:58:44 -0800 Subject: [PATCH 2/3] uncomment exclude directive --- analysis_options.yaml | 6 +++--- sandbox/lib/main.dart | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index f7f5824..b3c2d75 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,5 +1,5 @@ include: package:flame_lint/analysis_options.yaml -#analyzer: -# exclude: -# - sandbox/** +analyzer: + exclude: + - sandbox/** diff --git a/sandbox/lib/main.dart b/sandbox/lib/main.dart index 90d28ea..6130f96 100644 --- a/sandbox/lib/main.dart +++ b/sandbox/lib/main.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'presets.dart'; import 'scene.dart'; +import 'presets.dart'; import 'widgets/left_menu.dart'; import 'widgets/scene_widget.dart'; import 'widgets/top_menu.dart'; From 15e25a3a2f5a0af635137a734e4338bc2e4645d1 Mon Sep 17 00:00:00 2001 From: Pasha Stetsenko Date: Sat, 8 Jan 2022 20:10:25 -0800 Subject: [PATCH 3/3] analyze --- sandbox/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sandbox/lib/main.dart b/sandbox/lib/main.dart index 6130f96..90d28ea 100644 --- a/sandbox/lib/main.dart +++ b/sandbox/lib/main.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'scene.dart'; import 'presets.dart'; +import 'scene.dart'; import 'widgets/left_menu.dart'; import 'widgets/scene_widget.dart'; import 'widgets/top_menu.dart';