浏览代码

Merge pull request #22 from UnityTech/image

fix image box fit & refine demo page
/main
GitHub 6 年前
当前提交
755960b0
共有 3 个文件被更改,包括 44 次插入21 次删除
  1. 45
      Assets/UIWidgets/Tests/Widgets.cs
  2. 9
      Assets/UIWidgets/painting/box_fit.cs
  3. 11
      Assets/UIWidgets/ui/painting/canvas_impl.cs

45
Assets/UIWidgets/Tests/Widgets.cs


)
),
new CustomButton(
padding: EdgeInsets.only(4.0, 0.0, 16.0, 0.0),
padding: EdgeInsets.only(0.0, 0.0, 16.0, 0.0),
Icons.notifications,
Icons.keyboard_arrow_down,
size: 18.0,
color: CLColors.icon2
)

cursorColor: Color.fromARGB(255, 0, 0, 0)
)
),
new CustomButton(
backgroundColor: CLColors.background4,
child: new Icon(
Icons.notifications,
size: 18.0,
color: CLColors.white
new Container(
decoration: new BoxDecoration(
color: CLColors.background4,
borderRadius: BorderRadius.all(2)
),
width: 36,
height: 36,
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget> {
new CustomButton(
padding: EdgeInsets.only(-8.0, 0.0, 8.0, 0.0),
child: new Icon(
Icons.search,
size: 18.0,
color: CLColors.white
)
)
}
)
),
new Container(

}
Widget _buildBanner(BuildContext context) {
return new Container(child:
new Container(
return new Container(
"https://d2ujflorbtfzji.cloudfront.net/banner/38942865-28db-482b-80c5-17809473f3c6.jpg",
"https://d2ujflorbtfzji.cloudfront.net/banner/5c57178c-4be6-4903-953b-85125bfb7154.jpg",
)
);
}

public override Widget build(BuildContext context) {
var card = new Container(
margin: EdgeInsets.only(right: 45),
color: CLColors.white,
color: CLColors.white,
decoration: new BoxDecoration(
color: CLColors.white,
borderRadius: BorderRadius.only(topLeft: 3, topRight: 3)
),
width: 200,
height: 124,
child: widgets.Image.network(

),
new Container(
color: CLColors.white,
width: 200,
height: 86,
padding: EdgeInsets.fromLTRB(14, 12, 14, 8),

public static class Icons {
public static readonly IconData notifications = new IconData(0xe7f4, fontFamily: "MaterialIcons");
public static readonly IconData account_circle = new IconData(0xe853, fontFamily: "MaterialIcons");
public static readonly IconData search = new IconData(0xe8b6, fontFamily: "MaterialIcons");
public static readonly IconData keyboard_arrow_down = new IconData(0xe313, fontFamily: "MaterialIcons");
}
public static class CLColors {

9
Assets/UIWidgets/painting/box_fit.cs


case BoxFit.cover:
if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) {
sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width);
} else {
sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height, inputSize.height);
else {
sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height,
inputSize.height);
}
break;
break;
case BoxFit.fitWidth:
sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width);
destinationSize = new Size(outputSize.width,

11
Assets/UIWidgets/ui/painting/canvas_impl.cs


public void drawImageRect(Rect src, Rect dst, Paint paint, Image image) {
if (image != null && image.texture != null) {
Graphics.DrawTexture(dst.toRect(), image.texture);
// convert src rect to Unity rect in normalized coordinates with (0,0) in the bottom-left corner.
var textureHeight = image.texture.height;
var textureWidth = image.texture.width;
var srcRect = new UnityEngine.Rect(
(float) (src.left / textureWidth),
(float) ((textureHeight - src.bottom) / textureHeight),
(float) (src.width / textureWidth),
(float) (src.height / textureHeight)
);
Graphics.DrawTexture(dst.toRect(), image.texture, srcRect, 0, 0 ,0 ,0);
}
}

正在加载...
取消
保存