您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
244 行
7.8 KiB
244 行
7.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using uiwidgets;
|
|
using Unity.UIWidgets.cupertino;
|
|
using Unity.UIWidgets.material;
|
|
using Unity.UIWidgets.painting;
|
|
using Unity.UIWidgets.rendering;
|
|
using Unity.UIWidgets.ui;
|
|
using Unity.UIWidgets.widgets;
|
|
using Canvas = Unity.UIWidgets.ui.Canvas;
|
|
using Color = Unity.UIWidgets.ui.Color;
|
|
using TextStyle = Unity.UIWidgets.painting.TextStyle;
|
|
using Transform = Unity.UIWidgets.widgets.Transform;
|
|
|
|
namespace UIWidgetsSample.RaycastableScene
|
|
{
|
|
public class SceneBoard : StatefulWidget
|
|
{
|
|
public override State createState()
|
|
{
|
|
return new SceneBoardState();
|
|
}
|
|
}
|
|
|
|
public class SceneBoardState : State<SceneBoard>
|
|
{
|
|
public override Widget build(BuildContext context)
|
|
{
|
|
return new Container(
|
|
height: RaycastableSceneConfig.height,
|
|
color: RaycastableSceneConfig.mainColor,
|
|
child:
|
|
new Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: new List<Widget>()
|
|
{
|
|
new Padding(padding: EdgeInsets.only(left:10f)),
|
|
new Text("Made with UIWidgets", style: new TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 12,
|
|
fontStyle: FontStyle.italic
|
|
)),
|
|
new Padding(padding: EdgeInsets.only(left: 50f)),
|
|
new Expanded(
|
|
child: Transform.scale(
|
|
alignment: Alignment.center,
|
|
scale: RaycastableSceneConfig.scaleSceneBoard,
|
|
child: new Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: new List<Widget>
|
|
{
|
|
new ActionBox(
|
|
name: RaycastableSceneConfig.LightSwitchName,
|
|
onChange: value =>
|
|
{
|
|
LightController.SwitchLight(value);
|
|
}),
|
|
new Padding(padding: EdgeInsets.only(left: 30f)),
|
|
new Divider(color: Colors.black),
|
|
new Padding(padding: EdgeInsets.only(right: 30f)),
|
|
new LightSlider()
|
|
})
|
|
)),
|
|
}
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
public class ActionBox : StatefulWidget
|
|
{
|
|
public string name;
|
|
public Action<bool> onChange;
|
|
|
|
public ActionBox(string name, Action<bool> onChange)
|
|
{
|
|
this.name = name;
|
|
this.onChange = onChange;
|
|
}
|
|
|
|
public override State createState()
|
|
{
|
|
return new ActionBoxState();
|
|
}
|
|
}
|
|
|
|
public class ActionBoxState : State<ActionBox>
|
|
{
|
|
private bool value = true;
|
|
|
|
public override Widget build(BuildContext context)
|
|
{
|
|
return new Row(
|
|
children: new List<Widget>()
|
|
{
|
|
new Text(
|
|
value? RaycastableSceneConfig.LightOn : RaycastableSceneConfig.LightOff,
|
|
style: RaycastableSceneConfig.fontStyle
|
|
),
|
|
new Padding(padding: EdgeInsets.only(left: 7f)),
|
|
new CupertinoSwitch(
|
|
value: value,
|
|
onChanged: valueIn =>
|
|
{
|
|
setState(() =>
|
|
{
|
|
value = valueIn;
|
|
widget.onChange?.Invoke(value);
|
|
});
|
|
}
|
|
),
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
class LightSlider : StatefulWidget
|
|
{
|
|
public override State createState()
|
|
{
|
|
return new LightSliderState();
|
|
}
|
|
}
|
|
|
|
internal class LightSliderState : State<LightSlider>
|
|
{
|
|
private float _currentSliderValue = 0;
|
|
|
|
public override Widget build(BuildContext context)
|
|
{
|
|
var color = HSVColor.fromAHSV(1, _currentSliderValue * 360, 1, 1).toColor();
|
|
return new Row(
|
|
children: new List<Widget>()
|
|
{
|
|
new Text(RaycastableSceneConfig.LightSliderName, style: RaycastableSceneConfig.fontStyle),
|
|
new Padding(padding: EdgeInsets.only(left: 7f)),
|
|
new Container(width: 20, height: 20, color: color),
|
|
new Padding(padding: EdgeInsets.only(left: 7f)),
|
|
new Slider(
|
|
value: _currentSliderValue,
|
|
min: 0,
|
|
max: 1,
|
|
onChanged: (value) =>
|
|
{
|
|
setState(() =>
|
|
{
|
|
_currentSliderValue = value;
|
|
LightController.ChangeLightColor(value);
|
|
});
|
|
}
|
|
),
|
|
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
class ColorPicker : StatefulWidget
|
|
{
|
|
public readonly float width;
|
|
|
|
public ColorPicker(float width)
|
|
{
|
|
this.width = width;
|
|
}
|
|
|
|
public override State createState() => new _ColorPickerState();
|
|
}
|
|
|
|
class _ColorPickerState : State<ColorPicker>
|
|
{
|
|
readonly List<Color> _colors = new List<Color>()
|
|
{
|
|
Color.fromARGB(255, 255, 0, 0),
|
|
Color.fromARGB(255, 255, 128, 0),
|
|
Color.fromARGB(255, 255, 255, 0),
|
|
Color.fromARGB(255, 128, 255, 0),
|
|
Color.fromARGB(255, 0, 255, 0),
|
|
Color.fromARGB(255, 0, 255, 128),
|
|
Color.fromARGB(255, 0, 255, 255),
|
|
Color.fromARGB(255, 0, 128, 255),
|
|
Color.fromARGB(255, 0, 0, 255),
|
|
Color.fromARGB(255, 127, 0, 255),
|
|
Color.fromARGB(255, 255, 0, 255),
|
|
Color.fromARGB(255, 255, 0, 127),
|
|
Color.fromARGB(255, 128, 128, 128),
|
|
};
|
|
|
|
public override Widget build(BuildContext context)
|
|
{
|
|
return new Column(
|
|
children: new List<Widget>
|
|
{
|
|
new Center(
|
|
child: new Container(
|
|
width: widget.width,
|
|
height: 15,
|
|
decoration: new BoxDecoration(
|
|
border: Border.all(width: 2, color: Colors.grey[800]),
|
|
borderRadius: BorderRadius.circular(15),
|
|
gradient: new LinearGradient(colors: _colors)
|
|
)
|
|
)
|
|
)
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
class _SliderIndicatorPainter : CustomPainter {
|
|
readonly float position;
|
|
|
|
_SliderIndicatorPainter(float position)
|
|
{
|
|
this.position = position;
|
|
}
|
|
|
|
public void paint(Canvas canvas, Size size) {
|
|
canvas.drawCircle(
|
|
new Offset(position, size.height / 2), 12, new Paint(){color = Colors.black});
|
|
}
|
|
|
|
public bool shouldRepaint(CustomPainter oldDelegate)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public bool? hitTest(Offset position)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
|
|
public void addListener(VoidCallback listener)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void removeListener(VoidCallback listener)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|