浏览代码

todo app canvas

/main
fzhangtj 6 年前
当前提交
03761320
共有 8 个文件被更改,包括 262 次插入405 次删除
  1. 2
      Assets/UIWidgets/engine/AsScreen.cs
  2. 37
      Assets/UIWidgets/engine/WidgetCanvas.cs
  3. 12
      Assets/UIWidgets/engine/canvas_window.cs
  4. 14
      Assets/UIWidgets/widgets/basic.cs
  5. 384
      Assets/UIWidgetsSample/UIWidgetSample.unity
  6. 202
      Assets/UIWidgetsSample/ToDoAppCanvas.cs
  7. 13
      Assets/UIWidgetsSample/SampleCanvas.cs
  8. 3
      Assets/UIWidgetsSample/SampleCanvas.cs.meta

2
Assets/UIWidgets/engine/AsScreen.cs


namespace UIWidgets.engine
{
public class AsScreen : StatefulWidget
{
public AsScreen(Key key = null) : base(key)

37
Assets/UIWidgets/engine/WidgetCanvas.cs


namespace UIWidgets.engine
{
[SerializeField]
private int _canvasWidth = 1000;

{
this._paintingBinding = new PaintingBinding(null);
_paintingBinding.initInstances();
_windowAdapter = new CanvasWindowAdapter(new Rect(0, 0, _canvasWidth, _canvasHeight),
EditorGUIUtility.pixelsPerPoint, this.transform);
_windowAdapter.attachRootWidget(getWidget());
_windowAdapter = new CanvasWindowAdapter(new Rect(0, 0, getCanvasWidth(), getCanvasHeight()),
EditorGUIUtility.pixelsPerPoint, gameObject);
var root = new WidgetsApp(null, getWidget());
_windowAdapter.attachRootWidget(root);
}
setupMeshRenderer();

private void ensureRenderTexture()
{
if (_renderTexture != null && _renderTexture.IsCreated() &&
_renderTexture.width == _canvasWidth && _renderTexture.height == _canvasHeight)
_renderTexture.width == getCanvasWidth() && _renderTexture.height == getCanvasHeight())
{
return;
}

_renderTexture.Release();
}
_renderTexture = new RenderTexture(_canvasWidth, _canvasHeight, 24);
_renderTexture = new RenderTexture(getCanvasWidth(), getCanvasHeight(), 24);
var effectiveWidth = getCanvasWidth();
var effectiveHeight = getCanvasHeight();
Matrix4x4 m =Matrix4x4.Scale(new Vector3(2.0f / _canvasWidth, -2.0f / _canvasHeight, 1.0f))
* Matrix4x4.Translate(new Vector3(-_canvasWidth / 2.0f, -_canvasHeight / 2.0f, 0));
Matrix4x4 m =Matrix4x4.Scale(new Vector3(2.0f / effectiveWidth, -2.0f / effectiveHeight, 1.0f))
* Matrix4x4.Translate(new Vector3(-effectiveWidth / 2.0f, -effectiveHeight / 2.0f, 0));
GL.LoadProjectionMatrix(m);
ensureRenderTexture();

void OnMouseDown()
{
int x = Screen.width;
int y = Screen.height;
var pos = convertPosition(Input.mousePosition);
this._windowAdapter.PostPointerEvent(new PointerData(
timeStamp: DateTime.Now,

plan.Raycast(ray, out enter);
hitPoint = ray.GetPoint(enter);
}
(localPoint.x + 0.5) * _canvasWidth * EditorGUIUtility.pixelsPerPoint,
(-localPoint.y + 0.5) * _canvasHeight * EditorGUIUtility.pixelsPerPoint
(localPoint.x + 0.5) * getCanvasWidth() * _windowAdapter.devicePixelRatio,
(-localPoint.y + 0.5) * getCanvasHeight() * _windowAdapter.devicePixelRatio
);
}

}
return 0;
}
private int getCanvasWidth()
{
return _canvasWidth;
}
private int getCanvasHeight()
{
return _canvasHeight;
}
}
}

12
Assets/UIWidgets/engine/canvas_window.cs


{
private Rect _position;
private double __devicePixelRatio;
public CanvasWindowAdapter(Rect position, double devicePixelRatio, Transform tranform): base(position, devicePixelRatio)
private GameObject gameObject;
public CanvasWindowAdapter(Rect position, double devicePixelRatio, GameObject gameObject): base(position, devicePixelRatio)
this.gameObject = gameObject;
}
public override void scheduleFrame()

