fzhangtj
6 年前
当前提交
03761320
共有 8 个文件被更改,包括 262 次插入 和 405 次删除
-
2Assets/UIWidgets/engine/AsScreen.cs
-
37Assets/UIWidgets/engine/WidgetCanvas.cs
-
12Assets/UIWidgets/engine/canvas_window.cs
-
14Assets/UIWidgets/widgets/basic.cs
-
384Assets/UIWidgetsSample/UIWidgetSample.unity
-
202Assets/UIWidgetsSample/ToDoAppCanvas.cs
-
13Assets/UIWidgetsSample/SampleCanvas.cs
-
3Assets/UIWidgetsSample/SampleCanvas.cs.meta
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UIWidgets.engine; |
|||
using UIWidgets.foundation; |
|||
using UIWidgets.gestures; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.rendering; |
|||
using UIWidgets.ui; |
|||
using UIWidgets.widgets; |
|||
using TextStyle = UIWidgets.painting.TextStyle; |
|||
|
|||
namespace UIWidgetsSample |
|||
{ |
|||
public class ToDoAppCanvas : WidgetCanvas |
|||
{ |
|||
public class ToDoListApp : StatefulWidget |
|||
{ |
|||
public ToDoListApp(Key key = null) : base(key) |
|||
{ |
|||
} |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _ToDoListAppState(); |
|||
} |
|||
} |
|||
|
|||
protected override Widget getWidget() |
|||
{ |
|||
return new ToDoListApp(); |
|||
} |
|||
|
|||
public class CustomButton : StatelessWidget |
|||
{ |
|||
public CustomButton( |
|||
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.0); |
|||
this.backgroundColor = backgroundColor ?? CLColors.transparent; |
|||
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 |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _ToDoListAppState : State<ToDoListApp> |
|||
{ |
|||
public class ToDoItem |
|||
{ |
|||
public int id; |
|||
public string content; |
|||
} |
|||
|
|||
private List<ToDoItem> items = new List<ToDoItem>(); |
|||
private int nextId = 0; |
|||
private TextEditingController controller = new TextEditingController(""); |
|||
|
|||
private Widget title() |
|||
{ |
|||
return new Text("ToDo App", textAlign: TextAlign.center, |
|||
style: new TextStyle(fontSize:30, fontWeight: FontWeight.w700)); |
|||
} |
|||
|
|||
private Widget textInput() |
|||
{ |
|||
return new Container( |
|||
child: new Row( |
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|||
children: new List<Widget>( |
|||
) |
|||
{ |
|||
new Container( |
|||
width: 300, |
|||
decoration: new BoxDecoration(border: Border.all(new Color(0xFF000000), 1)), |
|||
padding: EdgeInsets.fromLTRB(8, 0, 8, 0), |
|||
child: new EditableText(maxLines: 1, |
|||
controller: controller, |
|||
|
|||
focusNode: new FocusNode(), |
|||
style: new TextStyle( |
|||
fontSize: 18, |
|||
height: 1.5f, |
|||
color: new Color(0xFF1389FD) |
|||
), |
|||
selectionColor: Color.fromARGB(255, 255, 0, 0), |
|||
cursorColor: Color.fromARGB(255, 0, 0, 0)) |
|||
), |
|||
|
|||
new CustomButton(backgroundColor: Color.fromARGB(255, 0, 204, 204), |
|||
padding: EdgeInsets.all(10), |
|||
child: new Text("Add", style: new TextStyle( |
|||
fontSize: 20, color: Color.fromARGB(255, 255, 255, 255), fontWeight: FontWeight.w700 |
|||
)), onPressed: () => |
|||
{ |
|||
setState(() => |
|||
{ |
|||
if (controller.text != "") |
|||
{ |
|||
items.Add(new ToDoItem() {id = nextId++, content = controller.text}); |
|||
} |
|||
}); |
|||
}) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
|
|||
private Widget contents() |
|||
{ |
|||
var children = items.Select((item) => { return (Widget) new Text( |
|||
item.content, style: new TextStyle( |
|||
fontSize: 18, |
|||
height: 1.5 |
|||
) |
|||
); }); |
|||
/*return new Flexible( todo use scroll list |
|||
child: new ListView( |
|||
physics: new AlwaysScrollableScrollPhysics(), |
|||
children: children.ToList() |
|||
) |
|||
);*/ |
|||
return new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.start, |
|||
children: children.ToList()); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
var container = new Container( |
|||
padding: EdgeInsets.all(10), |
|||
decoration: new BoxDecoration(border:Border.all(color: Color.fromARGB(255, 255, 0, 0), width: 5), |
|||
borderRadius: BorderRadius.all(2)), |
|||
child: new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: new List<Widget> |
|||
{ |
|||
title(), |
|||
textInput(), |
|||
contents(), |
|||
} |
|||
) |
|||
); |
|||
return container; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class CustomButton : StatelessWidget |
|||
{ |
|||
public CustomButton( |
|||
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.0); |
|||
this.backgroundColor = backgroundColor ?? CLColors.transparent; |
|||
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 |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
using UIWidgets.engine; |
|||
using UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample |
|||
{ |
|||
public class SampleCanvas:WidgetCanvas |
|||
{ |
|||
protected override Widget getWidget() |
|||
{ |
|||
return new AsScreen(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 45ef9c98c7594497921b0c714f2b4c33 |
|||
timeCreated: 1545377537 |
撰写
预览
正在加载...
取消
保存
Reference in new issue