mirror of
https://github.com/dancojocaru2000/logic-circuits-simulator.git
synced 2025-06-19 10:32:28 +03:00
Compare commits
No commits in common. "2a19505ed36c50c89597c9811ef9983b3c15c80f" and "eaa63f75af7711658f355a7ca486a0a8f296e8af" have entirely different histories.
2a19505ed3
...
eaa63f75af
5 changed files with 9 additions and 114 deletions
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:logic_circuits_simulator/models/project.dart';
|
import 'package:logic_circuits_simulator/models/project.dart';
|
||||||
import 'package:logic_circuits_simulator/state/project.dart';
|
import 'package:logic_circuits_simulator/state/project.dart';
|
||||||
import 'package:logic_circuits_simulator/utils/iterable_extension.dart';
|
|
||||||
import 'package:logic_circuits_simulator/utils/provider_hook.dart';
|
import 'package:logic_circuits_simulator/utils/provider_hook.dart';
|
||||||
|
|
||||||
class EditComponentPage extends HookWidget {
|
class EditComponentPage extends HookWidget {
|
||||||
|
@ -99,9 +98,7 @@ class EditComponentPage extends HookWidget {
|
||||||
),
|
),
|
||||||
SliverList(
|
SliverList(
|
||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
(context, i) => ListTile(
|
(context, i) => ListTile(title: Text(ce.inputs[i]),),
|
||||||
title: Text(ce.inputs[i]),
|
|
||||||
),
|
|
||||||
childCount: ce.inputs.length,
|
childCount: ce.inputs.length,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -116,9 +113,7 @@ class EditComponentPage extends HookWidget {
|
||||||
),
|
),
|
||||||
SliverList(
|
SliverList(
|
||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
(context, i) => ListTile(
|
(context, i) => ListTile(title: Text(ce.outputs[i]),),
|
||||||
title: Text(ce.outputs[i]),
|
|
||||||
),
|
|
||||||
childCount: ce.outputs.length,
|
childCount: ce.outputs.length,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -161,76 +156,6 @@ class EditComponentPage extends HookWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TruthTableHeaderText extends StatelessWidget {
|
|
||||||
final String text;
|
|
||||||
final BoxBorder? border;
|
|
||||||
|
|
||||||
const TruthTableHeaderText(this.text, {super.key, this.border});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: border,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
text,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontSize: 24,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TruthTableTrue extends StatelessWidget {
|
|
||||||
final BoxBorder? border;
|
|
||||||
|
|
||||||
const TruthTableTrue({super.key, this.border});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: border,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
'T',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
|
|
||||||
color: Colors.green,
|
|
||||||
fontSize: 20,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TruthTableFalse extends StatelessWidget {
|
|
||||||
final BoxBorder? border;
|
|
||||||
|
|
||||||
const TruthTableFalse({super.key, this.border});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: border,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
'F',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
|
|
||||||
color: Colors.red,
|
|
||||||
fontSize: 20,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TruthTableEditor extends StatelessWidget {
|
class TruthTableEditor extends StatelessWidget {
|
||||||
final List<String> inputs;
|
final List<String> inputs;
|
||||||
final List<String> outputs;
|
final List<String> outputs;
|
||||||
|
@ -242,44 +167,20 @@ class TruthTableEditor extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Table(
|
return Table(
|
||||||
defaultColumnWidth: const IntrinsicColumnWidth(),
|
defaultColumnWidth: const IntrinsicColumnWidth(),
|
||||||
border: TableBorder.symmetric(outside: const BorderSide(width: 2)),
|
|
||||||
children: List.generate(
|
children: List.generate(
|
||||||
truthTable.length + 1,
|
truthTable.length + 1,
|
||||||
(index) {
|
(index) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
return TableRow(
|
return TableRow(
|
||||||
children: inputs
|
children: inputs.map((e) => Text(e)).followedBy(outputs.map((e) => Text(e))).toList(),
|
||||||
.indexedMap<Widget>(
|
|
||||||
(index, e) => TruthTableHeaderText(
|
|
||||||
e,
|
|
||||||
border: Border(
|
|
||||||
bottom: const BorderSide(width: 2),
|
|
||||||
right: index == inputs.length - 1 ? const BorderSide(width: 2) : BorderSide.none,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.followedBy(
|
|
||||||
outputs
|
|
||||||
.map((e) => TruthTableHeaderText(e, border: const Border(bottom: BorderSide(width: 2)),))
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final inputBinary = (index - 1).toRadixString(2).padLeft(inputs.length, '0');
|
final inputBinary = (index - 1).toRadixString(2).padLeft(inputs.length, '0');
|
||||||
final outputBinary = truthTable[index - 1];
|
final outputBinary = truthTable[index - 1];
|
||||||
|
|
||||||
Widget runeToWidget(int rune, {BoxBorder? border}) {
|
|
||||||
return int.parse(String.fromCharCode(rune)) != 0 ? TruthTableTrue(border: border) : TruthTableFalse(border: border);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TableRow(
|
return TableRow(
|
||||||
children: inputBinary.runes.indexedMap(
|
children: inputBinary.runes.map((r) => Text(String.fromCharCodes([r])))
|
||||||
(index, r) => runeToWidget(
|
.followedBy(outputBinary.runes.map((r) => Text(String.fromCharCodes([r]))))
|
||||||
r,
|
|
||||||
border: index == inputBinary.runes.length - 1 ? const Border(right: BorderSide(width: 2)) : null,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.followedBy(outputBinary.runes.map((r) => runeToWidget(r)))
|
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -40,7 +40,7 @@ class ProjectState extends ChangeNotifier {
|
||||||
final indexFile = await _getIndexFile();
|
final indexFile = await _getIndexFile();
|
||||||
if (!await indexFile.exists()) {
|
if (!await indexFile.exists()) {
|
||||||
_index = const ProjectIndex(components: []);
|
_index = const ProjectIndex(components: []);
|
||||||
await indexFile.writeAsString(const JsonEncoder.withIndent(" ").convert(_index.toJson()));
|
await indexFile.writeAsString(jsonEncode(_index.toJson()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_index = ProjectIndex.fromJson(jsonDecode(await indexFile.readAsString()));
|
_index = ProjectIndex.fromJson(jsonDecode(await indexFile.readAsString()));
|
||||||
|
@ -51,7 +51,7 @@ class ProjectState extends ChangeNotifier {
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
_index = newIndex;
|
_index = newIndex;
|
||||||
final indexFile = await _getIndexFile();
|
final indexFile = await _getIndexFile();
|
||||||
await indexFile.writeAsString(const JsonEncoder.withIndent(" ").convert(index.toJson()));
|
await indexFile.writeAsString(jsonEncode(index.toJson()));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class ProjectsState extends ChangeNotifier {
|
||||||
// Sort projects when updating: latest update first
|
// Sort projects when updating: latest update first
|
||||||
index = newIndex.copyWith(projects: newIndex.projects.toList()..sort((p1, p2) => p2.lastUpdate.compareTo(p1.lastUpdate)));
|
index = newIndex.copyWith(projects: newIndex.projects.toList()..sort((p1, p2) => p2.lastUpdate.compareTo(p1.lastUpdate)));
|
||||||
final indexFile = await _getIndexFile();
|
final indexFile = await _getIndexFile();
|
||||||
await indexFile.writeAsString(const JsonEncoder.withIndent(" ").convert(index.toJson()));
|
await indexFile.writeAsString(jsonEncode(index.toJson()));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
extension IndexedMap<T> on Iterable<T> {
|
|
||||||
Iterable<O> indexedMap<O>(O Function(int, T) toElement) {
|
|
||||||
int index = 0;
|
|
||||||
return map((e) => toElement(index++, e));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,7 +28,7 @@ packages:
|
||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.9.0"
|
version: "2.8.2"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
Loading…
Add table
Reference in a new issue