浏览代码

text field

/main
fzhangtj 6 年前
当前提交
a497f6a5
共有 6 个文件被更改,包括 139 次插入138 次删除
  1. 127
      Runtime/material/input_decorator.cs
  2. 2
      Runtime/material/text_field.cs
  3. 108
      Runtime/material/text_selection.cs
  4. 7
      Runtime/service/keyboard.cs
  5. 22
      Samples/UIWidgetSample/txt/TextFieldSample.cs
  6. 11
      Samples/UIWidgetSample/txt/TextFieldSample.cs.meta

127
Runtime/material/input_decorator.cs


}
class _InputBorderGap : ChangeNotifier {
class _InputBorderGap : ChangeNotifier, IEquatable<_InputBorderGap> {
float _start;
public float start {

}
}
public static bool operator ==(_InputBorderGap left, _InputBorderGap right) {
return left.Equals(right);
}
public bool Equals(_InputBorderGap other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
public static bool operator !=(_InputBorderGap left, _InputBorderGap other) {
return left.start != other.start || left.extent != other.extent;
return this.start == other.start && this.extent == other._extent;
public bool Equals(_InputBorderGap other) {
return this.start == other.start && this.extent == other.extent;
}
return (this.start.GetHashCode() * 397) ^ this.extent.GetHashCode();
return (this._start.GetHashCode() * 397) ^ this._extent.GetHashCode();
}
public static bool operator ==(_InputBorderGap left, _InputBorderGap right) {
return Equals(left, right);
}
public static bool operator !=(_InputBorderGap left, _InputBorderGap right) {
return !Equals(left, right);
}
}

container
}
class _Decoration {
class _Decoration : IEquatable<_Decoration> {
public _Decoration(
EdgeInsets contentPadding,
bool isCollapsed,

public readonly Widget counter;
public readonly Widget container;
public static bool operator ==(_Decoration left, _Decoration right) {
return left.Equals(right);
}
public bool Equals(_Decoration other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
public static bool operator !=(_Decoration left, _Decoration right) {
return !left.Equals(right);
return Equals(this.contentPadding, other.contentPadding) && this.isCollapsed == other.isCollapsed &&
this.floatingLabelHeight.Equals(other.floatingLabelHeight) &&
this.floatingLabelProgress.Equals(other.floatingLabelProgress) &&
Equals(this.border, other.border) && Equals(this.borderGap, other.borderGap) &&
Equals(this.icon, other.icon) && Equals(this.input, other.input) &&
Equals(this.label, other.label) && Equals(this.hint, other.hint) &&
Equals(this.prefix, other.prefix) && Equals(this.suffix, other.suffix) &&
Equals(this.prefixIcon, other.prefixIcon) && Equals(this.suffixIcon, other.suffixIcon) &&
Equals(this.helperError, other.helperError) && Equals(this.counter, other.counter) &&
Equals(this.container, other.container);
public bool Equals(_Decoration other) {
return this.contentPadding == other.contentPadding
&& this.floatingLabelHeight == other.floatingLabelHeight
&& this.floatingLabelProgress == other.floatingLabelProgress
&& this.border == other.border
&& this.borderGap == other.borderGap
&& this.icon == other.icon
&& this.input == other.input
&& this.label == other.label
&& this.hint == other.hint
&& this.prefix == other.prefix
&& this.suffix == other.suffix
&& this.prefixIcon == other.prefixIcon
&& this.suffixIcon == other.suffixIcon
&& this.helperError == other.helperError
&& this.counter == other.counter
&& this.container == other.container;
}
var hashCode = this.contentPadding.GetHashCode();
var hashCode = (this.contentPadding != null ? this.contentPadding.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ this.isCollapsed.GetHashCode();
hashCode = (hashCode * 397) ^ this.border.GetHashCode();
hashCode = (hashCode * 397) ^ this.borderGap.GetHashCode();
hashCode = (hashCode * 397) ^ this.icon.GetHashCode();
hashCode = (hashCode * 397) ^ this.input.GetHashCode();
hashCode = (hashCode * 397) ^ this.label.GetHashCode();
hashCode = (hashCode * 397) ^ this.hint.GetHashCode();
hashCode = (hashCode * 397) ^ this.prefix.GetHashCode();
hashCode = (hashCode * 397) ^ this.suffix.GetHashCode();
hashCode = (hashCode * 397) ^ this.prefixIcon.GetHashCode();
hashCode = (hashCode * 397) ^ this.suffixIcon.GetHashCode();
hashCode = (hashCode * 397) ^ this.helperError.GetHashCode();
hashCode = (hashCode * 397) ^ this.counter.GetHashCode();
hashCode = (hashCode * 397) ^ this.container.GetHashCode();
hashCode = (hashCode * 397) ^ (this.border != null ? this.border.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.borderGap != null ? this.borderGap.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.icon != null ? this.icon.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.input != null ? this.input.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.label != null ? this.label.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.hint != null ? this.hint.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.prefix != null ? this.prefix.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.suffix != null ? this.suffix.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.prefixIcon != null ? this.prefixIcon.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.suffixIcon != null ? this.suffixIcon.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.helperError != null ? this.helperError.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.counter != null ? this.counter.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.container != null ? this.container.GetHashCode() : 0);
}
public static bool operator ==(_Decoration left, _Decoration right) {
return Equals(left, right);
}
public static bool operator !=(_Decoration left, _Decoration right) {
return !Equals(left, right);
}
}

}
void _mountChild(Widget widget, _DecorationSlot slot) {
Element oldChild = this.slotToChild[slot];
Element oldChild = this.slotToChild.getOrDefault(slot);
Element newChild = this.updateChild(oldChild, widget, slot);
if (oldChild != null) {
this.slotToChild.Remove(slot);

}
void _updateChild(Widget widget, _DecorationSlot slot) {
Element oldChild = this.slotToChild[slot];
Element newChild = this.updateChild(oldChild, this.widget, slot);
Element oldChild = this.slotToChild.getOrDefault(slot);
Element newChild = this.updateChild(oldChild, widget, slot);
if (oldChild != null) {
this.childToSlot.Remove(oldChild);
this.slotToChild.Remove(slot);

}
public static bool operator ==(InputDecoration left, InputDecoration right) {
return left.Equals(right);
return Equals(left, right);
return !left.Equals(right);
return !Equals(left, right);
}
public bool Equals(InputDecoration other) {

2
Runtime/material/text_field.cs


this.controller = controller;
this.focusNode = focusNode;
this.decoration = decoration;
this.decoration = decoration ?? new InputDecoration();
this.textInputAction = textInputAction;
this.textCapitalization = textCapitalization;
this.style = style;

108
Runtime/material/text_selection.cs


using Rect = Unity.UIWidgets.ui.Rect;
using Transform = Unity.UIWidgets.widgets.Transform;
// todo using material components: FlatButton & Material ...
}
static class _TextSelectionUtils {
public _TextSelectionToolbar(Key key = null, Action handleCut = null,
Action handleCopy = null, Action handlePaste = null, Action handleSelectAll = null) : base(key: key) {
public _TextSelectionToolbar(Key key = null, VoidCallback handleCut = null,
VoidCallback handleCopy = null, VoidCallback handlePaste = null, VoidCallback handleSelectAll = null) : base(key: key) {
this.handleCut = handleCut;
this.handleCopy = handleCopy;
this.handlePaste = handlePaste;

public readonly Action handleCut;
public readonly Action handleCopy;
public readonly Action handlePaste;
public readonly Action handleSelectAll;
public readonly VoidCallback handleCut;
public readonly VoidCallback handleCopy;
public readonly VoidCallback handlePaste;
public readonly VoidCallback handleSelectAll;
MaterialLocalizations localizations = MaterialLocalizations.of(context);
items.Add(new _TempButton(onPressed: () => this.handleCut(), child: new Text("Cut")));
items.Add(new FlatButton(child: new Text(localizations.cutButtonLabel), onPressed: this.handleCut));
items.Add(new _TempButton(onPressed: () => this.handleCopy(), child: new Text("Copy")));
items.Add(new FlatButton(child: new Text(localizations.copyButtonLabel), onPressed: this.handleCopy));
items.Add(new _TempButton(onPressed: () => this.handlePaste(), child: new Text("Past")));
items.Add(new FlatButton(child: new Text(localizations.pasteButtonLabel), onPressed: this.handlePaste));
items.Add(new _TempButton(onPressed: () => this.handleSelectAll(), child: new Text("Select All")));
items.Add(new FlatButton(child: new Text(localizations.selectAllButtonLabel),
onPressed: this.handleSelectAll));
return new Container(
color: new Color(0xFFEFEFEF),
height: 44.0f, child: new Row(mainAxisSize: MainAxisSize.min, children: items));
return new Material(
elevation: 1.0f,
child: new Container(
color: new Color(0xFFEFEFEF),
height: 44.0f, child: new Row(mainAxisSize: MainAxisSize.min, children: items))
);
}
}

float x = globalPosition.dx - childSize.width / 2.0f;
float y = globalPosition.dy - childSize.height;
if (x < _TextSelectionUtils._kToolbarScreenPadding) {
x = _TextSelectionUtils._kToolbarScreenPadding;
if (x < MaterialUtils._kToolbarScreenPadding) {
x = MaterialUtils._kToolbarScreenPadding;
else if (x + childSize.width > this.screenSize.width - _TextSelectionUtils._kToolbarScreenPadding) {
x = this.screenSize.width - childSize.width - _TextSelectionUtils._kToolbarScreenPadding;
else if (x + childSize.width > this.screenSize.width - MaterialUtils._kToolbarScreenPadding) {
x = this.screenSize.width - childSize.width - MaterialUtils._kToolbarScreenPadding;
if (y < _TextSelectionUtils._kToolbarScreenPadding) {
y = _TextSelectionUtils._kToolbarScreenPadding;
if (y < MaterialUtils._kToolbarScreenPadding) {
y = MaterialUtils._kToolbarScreenPadding;
else if (y + childSize.height > this.screenSize.height - _TextSelectionUtils._kToolbarScreenPadding) {
y = this.screenSize.height - childSize.height - _TextSelectionUtils._kToolbarScreenPadding;
else if (y + childSize.height > this.screenSize.height - MaterialUtils._kToolbarScreenPadding) {
y = this.screenSize.height - childSize.height - MaterialUtils._kToolbarScreenPadding;
}
return new Offset(x, y);

class _MaterialTextSelectionControls : TextSelectionControls {
public override Size handleSize {
get {
return new Size(_TextSelectionUtils._kHandleSize,
_TextSelectionUtils._kHandleSize);
return new Size(MaterialUtils._kHandleSize,
MaterialUtils._kHandleSize);
}
}

child: new _TextSelectionToolbar(
handleCut: this.canCut(selectionDelegate)
? () => this.handleCut(selectionDelegate)
: (Action) null,
: (VoidCallback) null,
: (Action) null,
: (VoidCallback) null,
: (Action) null,
: (VoidCallback) null,
: (Action) null
: (VoidCallback) null
)
)
);

Widget handle = new Padding(
padding: EdgeInsets.only(right: 26.0f, bottom: 26.0f),
child: new SizedBox(
width: 20,
height: 20,
width: MaterialUtils._kHandleSize,
height: MaterialUtils._kHandleSize,
color: new Color(0xFFFF0000)
color: Theme.of(context).textSelectionHandleColor
)
)
)

}
return null;
}
}
public class _TempButton : StatelessWidget {
public _TempButton(
Key key = null,
GestureTapCallback onPressed = null,
EdgeInsets padding = null,
Color backgroundColor = null,
Widget child = null
) : base(key: key) {
this.onPressed = onPressed;
this.padding = padding ?? EdgeInsets.all(8.0f);
this.backgroundColor = backgroundColor ?? new Color(0);
this.child = child;
}
public readonly GestureTapCallback onPressed;
public readonly EdgeInsets padding;
public readonly Widget child;
public readonly Color backgroundColor;
public override Widget build(BuildContext context) {
return new GestureDetector(
onTap: this.onPressed,
child: new Container(
padding: this.padding,
color: this.backgroundColor,
child: this.child
)
);
}
}
}

7
Runtime/service/keyboard.cs


}
abstract class AbstractUIWidgetsKeyboardDelegate : KeyboardDelegate {
UIWidgetsMessageManager.instance.AddChannelMessageDelegate("TextInput", this._handleMethodCall);
UIWidgetsMessageManager.instance.
AddChannelMessageDelegate("TextInput", this._handleMethodCall);
UIWidgetsMessageManager.instance.RemoveChannelMessageDelegate("TextInput", this._handleMethodCall);
UIWidgetsMessageManager.instance.
RemoveChannelMessageDelegate("TextInput", this._handleMethodCall);
}
public abstract void show();

22
Samples/UIWidgetSample/txt/TextFieldSample.cs


using Unity.UIWidgets.widgets;
using UnityEngine;
using DialogUtils = Unity.UIWidgets.material.DialogUtils;
using FontStyle = Unity.UIWidgets.ui.FontStyle;
namespace UIWidgetsSample {
public class TextFieldSample : UIWidgetsSamplePanel {

}
}
class MyCustomForm: StatefulWidget {
class MyCustomForm : StatefulWidget {
class _MyCustomFormState: State<MyCustomForm> {
class _MyCustomFormState : State<MyCustomForm> {
readonly TextEditingController myController = new TextEditingController();
public override void dispose() {

child: new TextField(controller: this.myController)
),
floatingActionButton: new FloatingActionButton(
// When the user presses the button, show an alert dialog with the
// text the user has typed into our text field.
// When the user presses the button, show an alert dialog with the
// text the user has typed into our text field.
return new AlertDialog(
// Retrieve the text the user has typed in using our
// TextEditingController
content: new Text(myController.text)
);
});
return new AlertDialog(
// Retrieve the text the user has typed in using our
// TextEditingController
content: new Text(this.myController.text)
);
});
},
tooltip: "Show me the value",
child: new Icon(Icons.search)

11
Samples/UIWidgetSample/txt/TextFieldSample.cs.meta


fileFormatVersion: 2
guid: 85b678a668e064f5c90ee8a9f7c13f35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存