浏览代码

Merge remote-tracking branch 'origin/master'

/main
kg 6 年前
当前提交
923965c5
共有 4 个文件被更改,包括 138 次插入22 次删除
  1. 37
      Assets/UIWidgets/Tests/Widgets.cs
  2. 8
      Assets/UIWidgets/painting/decoration_image.cs
  3. 53
      Assets/UIWidgets/painting/image_provider.cs
  4. 62
      Assets/UIWidgets/widgets/image.cs

37
Assets/UIWidgets/Tests/Widgets.cs


using UIWidgets.gestures;
using UIWidgets.ui;
using Color = UIWidgets.ui.Color;
using Image = UIWidgets.ui.Image;
using TextStyle = UIWidgets.painting.TextStyle;
namespace UIWidgets.Tests {

private readonly string[] _optionStrings;
private int _selected;
private string localImagePath;
this.localImage,
this.container,
this.flexRow,
this.flexColumn,

void OnGUI() {
var selected = EditorGUILayout.Popup("test case", this._selected, this._optionStrings);
if (selected != this._selected || !this.hasInvoked) {
// if local image test
if (selected == 0) {
localImagePath = EditorGUILayout.TextField(localImagePath);
if (this._selected != selected) {
this._selected = selected;
this.windowAdapter.attachRootWidget(null);
}
if (GUILayout.Button("load")) {
var rootWidget = this._options[this._selected]();
this.windowAdapter.attachRootWidget(rootWidget);
}
} else if (selected != this._selected || !this.hasInvoked) {
this._selected = selected;
this.hasInvoked = true;

this.windowAdapter = null;
}
Widget localImage() {
var image = widgets.Image.file(
localImagePath
);
return image;
}
var image = new widgets.Image(
var image = widgets.Image.network(
"https://tse3.mm.bing.net/th?id=OIP.XOAIpvR1kh-CzISe_Nj9GgHaHs&pid=Api",
width: 100,
height: 100

}
Widget flexColumn() {
var image = new widgets.Image(
var image = widgets.Image.network(
"https://tse3.mm.bing.net/th?id=OIP.XOAIpvR1kh-CzISe_Nj9GgHaHs&pid=Api",
width: 100,
height: 100

}
Widget container() {
var image = new widgets.Image(
var image = widgets.Image.network(
"https://tse3.mm.bing.net/th?id=OIP.XOAIpvR1kh-CzISe_Nj9GgHaHs&pid=Api",
width: 100,
height: 100,

if (pixels <= headerHeight) {
setState(() => { _offsetY = pixels / 2.0; });
}
} else {
}
else {
if (_offsetY != 0.0) {
setState(() => { _offsetY = 0.0; });
}

8
Assets/UIWidgets/painting/decoration_image.cs


Rect rect,
ui.Image image,
// ColorFilter colorFileter,
BoxFit fit,
BoxFit? fit,
Rect centerSlice,
Alignment alignment = null,
ImageRepeat repeat = ImageRepeat.noRepeat

inputSize -= sliceBorder;
}
fit = centerSlice == null ? BoxFit.scaleDown : BoxFit.fill;
FittedSizes fittedSizes = FittedSizes.applyBoxFit(fit, inputSize, outputSize);
if (fit == null) {
fit = centerSlice == null ? BoxFit.scaleDown : BoxFit.fill;
}
FittedSizes fittedSizes = FittedSizes.applyBoxFit(fit.Value, inputSize, outputSize);
Size sourceSize = fittedSizes.source;
Size destinationSize = fittedSizes.destination;
if (centerSlice != null) {

53
Assets/UIWidgets/painting/image_provider.cs


using RSG;
using System.Net;
using System;
using System.IO;
using UIWidgets.lib.cache_manager;
using UIWidgets.ui;

public override int GetHashCode() {
unchecked {
var hashCode = this.url.GetHashCode();
hashCode = (hashCode * 397) ^ this.scale.GetHashCode();
return hashCode;
}
}
}
public class FileImage : ImageProvider<FileImage> {
public FileImage(string path, double scale = 1.0) {
this.path = path;
this.scale = scale;
}
public string path;
public double scale;
public override FileImage obtainKey(ImageConfiguration configuration) {
return this;
}
public override ImageStreamCompleter load(FileImage key) {
return new OneFrameImageStreamCompleter(_loadAsync(key));
}
public static IPromise<ImageInfo> _loadAsync(FileImage key) {
var promise = new Promise<ImageInfo>();
var bytes = File.ReadAllBytes(key.path);
var imageInfo = new ImageInfo(new ui.Image(
bytes
));
promise.Resolve(imageInfo);
return promise;
}
public override string ToString() {
return "FileImage with Path: " + this.path;
}
public bool Equals(FileImage other) {
return this.path.Equals(other.path) && this.scale.Equals(other.scale);
}
public override bool Equals(object obj) {
if (object.ReferenceEquals(null, obj)) return false;
if (object.ReferenceEquals(this, obj)) return true;
return obj is FileImage && this.Equals((FileImage) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = this.path.GetHashCode();
hashCode = (hashCode * 397) ^ this.scale.GetHashCode();
return hashCode;
}

62
Assets/UIWidgets/widgets/image.cs


using UIWidgets.painting;
using UIWidgets.foundation;
using UIWidgets.ui;
using UnityEngine;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.widgets {

public Image(
Key key,
ImageProvider<object> image,
ImageProvider image,
double width,
double height,
Color color,

this.gaplessPlayback = gaplessPlayback;
}
// Network Image
public Image(
public static Image network(
string src,
Key key = null,
double width = 0.0,

ImageRepeat repeat = ImageRepeat.noRepeat,
bool gaplessPlayback = false,
double scale = 1.0
) : base(key) {
this.image = new NetworkImage(src, headers, scale);
this.width = width;
this.height = height;
this.color = color;
this.colorBlendMode = colorBlendMode;
this.fit = fit;
this.alignment = alignment;
this.centerSlice = centerSlice;
this.repeat = repeat;
this.gaplessPlayback = gaplessPlayback;
) {
var networkImage = new NetworkImage(src, headers, scale);
return new Image(
key,
networkImage,
width,
height,
color,
colorBlendMode,
fit,
centerSlice,
alignment,
repeat,
gaplessPlayback
);
}
public static Image file(
string path,
Key key = null,
double width = 0.0,
double height = 0.0,
Color color = null,
BlendMode colorBlendMode = BlendMode.None,
BoxFit fit = BoxFit.none,
Alignment alignment = null,
ui.Rect centerSlice = null,
ImageRepeat repeat = ImageRepeat.noRepeat,
bool gaplessPlayback = false,
double scale = 1.0
) {
var fileImage = new FileImage(path, scale);
return new Image(
key,
fileImage,
width,
height,
color,
colorBlendMode,
fit,
centerSlice,
alignment,
repeat,
gaplessPlayback
);
}
public override State createState() {

正在加载...
取消
保存