public override GUIContent titleContent
{
get
{
return new GUIContent(gameObject.name);
}
}
protected override void getWindowMetrics(out double devicePixelRatio, out Rect position)
{
devicePixelRatio = this.__devicePixelRatio;

14
Assets/UIWidgets/widgets/basic.cs


this.textBaseline = textBaseline;
}
public Axis direction;
public MainAxisAlignment mainAxisAlignment;
public MainAxisSize mainAxisSize;
public CrossAxisAlignment crossAxisAlignment;
public TextDirection? textDirection;
public VerticalDirection verticalDirection;
public TextBaseline? textBaseline;
public readonly Axis direction;
public readonly MainAxisAlignment mainAxisAlignment;
public readonly MainAxisSize mainAxisSize;
public readonly CrossAxisAlignment crossAxisAlignment;
public readonly TextDirection? textDirection;
public readonly VerticalDirection verticalDirection;
public readonly TextBaseline? textBaseline;
private bool _needTextDirection {
get {

384
Assets/UIWidgetsSample/UIWidgetSample.unity


debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &8243871
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8243874}
- component: {fileID: 8243873}
- component: {fileID: 8243872}
m_Layer: 0
m_Name: SubCamera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!81 &8243872
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8243871}
m_Enabled: 1
--- !u!20 &8243873
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8243871}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_GateFitMode: 2
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 26.991467
orthographic: 0
orthographic size: 5
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 8400000, guid: 434a0618f87de4aed83cd4d4d2ab0db9, type: 2}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &8243874
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8243871}
m_LocalRotation: {x: 0.40821788, y: -0.10938167, z: 0.23456976, w: 0.8754261}
m_LocalPosition: {x: 0, y: 8, z: -8}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 50, y: 0, z: 30}
--- !u!1 &104466517
GameObject:
m_ObjectHideFlags: 0

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &104466518
MonoBehaviour:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 104466517}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 3, y: -3, z: 10}
m_LocalPosition: {x: 0, y: 0, z: 10}
m_RootOrder: 8
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &106383827
GameObject:

m_GameObject: {fileID: 244594849}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.43529412, g: 0.43529412, b: 0.43529412, a: 1}
m_ClearFlags: 1
m_BackGroundColor: {r: 1, g: 1, b: 1, a: 1}
m_projectionMatrixMode: 1
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 244594849}
m_LocalRotation: {x: 0.08710269, y: 0.03476669, z: -0.0030416925, w: 0.9955878}
m_LocalPosition: {x: 0, y: 2, z: -15}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -15}
m_LocalEulerAnglesHint: {x: 10, y: 4, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &244594853
MonoBehaviour:
m_ObjectHideFlags: 0

- {fileID: 106383828}
- {fileID: 2122583335}
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &738891908
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 738891912}
- component: {fileID: 738891911}
- component: {fileID: 738891910}
- component: {fileID: 738891909}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!135 &738891909
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 738891908}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &738891910
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 738891908}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 70a67730c853045f8897618c93c7eb2f, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &738891911
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 738891908}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &738891912
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 738891908}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1492232671
GameObject:

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!65 &1492232672
BoxCollider:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 45ef9c98c7594497921b0c714f2b4c33, type: 3}
m_Name:
m_EditorClassIdentifier:
_canvasWidth: 1000
_canvasWidth: 500
_canvasHeight: 800
--- !u!4 &1601353204
Transform:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1601353202}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 3, y: -3, z: 10}
m_LocalScale: {x: 10, y: 8, z: 1}
m_LocalPosition: {x: -3, y: 0, z: 5}
m_LocalScale: {x: 5, y: 8, z: 1}
m_RootOrder: 9
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1632355044
GameObject:

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1639769398}
m_CullTransparentMesh: 0
--- !u!1 &1722587565
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1722587569}
- component: {fileID: 1722587568}
- component: {fileID: 1722587566}
- component: {fileID: 1722587567}
m_Layer: 0
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!23 &1722587566
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1722587565}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1722587567
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1722587565}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &1722587568
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1722587565}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 91ddd2cdccbf943eba2642d5c1008038, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1722587569
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1722587565}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -2, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1747383262
GameObject:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1948692140}
m_CullTransparentMesh: 0
--- !u!1 &2013714663
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2013714667}
- component: {fileID: 2013714666}
- component: {fileID: 2013714665}
- component: {fileID: 2013714664}
m_Layer: 0
m_Name: Cube (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!65 &2013714664
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2013714663}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &2013714665
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2013714663}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 9ce2d2adc91f3476aa88f8f119a0374d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &2013714666
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2013714663}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &2013714667
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2013714663}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -2.63, y: 0.1, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2045656574
GameObject:
m_ObjectHideFlags: 0

202
Assets/UIWidgetsSample/ToDoAppCanvas.cs


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
)
);
}
}
}

13
Assets/UIWidgetsSample/SampleCanvas.cs


using UIWidgets.engine;
using UIWidgets.widgets;
namespace UIWidgetsSample
{
public class SampleCanvas:WidgetCanvas
{
protected override Widget getWidget()
{
return new AsScreen();
}
}
}

3
Assets/UIWidgetsSample/SampleCanvas.cs.meta


fileFormatVersion: 2
guid: 45ef9c98c7594497921b0c714f2b4c33
timeCreated: 1545377537
正在加载...
取消
保存