From aad96e0a0f13a0db3f49cbb80a41e5f1469967cd Mon Sep 17 00:00:00 2001 From: Max Korbel Date: Mon, 9 Sep 2024 16:30:51 -0700 Subject: [PATCH] starting on configurator for counter and sum --- .../lib/hcl/view/screen/content_widget.dart | 8 ++- .../components/config_counter.dart | 29 +++++++++++ .../config_knobs/config_knobs.dart | 2 + .../config_knobs/int_config_knob.dart | 6 ++- .../int_optional_config_knob.dart | 50 +++++++++++++++++++ .../config_knobs/string_config_knob.dart | 2 +- .../config_knobs/text_config_knob.dart | 22 ++++++++ 7 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 lib/src/component_config/components/config_counter.dart create mode 100644 lib/src/component_config/config_knobs/int_optional_config_knob.dart create mode 100644 lib/src/component_config/config_knobs/text_config_knob.dart diff --git a/confapp/lib/hcl/view/screen/content_widget.dart b/confapp/lib/hcl/view/screen/content_widget.dart index 4e807935b..e28e43166 100644 --- a/confapp/lib/hcl/view/screen/content_widget.dart +++ b/confapp/lib/hcl/view/screen/content_widget.dart @@ -69,15 +69,13 @@ class _SVGeneratorState extends State { ); final key = Key(label); - if (knob is IntConfigKnob || knob is StringConfigKnob) { + if (knob is TextInputConfigKnob) { selector = TextFormField( key: key, - initialValue: (knob is IntConfigKnob && knob.value > 255) - ? '0x${knob.value.toRadixString(16)}' - : knob.value.toString(), + initialValue: knob.valueString, decoration: decoration, validator: (value) { - if (value!.isEmpty) { + if (value.isEmpty && !value.allowEmpty) { return 'Please enter value'; } return null; diff --git a/lib/src/component_config/components/config_counter.dart b/lib/src/component_config/components/config_counter.dart new file mode 100644 index 000000000..326f96817 --- /dev/null +++ b/lib/src/component_config/components/config_counter.dart @@ -0,0 +1,29 @@ +// Copyright (C) 2024 Intel Corporation +// SPDX-License-Identifier: BSD-3-Clause +// +// config_counter.dart +// Configurator for a Counter. +// +// 2024 September 6 +// Author: Max Korbel + +import 'package:rohd_hcl/rohd_hcl.dart'; + +class SumInterfaceKnob extends GroupOfKnobs { + ToggleConfigKnob hasEnableKnob = ToggleConfigKnob(value: false); + + ToggleConfigKnob isFixedValueKnob = ToggleConfigKnob(value: false); + + IntOptionalConfigKnob widthKnob = IntOptionalConfigKnob(value: 8); + + SumInterfaceKnob() : super({}); + + @override + Map> get subKnobs => { + 'Has Enable': hasEnableKnob, + 'Is Fixed Value': isFixedValueKnob, + 'Width': widthKnob, + }; +} + +// class CounterConfigurator extends Configurator {} diff --git a/lib/src/component_config/config_knobs/config_knobs.dart b/lib/src/component_config/config_knobs/config_knobs.dart index 6f33c5ac3..bf271a366 100644 --- a/lib/src/component_config/config_knobs/config_knobs.dart +++ b/lib/src/component_config/config_knobs/config_knobs.dart @@ -5,6 +5,8 @@ export 'choice_config_knob.dart'; export 'config_knob.dart'; export 'group_of_knobs_knob.dart'; export 'int_config_knob.dart'; +export 'int_optional_config_knob.dart'; export 'list_of_knobs_knob.dart'; export 'string_config_knob.dart'; +export 'text_config_knob.dart'; export 'toggle_config_knob.dart'; diff --git a/lib/src/component_config/config_knobs/int_config_knob.dart b/lib/src/component_config/config_knobs/int_config_knob.dart index e5a707941..2405271fc 100644 --- a/lib/src/component_config/config_knobs/int_config_knob.dart +++ b/lib/src/component_config/config_knobs/int_config_knob.dart @@ -9,7 +9,7 @@ import 'package:rohd_hcl/rohd_hcl.dart'; /// A knob to store an [int]. -class IntConfigKnob extends ConfigKnob { +class IntConfigKnob extends TextConfigKnob { /// Creates a new config knob with the specified initial [value]. IntConfigKnob({required super.value}); @@ -17,6 +17,10 @@ class IntConfigKnob extends ConfigKnob { Map toJson() => {'value': value > 255 ? '0x${value.toRadixString(16)}' : value}; + @override + String get valueString => + value > 255 ? '0x${value.toRadixString(16)}' : value.toString(); + @override void loadJson(Map decodedJson) { final val = decodedJson['value']; diff --git a/lib/src/component_config/config_knobs/int_optional_config_knob.dart b/lib/src/component_config/config_knobs/int_optional_config_knob.dart new file mode 100644 index 000000000..bcc134724 --- /dev/null +++ b/lib/src/component_config/config_knobs/int_optional_config_knob.dart @@ -0,0 +1,50 @@ +// Copyright (C) 2024 Intel Corporation +// SPDX-License-Identifier: BSD-3-Clause +// +// int_optional_config_knob.dart +// A knob for holding a number or null. +// +// 2024 September 9 + +import 'package:rohd_hcl/rohd_hcl.dart'; + +/// A knob to store an [int]. +class IntOptionalConfigKnob extends TextConfigKnob { + /// Creates a new config knob with the specified initial [value]. + IntOptionalConfigKnob({required super.value}); + + @override + Map toJson() => { + 'value': value == null + ? null + : value! > 255 + ? '0x${value!.toRadixString(16)}' + : value + }; + + @override + String get valueString => value == null + ? '' + : value! > 255 + ? '0x${value!.toRadixString(16)}' + : value.toString(); + + @override + bool get allowEmpty => true; + + @override + void loadJson(Map decodedJson) { + final val = decodedJson['value']; + if (val == null) { + value = null; + } else if (val is String) { + if (val.isEmpty) { + value = null; + } else { + value = int.parse(val); + } + } else { + value = val as int; + } + } +} diff --git a/lib/src/component_config/config_knobs/string_config_knob.dart b/lib/src/component_config/config_knobs/string_config_knob.dart index fc90d6689..4664bb692 100644 --- a/lib/src/component_config/config_knobs/string_config_knob.dart +++ b/lib/src/component_config/config_knobs/string_config_knob.dart @@ -9,7 +9,7 @@ import 'package:rohd_hcl/rohd_hcl.dart'; /// A knob for holding a [String]. -class StringConfigKnob extends ConfigKnob { +class StringConfigKnob extends TextConfigKnob { /// Creates a new knob with the specified initial [value]. StringConfigKnob({required super.value}); } diff --git a/lib/src/component_config/config_knobs/text_config_knob.dart b/lib/src/component_config/config_knobs/text_config_knob.dart new file mode 100644 index 000000000..7f3bead7d --- /dev/null +++ b/lib/src/component_config/config_knobs/text_config_knob.dart @@ -0,0 +1,22 @@ +// Copyright (C) 2024 Intel Corporation +// SPDX-License-Identifier: BSD-3-Clause +// +// text_config_knob.dart +// Definition of a configuration knob which can be configured by parsing text. +// +// 2023 December 5 + +import 'package:rohd_hcl/rohd_hcl.dart'; + +/// A configuration knob for use in [Configurator]s which can be configured by +/// text. +abstract class TextConfigKnob extends ConfigKnob { + /// Creates a new knob with an initial [value]. + TextConfigKnob({required super.value}); + + /// A [String] representation of the [value]. + String get valueString => value.toString(); + + /// Whether the knob allows an empty string as input. + bool get allowEmpty => false; +}