feat: make gesture editable.
This commit is contained in:
@@ -22,6 +22,8 @@ class ProviderGenerator extends GeneratorForAnnotation<ProviderModel> {
|
|||||||
List<AnnotationField> fields = [];
|
List<AnnotationField> fields = [];
|
||||||
element.fields.forEach((field) {
|
element.fields.forEach((field) {
|
||||||
var annotation = field.metadata.firstWhereOrNull(
|
var annotation = field.metadata.firstWhereOrNull(
|
||||||
|
(m) => m.computeConstantValue()?.type?.getDisplayString(withNullability: true) == 'ProviderModelProp') ??
|
||||||
|
field.getter?.metadata.firstWhereOrNull(
|
||||||
(m) => m.computeConstantValue()?.type?.getDisplayString(withNullability: true) == 'ProviderModelProp');
|
(m) => m.computeConstantValue()?.type?.getDisplayString(withNullability: true) == 'ProviderModelProp');
|
||||||
if (annotation != null)
|
if (annotation != null)
|
||||||
fields.add(
|
fields.add(
|
||||||
@@ -77,7 +79,7 @@ String? _genCopyFunc(String displayName, List<AnnotationField> fields, bool copy
|
|||||||
return '''
|
return '''
|
||||||
void copyFrom(${displayName} other) {
|
void copyFrom(${displayName} other) {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
${fields.map((f) => 'if (other.${f.name}.diff(this.${f.name})) {this.${f.name} = other.${f.name}; changed = true; }').join('\n')}
|
${fields.map((f) => 'if (other.${f.name} != this.${f.name}) {this.${f.name} = other.${f.name}; changed = true; }').join('\n')}
|
||||||
if (changed) notifyListeners();
|
if (changed) notifyListeners();
|
||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:convert';
|
|||||||
import 'package:dde_gesture_manager/builder/provider_annotation.dart';
|
import 'package:dde_gesture_manager/builder/provider_annotation.dart';
|
||||||
import 'package:dde_gesture_manager/extensions.dart';
|
import 'package:dde_gesture_manager/extensions.dart';
|
||||||
import 'package:dde_gesture_manager/utils/helper.dart';
|
import 'package:dde_gesture_manager/utils/helper.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@ProviderModel(copyable: true)
|
@ProviderModel(copyable: true)
|
||||||
class Scheme {
|
class Scheme {
|
||||||
@@ -76,6 +77,20 @@ class GestureProp {
|
|||||||
@ProviderModelProp()
|
@ProviderModelProp()
|
||||||
String? remark;
|
String? remark;
|
||||||
|
|
||||||
|
@ProviderModelProp()
|
||||||
|
bool get editMode => _editMode;
|
||||||
|
|
||||||
|
set editMode(bool val) {
|
||||||
|
_editMode = val;
|
||||||
|
if (val == false) onEditEnd?.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
VoidCallback? onEditEnd;
|
||||||
|
|
||||||
|
bool _editMode = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
other is GestureProp &&
|
other is GestureProp &&
|
||||||
|
|||||||
@@ -13,72 +13,6 @@ import 'package:flutter/material.dart';
|
|||||||
class GestureEditor extends StatelessWidget {
|
class GestureEditor extends StatelessWidget {
|
||||||
const GestureEditor({Key? key}) : super(key: key);
|
const GestureEditor({Key? key}) : super(key: key);
|
||||||
|
|
||||||
List<DDataRow> _buildDataRow(List<GestureProp>? gestures, BuildContext context) => (gestures ?? []).map((gesture) {
|
|
||||||
bool selected = context.watch<GesturePropProvider>() == gesture;
|
|
||||||
return DDataRow(
|
|
||||||
onSelectChanged: (selected) {
|
|
||||||
if (selected == true)
|
|
||||||
context.read<GesturePropProvider>().setProps(
|
|
||||||
gesture: gesture.gesture,
|
|
||||||
direction: gesture.direction,
|
|
||||||
fingers: gesture.fingers,
|
|
||||||
type: gesture.type,
|
|
||||||
command: gesture.command,
|
|
||||||
remark: gesture.remark,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
selected: selected,
|
|
||||||
cells: [
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
'${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(gesture.gesture)}',
|
|
||||||
style: TextStyle(
|
|
||||||
color: selected ? Colors.white : null,
|
|
||||||
),
|
|
||||||
).tr(),
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
'${LocaleKeys.gesture_editor_directions}.${H.getGestureDirectionName(gesture.direction)}',
|
|
||||||
style: TextStyle(
|
|
||||||
color: selected ? Colors.white : null,
|
|
||||||
),
|
|
||||||
).tr()),
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
'${gesture.fingers}',
|
|
||||||
style: TextStyle(
|
|
||||||
color: selected ? Colors.white : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: Text(
|
|
||||||
'${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(gesture.type)}',
|
|
||||||
style: TextStyle(
|
|
||||||
color: selected ? Colors.white : null,
|
|
||||||
),
|
|
||||||
).tr()),
|
|
||||||
Text(
|
|
||||||
gesture.command ?? '',
|
|
||||||
style: TextStyle(
|
|
||||||
color: selected ? Colors.white : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
gesture.remark ?? '',
|
|
||||||
style: TextStyle(
|
|
||||||
color: selected ? Colors.white : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
.map(
|
|
||||||
(ele) => DDataCell(ele),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var layoutProvider = context.watch<ContentLayoutProvider>();
|
var layoutProvider = context.watch<ContentLayoutProvider>();
|
||||||
@@ -131,6 +65,10 @@ class GestureEditor extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
Container(height: 10),
|
Container(height: 10),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
context.read<GesturePropProvider>().copyFrom(GestureProp.empty());
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(defaultBorderRadius),
|
borderRadius: BorderRadius.circular(defaultBorderRadius),
|
||||||
@@ -173,7 +111,7 @@ class GestureEditor extends StatelessWidget {
|
|||||||
DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())),
|
DDataColumn(label: Text(LocaleKeys.gesture_editor_command.tr())),
|
||||||
DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())),
|
DDataColumn(label: Text(LocaleKeys.gesture_editor_remark.tr())),
|
||||||
],
|
],
|
||||||
rows: _buildDataRow(schemeProvider.gestures, context),
|
rows: _buildDataRows(schemeProvider.gestures, context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -181,6 +119,7 @@ class GestureEditor extends StatelessWidget {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
Container(height: 10),
|
Container(height: 10),
|
||||||
Container(
|
Container(
|
||||||
height: 300,
|
height: 300,
|
||||||
@@ -200,3 +139,92 @@ class GestureEditor extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<DDataRow> _buildDataRows(List<GestureProp>? gestures, BuildContext context) => (gestures ?? []).map((gesture) {
|
||||||
|
var gesturePropProvider = context.watch<GesturePropProvider>();
|
||||||
|
bool editing = gesturePropProvider == gesture && gesturePropProvider.editMode == true;
|
||||||
|
bool selected = gesturePropProvider == gesture && !editing;
|
||||||
|
return DDataRow(
|
||||||
|
onSelectChanged: (selected) {
|
||||||
|
if (selected == true)
|
||||||
|
context.read<GesturePropProvider>().setProps(
|
||||||
|
gesture: gesture.gesture,
|
||||||
|
direction: gesture.direction,
|
||||||
|
fingers: gesture.fingers,
|
||||||
|
type: gesture.type,
|
||||||
|
command: gesture.command,
|
||||||
|
remark: gesture.remark,
|
||||||
|
editMode: false,
|
||||||
|
);
|
||||||
|
else if (selected == false) {
|
||||||
|
var provider = context.read<GesturePropProvider>();
|
||||||
|
provider.onEditEnd = () {
|
||||||
|
/// todo: resort rows && check where changed
|
||||||
|
};
|
||||||
|
provider.setProps(
|
||||||
|
editMode: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
selected: selected,
|
||||||
|
cells: editing ? _buildRowCellsEditing(gesture) : _buildRowCellsNormal(selected, gesture),
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
List<DDataCell> _buildRowCellsEditing(GestureProp gesture) => [
|
||||||
|
Text('1'),
|
||||||
|
Text('2'),
|
||||||
|
Text('3'),
|
||||||
|
Text('4'),
|
||||||
|
TextField(controller: TextEditingController(text: gesture.command)),
|
||||||
|
TextField(controller: TextEditingController(text: gesture.remark)),
|
||||||
|
].map((e) => DDataCell(e)).toList();
|
||||||
|
|
||||||
|
List<DDataCell> _buildRowCellsNormal(bool selected, GestureProp gesture) => [
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
'${LocaleKeys.gesture_editor_gestures}.${H.getGestureName(gesture.gesture)}',
|
||||||
|
style: TextStyle(
|
||||||
|
color: selected ? Colors.white : null,
|
||||||
|
),
|
||||||
|
).tr(),
|
||||||
|
),
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
'${LocaleKeys.gesture_editor_directions}.${H.getGestureDirectionName(gesture.direction)}',
|
||||||
|
style: TextStyle(
|
||||||
|
color: selected ? Colors.white : null,
|
||||||
|
),
|
||||||
|
).tr()),
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
'${gesture.fingers}',
|
||||||
|
style: TextStyle(
|
||||||
|
color: selected ? Colors.white : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
'${LocaleKeys.gesture_editor_types}.${H.getGestureTypeName(gesture.type)}',
|
||||||
|
style: TextStyle(
|
||||||
|
color: selected ? Colors.white : null,
|
||||||
|
),
|
||||||
|
).tr()),
|
||||||
|
Text(
|
||||||
|
gesture.command ?? '',
|
||||||
|
style: TextStyle(
|
||||||
|
color: selected ? Colors.white : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
gesture.remark ?? '',
|
||||||
|
style: TextStyle(
|
||||||
|
color: selected ? Colors.white : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.map(
|
||||||
|
(ele) => DDataCell(ele),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
|||||||
@@ -158,64 +158,6 @@ class _LocalManagerState extends State<LocalManager> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Flexible(
|
|
||||||
child: ListView.builder(
|
|
||||||
controller: _scrollController,
|
|
||||||
itemBuilder: (context, index) => GestureDetector(
|
|
||||||
onDoubleTap: () {
|
|
||||||
context.read<SchemeProvider>().copyFrom(localSchemes[index].scheme);
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = index;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = index;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: MouseRegion(
|
|
||||||
cursor: SystemMouseCursors.click,
|
|
||||||
onEnter: (_) {
|
|
||||||
setState(() {
|
|
||||||
_hoveringIndex = index;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
color: _getItemBackgroundColor(index),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(right: 12.0),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
localSchemes[index].scheme.name ?? '',
|
|
||||||
style: TextStyle(
|
|
||||||
color: index == _selectedIndex ? Colors.white : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'456',
|
|
||||||
style: TextStyle(
|
|
||||||
color: index == _selectedIndex ? Colors.white : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
itemCount: localSchemes.length,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
height: 150,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ class H {
|
|||||||
var list = inp.split(',');
|
var list = inp.split(',');
|
||||||
if (list.length != 4) return null;
|
if (list.length != 4) return null;
|
||||||
var rgba = list.map<int>((e) => int.parse(e) ~/ 257).toList();
|
var rgba = list.map<int>((e) => int.parse(e) ~/ 257).toList();
|
||||||
rgba.sout();
|
|
||||||
return Color.fromARGB(rgba[3], rgba[0], rgba[1], rgba[2]);
|
return Color.fromARGB(rgba[3], rgba[0], rgba[1], rgba[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user