浏览代码
Merge branch 'kgdev' into 'master'
Merge branch 'kgdev' into 'master'
MediaQuery See merge request upm-packages/ui-widgets/com.unity.uiwidgets!9/main
Fan Zhang
6 年前
当前提交
563bba8d
共有 18 个文件被更改,包括 767 次插入 和 182 次删除
-
6Runtime/Resources/UIWidgets_canvas.shader
-
27Runtime/editor/surface.cs
-
54Runtime/engine/WidgetCanvas.cs
-
9Runtime/painting/edge_insets.cs
-
23Runtime/painting/image_resolution.cs
-
4Runtime/rendering/binding.cs
-
177Runtime/ui/window.cs
-
111Runtime/widgets/app.cs
-
22Runtime/widgets/binding.cs
-
38Runtime/widgets/framework.cs
-
3Runtime/widgets/image.cs
-
10Runtime/widgets/widget_inspector.cs
-
2Tests/Editor/MouseHover.cs
-
19Tests/Editor/Widgets.cs
-
114Runtime/Resources/UIWidgets_UIDefault.shader
-
9Runtime/Resources/UIWidgets_UIDefault.shader.meta
-
310Runtime/widgets/media_query.cs
-
11Runtime/widgets/media_query.cs.meta
|
|||
Shader "UIWidgets/UIDefault" |
|||
{ |
|||
Properties |
|||
{ |
|||
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} |
|||
_Color ("Tint", Color) = (1,1,1,1) |
|||
|
|||
_StencilComp ("Stencil Comparison", Float) = 8 |
|||
_Stencil ("Stencil ID", Float) = 0 |
|||
_StencilOp ("Stencil Operation", Float) = 0 |
|||
_StencilWriteMask ("Stencil Write Mask", Float) = 255 |
|||
_StencilReadMask ("Stencil Read Mask", Float) = 255 |
|||
|
|||
_ColorMask ("Color Mask", Float) = 15 |
|||
|
|||
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags |
|||
{ |
|||
"Queue"="Transparent" |
|||
"IgnoreProjector"="True" |
|||
"RenderType"="Transparent" |
|||
"PreviewType"="Plane" |
|||
"CanUseSpriteAtlas"="True" |
|||
} |
|||
|
|||
Stencil |
|||
{ |
|||
Ref [_Stencil] |
|||
Comp [_StencilComp] |
|||
Pass [_StencilOp] |
|||
ReadMask [_StencilReadMask] |
|||
WriteMask [_StencilWriteMask] |
|||
} |
|||
|
|||
Cull Off |
|||
Lighting Off |
|||
ZWrite Off |
|||
ZTest [unity_GUIZTestMode] |
|||
Blend One OneMinusSrcAlpha |
|||
ColorMask [_ColorMask] |
|||
|
|||
Pass |
|||
{ |
|||
Name "Default" |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma target 2.0 |
|||
|
|||
#include "UnityCG.cginc" |
|||
#include "UnityUI.cginc" |
|||
|
|||
#pragma multi_compile __ UNITY_UI_CLIP_RECT |
|||
#pragma multi_compile __ UNITY_UI_ALPHACLIP |
|||
|
|||
struct appdata_t |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct v2f |
|||
{ |
|||
float4 vertex : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
float4 worldPosition : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
fixed4 _Color; |
|||
fixed4 _TextureSampleAdd; |
|||
float4 _ClipRect; |
|||
float4 _MainTex_ST; |
|||
|
|||
v2f vert(appdata_t v) |
|||
{ |
|||
v2f OUT; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); |
|||
OUT.worldPosition = v.vertex; |
|||
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition); |
|||
|
|||
OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); |
|||
|
|||
OUT.color = v.color * _Color; |
|||
return OUT; |
|||
} |
|||
|
|||
fixed4 frag(v2f IN) : SV_Target |
|||
{ |
|||
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color; |
|||
|
|||
#ifdef UNITY_UI_CLIP_RECT |
|||
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect); |
|||
#endif |
|||
|
|||
#ifdef UNITY_UI_ALPHACLIP |
|||
clip (color.a - 0.001); |
|||
#endif |
|||
|
|||
return color; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 43b4ae1d316ca415589f96e49cc0fcab |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.widgets { |
|||
public enum Orientation { |
|||
portrait, |
|||
landscape |
|||
} |
|||
|
|||
public class MediaQueryData : IEquatable<MediaQueryData> { |
|||
public MediaQueryData( |
|||
Size size = null, |
|||
double devicePixelRatio = 1.0, |
|||
double textScaleFactor = 1.0, |
|||
EdgeInsets viewInsets = null, |
|||
EdgeInsets padding = null, |
|||
bool alwaysUse24HourFormat = false, |
|||
bool accessibleNavigation = false, |
|||
bool invertColors = false, |
|||
bool disableAnimations = false, |
|||
bool boldText = false |
|||
) { |
|||
this.size = size ?? Size.zero; |
|||
this.devicePixelRatio = devicePixelRatio; |
|||
this.textScaleFactor = textScaleFactor; |
|||
this.viewInsets = viewInsets ?? EdgeInsets.zero; |
|||
this.padding = padding ?? EdgeInsets.zero; |
|||
this.alwaysUse24HourFormat = alwaysUse24HourFormat; |
|||
this.accessibleNavigation = accessibleNavigation; |
|||
this.invertColors = invertColors; |
|||
this.disableAnimations = disableAnimations; |
|||
this.boldText = boldText; |
|||
} |
|||
|
|||
public static MediaQueryData fromWindow(Window window) { |
|||
return new MediaQueryData( |
|||
size: window.physicalSize / window.devicePixelRatio, |
|||
devicePixelRatio: window.devicePixelRatio, |
|||
textScaleFactor: window.textScaleFactor, |
|||
viewInsets: EdgeInsets.fromWindowPadding(window.viewInsets, window.devicePixelRatio), |
|||
padding: EdgeInsets.fromWindowPadding(window.padding, window.devicePixelRatio) |
|||
// accessibleNavigation: window.accessibilityFeatures.accessibleNavigation,
|
|||
// invertColors: window.accessibilityFeatures.invertColors,
|
|||
// disableAnimations: window.accessibilityFeatures.disableAnimations,
|
|||
// boldText: window.accessibilityFeatures.boldText,
|
|||
// alwaysUse24HourFormat: window.alwaysUse24HourFormat
|
|||
); |
|||
} |
|||
|
|||
public readonly Size size; |
|||
|
|||
public readonly double devicePixelRatio; |
|||
|
|||
public readonly double textScaleFactor; |
|||
|
|||
public readonly EdgeInsets viewInsets; |
|||
|
|||
public readonly EdgeInsets padding; |
|||
|
|||
public readonly bool alwaysUse24HourFormat; |
|||
|
|||
public readonly bool accessibleNavigation; |
|||
|
|||
public readonly bool invertColors; |
|||
|
|||
public readonly bool disableAnimations; |
|||
|
|||
public readonly bool boldText; |
|||
|
|||
public Orientation orientation => |
|||
this.size.width > this.size.height ? Orientation.landscape : Orientation.portrait; |
|||
|
|||
public MediaQueryData copyWith( |
|||
Size size = null, |
|||
double? devicePixelRatio = null, |
|||
double? textScaleFactor = null, |
|||
EdgeInsets viewInsets = null, |
|||
EdgeInsets padding = null, |
|||
bool? alwaysUse24HourFormat = null, |
|||
bool? accessibleNavigation = null, |
|||
bool? invertColors = null, |
|||
bool? disableAnimations = null, |
|||
bool? boldText = null |
|||
) { |
|||
return new MediaQueryData( |
|||
size: size ?? this.size, |
|||
devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, |
|||
textScaleFactor: textScaleFactor ?? this.textScaleFactor, |
|||
viewInsets: viewInsets ?? this.viewInsets, |
|||
padding: padding ?? this.padding, |
|||
alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat, |
|||
accessibleNavigation: accessibleNavigation ?? this.accessibleNavigation, |
|||
invertColors: invertColors ?? this.invertColors, |
|||
disableAnimations: disableAnimations ?? this.disableAnimations, |
|||
boldText: boldText ?? this.boldText |
|||
); |
|||
} |
|||
|
|||
public MediaQueryData removePadding( |
|||
bool removeLeft = false, |
|||
bool removeTop = false, |
|||
bool removeRight = false, |
|||
bool removeBottom = false |
|||
) { |
|||
if (!(removeLeft || removeTop || removeRight || removeBottom)) { |
|||
return this; |
|||
} |
|||
|
|||
return new MediaQueryData( |
|||
size: this.size, |
|||
devicePixelRatio: this.devicePixelRatio, |
|||
textScaleFactor: this.textScaleFactor, |
|||
padding: this.padding.copyWith( |
|||
left: removeLeft ? (double?) 0.0 : null, |
|||
top: removeTop ? (double?) 0.0 : null, |
|||
right: removeRight ? (double?) 0.0 : null, |
|||
bottom: removeBottom ? (double?) 0.0 : null |
|||
), |
|||
viewInsets: this.viewInsets, |
|||
alwaysUse24HourFormat: this.alwaysUse24HourFormat, |
|||
disableAnimations: this.disableAnimations, |
|||
invertColors: this.invertColors, |
|||
accessibleNavigation: this.accessibleNavigation, |
|||
boldText: this.boldText |
|||
); |
|||
} |
|||
|
|||
public MediaQueryData removeViewInsets( |
|||
bool removeLeft = false, |
|||
bool removeTop = false, |
|||
bool removeRight = false, |
|||
bool removeBottom = false |
|||
) { |
|||
if (!(removeLeft || removeTop || removeRight || removeBottom)) { |
|||
return this; |
|||
} |
|||
|
|||
return new MediaQueryData( |
|||
size: this.size, |
|||
devicePixelRatio: this.devicePixelRatio, |
|||
textScaleFactor: this.textScaleFactor, |
|||
padding: this.padding, |
|||
viewInsets: this.viewInsets.copyWith( |
|||
left: removeLeft ? (double?) 0.0 : null, |
|||
top: removeTop ? (double?) 0.0 : null, |
|||
right: removeRight ? (double?) 0.0 : null, |
|||
bottom: removeBottom ? (double?) 0.0 : null |
|||
), |
|||
alwaysUse24HourFormat: this.alwaysUse24HourFormat, |
|||
disableAnimations: this.disableAnimations, |
|||
invertColors: this.invertColors, |
|||
accessibleNavigation: this.accessibleNavigation, |
|||
boldText: this.boldText |
|||
); |
|||
} |
|||
|
|||
public bool Equals(MediaQueryData other) { |
|||
if (ReferenceEquals(null, other)) return false; |
|||
if (ReferenceEquals(this, other)) return true; |
|||
return Equals(this.size, other.size) && this.devicePixelRatio.Equals(other.devicePixelRatio) && |
|||
this.textScaleFactor.Equals(other.textScaleFactor) && Equals(this.viewInsets, other.viewInsets) && |
|||
Equals(this.padding, other.padding) && this.alwaysUse24HourFormat == other.alwaysUse24HourFormat && |
|||
this.accessibleNavigation == other.accessibleNavigation && this.invertColors == other.invertColors && |
|||
this.disableAnimations == other.disableAnimations && this.boldText == other.boldText; |
|||
} |
|||
|
|||
public override bool Equals(object obj) { |
|||
if (ReferenceEquals(null, obj)) return false; |
|||
if (ReferenceEquals(this, obj)) return true; |
|||
if (obj.GetType() != this.GetType()) return false; |
|||
return this.Equals((MediaQueryData) obj); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
var hashCode = (this.size != null ? this.size.GetHashCode() : 0); |
|||
hashCode = (hashCode * 397) ^ this.devicePixelRatio.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.textScaleFactor.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ (this.viewInsets != null ? this.viewInsets.GetHashCode() : 0); |
|||
hashCode = (hashCode * 397) ^ (this.padding != null ? this.padding.GetHashCode() : 0); |
|||
hashCode = (hashCode * 397) ^ this.alwaysUse24HourFormat.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.accessibleNavigation.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.invertColors.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.disableAnimations.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.boldText.GetHashCode(); |
|||
return hashCode; |
|||
} |
|||
} |
|||
|
|||
public static bool operator ==(MediaQueryData left, MediaQueryData right) { |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(MediaQueryData left, MediaQueryData right) { |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
public override string ToString() { |
|||
return $"{this.GetType()}(" + |
|||
$"size: {this.size}, " + |
|||
$"devicePixelRatio: {this.devicePixelRatio:F1}, " + |
|||
$"textScaleFactor: {this.textScaleFactor:F1}, " + |
|||
$"padding: {this.padding}, " + |
|||
$"viewInsets: {this.viewInsets}, " + |
|||
$"alwaysUse24HourFormat: {this.alwaysUse24HourFormat}, " + |
|||
$"accessibleNavigation: {this.accessibleNavigation}" + |
|||
$"disableAnimations: {this.disableAnimations}" + |
|||
$"invertColors: {this.invertColors}" + |
|||
$"boldText: {this.boldText}" + |
|||
")"; |
|||
} |
|||
} |
|||
|
|||
public class MediaQuery : InheritedWidget { |
|||
public MediaQuery( |
|||
Key key = null, |
|||
MediaQueryData data = null, |
|||
Widget child = null |
|||
) : base(key, child) { |
|||
D.assert(child != null); |
|||
D.assert(data != null); |
|||
this.data = data; |
|||
} |
|||
|
|||
public static MediaQuery removePadding( |
|||
Key key = null, |
|||
BuildContext context = null, |
|||
bool removeLeft = false, |
|||
bool removeTop = false, |
|||
bool removeRight = false, |
|||
bool removeBottom = false, |
|||
Widget child = null |
|||
) { |
|||
D.assert(context != null); |
|||
return new MediaQuery( |
|||
key: key, |
|||
data: MediaQuery.of(context).removePadding( |
|||
removeLeft: removeLeft, |
|||
removeTop: removeTop, |
|||
removeRight: removeRight, |
|||
removeBottom: removeBottom |
|||
), |
|||
child: child |
|||
); |
|||
} |
|||
|
|||
public static MediaQuery removeViewInsets( |
|||
Key key = null, |
|||
BuildContext context = null, |
|||
bool removeLeft = false, |
|||
bool removeTop = false, |
|||
bool removeRight = false, |
|||
bool removeBottom = false, |
|||
Widget child = null |
|||
) { |
|||
D.assert(context != null); |
|||
return new MediaQuery( |
|||
key: key, |
|||
data: MediaQuery.of(context).removeViewInsets( |
|||
removeLeft: removeLeft, |
|||
removeTop: removeTop, |
|||
removeRight: removeRight, |
|||
removeBottom: removeBottom |
|||
), |
|||
child: child |
|||
); |
|||
} |
|||
|
|||
public readonly MediaQueryData data; |
|||
|
|||
public static MediaQueryData of(BuildContext context, bool nullOk = false) { |
|||
D.assert(context != null); |
|||
MediaQuery query = (MediaQuery) context.inheritFromWidgetOfExactType(typeof(MediaQuery)); |
|||
if (query != null) { |
|||
return query.data; |
|||
} |
|||
|
|||
if (nullOk) { |
|||
return null; |
|||
} |
|||
|
|||
throw new UIWidgetsError( |
|||
"MediaQuery.of() called with a context that does not contain a MediaQuery.\n" + |
|||
"No MediaQuery ancestor could be found starting from the context that was passed " + |
|||
"to MediaQuery.of(). This can happen because you do not have a WidgetsApp or " + |
|||
"MaterialApp widget (those widgets introduce a MediaQuery), or it can happen " + |
|||
"if the context you use comes from a widget above those widgets.\n" + |
|||
"The context used was:\n" + |
|||
$" {context}"); |
|||
} |
|||
|
|||
public static double textScaleFactorOf(BuildContext context) { |
|||
return MediaQuery.of(context, nullOk: true)?.textScaleFactor ?? 1.0; |
|||
} |
|||
|
|||
static bool boldTextOverride(BuildContext context) { |
|||
return MediaQuery.of(context, nullOk: true)?.boldText ?? false; |
|||
} |
|||
|
|||
public override bool updateShouldNotify(InheritedWidget oldWidget) => |
|||
this.data != ((MediaQuery) oldWidget).data; |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new DiagnosticsProperty<MediaQueryData>("data", this.data, showName: false)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e578bc0c4f03f48ef88045315c000575 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue