Skip to content

Commit

Permalink
starting on configurator for counter and sum
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorbel1 committed Sep 9, 2024
1 parent ae5c0c3 commit aad96e0
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 7 deletions.
8 changes: 3 additions & 5 deletions confapp/lib/hcl/view/screen/content_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@ class _SVGeneratorState extends State<SVGenerator> {
);
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;
Expand Down
29 changes: 29 additions & 0 deletions lib/src/component_config/components/config_counter.dart
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

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<String, ConfigKnob<dynamic>> get subKnobs => {
'Has Enable': hasEnableKnob,
'Is Fixed Value': isFixedValueKnob,
'Width': widthKnob,
};
}

// class CounterConfigurator extends Configurator {}
2 changes: 2 additions & 0 deletions lib/src/component_config/config_knobs/config_knobs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
6 changes: 5 additions & 1 deletion lib/src/component_config/config_knobs/int_config_knob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
import 'package:rohd_hcl/rohd_hcl.dart';

/// A knob to store an [int].
class IntConfigKnob extends ConfigKnob<int> {
class IntConfigKnob extends TextConfigKnob<int> {
/// Creates a new config knob with the specified initial [value].
IntConfigKnob({required super.value});

@override
Map<String, dynamic> 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<String, dynamic> decodedJson) {
final val = decodedJson['value'];
Expand Down
Original file line number Diff line number Diff line change
@@ -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<int?> {
/// Creates a new config knob with the specified initial [value].
IntOptionalConfigKnob({required super.value});

@override
Map<String, dynamic> 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<String, dynamic> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import 'package:rohd_hcl/rohd_hcl.dart';

/// A knob for holding a [String].
class StringConfigKnob extends ConfigKnob<String> {
class StringConfigKnob extends TextConfigKnob<String> {
/// Creates a new knob with the specified initial [value].
StringConfigKnob({required super.value});
}
22 changes: 22 additions & 0 deletions lib/src/component_config/config_knobs/text_config_knob.dart
Original file line number Diff line number Diff line change
@@ -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<T> extends ConfigKnob<T> {
/// 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;
}

0 comments on commit aad96e0

Please sign in to comment.