浏览代码

MediaQuery

/main
kg 6 年前
当前提交
b8702585
共有 14 个文件被更改,包括 596 次插入145 次删除
  1. 2
      Runtime/engine/WidgetCanvas.cs
  2. 9
      Runtime/painting/edge_insets.cs
  3. 23
      Runtime/painting/image_resolution.cs
  4. 4
      Runtime/rendering/binding.cs
  5. 177
      Runtime/ui/window.cs
  6. 111
      Runtime/widgets/app.cs
  7. 22
      Runtime/widgets/binding.cs
  8. 38
      Runtime/widgets/framework.cs
  9. 3
      Runtime/widgets/image.cs
  10. 10
      Runtime/widgets/widget_inspector.cs
  11. 2
      Tests/Editor/MouseHover.cs
  12. 19
      Tests/Editor/Widgets.cs
  13. 310
      Runtime/widgets/media_query.cs
  14. 11
      Runtime/widgets/media_query.cs.meta

2
Runtime/engine/WidgetCanvas.cs


}
_windowAdapter.OnEnable();
var root = new WidgetsApp(null, getWidget(), _windowAdapter);
var root = new WidgetsApp(home: getWidget(), window: _windowAdapter);
_windowAdapter.attachRootWidget(root);
_lastMouseMove = Input.mousePosition;
}

9
Runtime/painting/edge_insets.cs


return new EdgeInsets(horizontal, vertical, horizontal, vertical);
}
public static EdgeInsets fromWindowPadding(WindowPadding padding, double devicePixelRatio) {
return new EdgeInsets(
left: padding.left / devicePixelRatio,
top: padding.top / devicePixelRatio,
right: padding.right / devicePixelRatio,
bottom: padding.bottom / devicePixelRatio
);
}
public static readonly EdgeInsets zero = EdgeInsets.only();
public Offset topLeft {

23
Runtime/painting/image_resolution.cs


using System;
using System.Collections;
using System.Collections.Generic;
using RSG;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;

public readonly string assetName;
public readonly AssetBundle bundle;
readonly Dictionary<ImageConfiguration, AssetBundleImageKey> _cache =
new Dictionary<ImageConfiguration, AssetBundleImageKey>();
AssetBundleImageKey key;
if (this._cache.TryGetValue(configuration, out key)) {
return Promise<AssetBundleImageKey>.Resolved(key);
}
return (AssetBundleImageKey) result;
key = (AssetBundleImageKey) result;
this._cache[configuration] = key;
return key;
});
}

asset = request.asset;
}
if (asset != null) {
if (asset != null) {
if (bundle == null) {
Resources.UnloadAsset(asset);
} else {
bundle.Unload(asset);
}
yield return new AssetBundleImageKey(
bundle,
assetName,

4
Runtime/rendering/binding.cs


);
Window.instance.onMetricsChanged += this.handleMetricsChanged;
Window.instance.onTextScaleFactorChanged += this.handleTextScaleFactorChanged;
this.initRenderView();
D.assert(this.renderView != null);
this.addPersistentFrameCallback(this._handlePersistentFrameCallback);

protected virtual void handleMetricsChanged() {
this.renderView.configuration = this.createViewConfiguration();
this.scheduleForcedFrame();
}
protected virtual void handleTextScaleFactorChanged() {
}
protected virtual ViewConfiguration createViewConfiguration() {

177
Runtime/ui/window.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.async;
using Unity.UIWidgets.service;
using Unity.UIWidgets.foundation;

public delegate void PointerDataPacketCallback(PointerDataPacket packet);
public class WindowPadding {
public WindowPadding(double left, double top, double right, double bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public readonly double left;
public readonly double top;
public readonly double right;
public readonly double bottom;
public static WindowPadding zero = new WindowPadding(left: 0.0, top: 0.0, right: 0.0, bottom: 0.0);
public override string ToString() {
return $"{this.GetType()}(left: {this.left}, top: {this.top}, right: {this.right}, bottom: {this.bottom})";
}
}
public class Locale : IEquatable<Locale> {
public Locale(string languageCode, string countryCode = null) {
D.assert(languageCode != null);
this._languageCode = languageCode;
this._countryCode = countryCode;
}
readonly string _languageCode;
public string languageCode => this._languageCode;
readonly string _countryCode;
public string countryCode => this._countryCode;
public bool Equals(Locale other) {
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(this._languageCode, other._languageCode) &&
string.Equals(this._countryCode, other._countryCode);
}
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((Locale) obj);
}
public override int GetHashCode() {
unchecked {
return ((this._languageCode != null ? this._languageCode.GetHashCode() : 0) * 397) ^
(this._countryCode != null ? this._countryCode.GetHashCode() : 0);
}
}
public static bool operator ==(Locale left, Locale right) {
return Equals(left, right);
}
public static bool operator !=(Locale left, Locale right) {
return !Equals(left, right);
}
public override string ToString() {
if (this.countryCode == null) {
return this.languageCode;
}
return $"{this.languageCode}_{this.countryCode}";
}
}
public abstract class Window {
public static Window instance {
get {

}
public static bool hasInstance {
get {
return _instance != null;
}
get { return _instance != null; }
public double devicePixelRatio {
get { return this._devicePixelRatio; }
}
public double devicePixelRatio => this._devicePixelRatio;
public Size physicalSize {
get { return this._physicalSize; }
}
public Size physicalSize => this._physicalSize;
protected Size _physicalSize = Size.zero;
protected Size _physicalSize = Size.zero;
public WindowPadding viewInsets => this._viewInsets;
protected WindowPadding _viewInsets = WindowPadding.zero;
public WindowPadding padding => this._padding;
protected WindowPadding _padding = WindowPadding.zero;
public VoidCallback onMetricsChanged {
get { return this._onMetricsChanged; }

VoidCallback _onMetricsChanged;
public Locale locale {
get {
if (this._locales != null && this._locales.isNotEmpty()) {
return this._locales[0];
}
return null;
}
}
public List<Locale> locales => this._locales;
protected List<Locale> _locales;
public VoidCallback onLocaleChanged {
get { return this._onLocaleChanged; }
set { this._onLocaleChanged = value; }

public double textScaleFactor => this._textScaleFactor;
protected double _textScaleFactor = 1.0;
public VoidCallback onTextScaleFactorChanged {
get { return this._onTextScaleFactorChanged; }
set { this._onTextScaleFactorChanged = value; }
}
VoidCallback _onTextScaleFactorChanged;
public FrameCallback onBeginFrame {
get { return this._onBeginFrame; }
set { this._onBeginFrame = value; }

}
VoidCallback _onDrawFrame;
public PointerDataPacketCallback onPointerEvent {
get { return this._onPointerEvent; }
set { this._onPointerEvent = value; }

public abstract void flushMicrotasks();
public abstract Timer run(TimeSpan duration, Action callback, bool periodic = false);
public Timer run(Action callback) {
return this.run(TimeSpan.Zero, callback);
}

public abstract IDisposable getScope();
}
public class Locale : IEquatable<Locale> {
public Locale(string languageCode, string countryCode = null) {
D.assert(languageCode != null);
this._languageCode = languageCode;
this._countryCode = countryCode;
}
readonly string _languageCode;
public string languageCode => this._languageCode;
readonly string _countryCode;
public string countryCode => this._countryCode;
public bool Equals(Locale other) {
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(this._languageCode, other._languageCode) &&
string.Equals(this._countryCode, other._countryCode);
}
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((Locale) obj);
}
public override int GetHashCode() {
unchecked {
return ((this._languageCode != null ? this._languageCode.GetHashCode() : 0) * 397) ^
(this._countryCode != null ? this._countryCode.GetHashCode() : 0);
}
}
public static bool operator ==(Locale left, Locale right) {
return Equals(left, right);
}
public static bool operator !=(Locale left, Locale right) {
return !Equals(left, right);
}
public override string ToString() {
if (this.countryCode == null) {
return this.languageCode;
}
return $"{this.languageCode}_{this.countryCode}";
}
}
}

111
Runtime/widgets/app.cs


using System;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.UIWidgets.widgets
{
public class WidgetsApp : StatefulWidget
{
namespace Unity.UIWidgets.widgets {
public class WidgetsApp : StatefulWidget {
public readonly Window window;
public readonly Widget child;
public readonly Widget home;
public readonly Window window;
public WidgetsApp(Key key, Widget child, Window window) : base(key)
{
public WidgetsApp(
Key key = null,
Window window = null,
Widget home = null
) : base(key) {
this.child = child;
this.home = home;
public override State createState()
{
public override State createState() {
readonly Window _window;
public WindowProvider(Window window, Widget child, Key key = null) : base(key: key, child: child) {
public WindowProvider(Key key = null, Window window = null, Widget child = null) :
base(key: key, child: child) {
_window = window;
this.window = window;
public readonly Window window;
WindowProvider provider = context.inheritFromWidgetOfExactType(typeof(WindowProvider)) as WindowProvider;
WindowProvider provider = (WindowProvider) context.inheritFromWidgetOfExactType(typeof(WindowProvider));
return provider._window;
return provider.window;
D.assert(_window == ((WindowProvider)oldWidget)._window);
D.assert(this.window == ((WindowProvider) oldWidget).window);
class _WidgetsAppState : State<WidgetsApp>
{
class _WidgetsAppState : State<WidgetsApp>, WidgetsBindingObserver {
D.assert(() =>
{
D.assert(() => {
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance.removeObserver(this);
D.assert(() =>
{
D.assert(() => {
WidgetInspectorService.instance.inspectorShowCallback -= inspectorShowChanged;
return true;
});

private void inspectorShowChanged()
{
setState(() => {});
private void inspectorShowChanged() {
this.setState();
public override Widget build(BuildContext context)
{
Widget result = widget.child;
result = new WindowProvider(widget.window, result);
D.assert(() =>
{
if (WidgetInspectorService.instance.debugShowInspector)
{
result = new WidgetInspector(null, result, _InspectorSelectButtonBuilder);
public void didChangeMetrics() {
this.setState();
}
public void didChangeTextScaleFactor() {
this.setState();
}
public void didChangeLocales(List<Locale> locale) {
// TODO: support locales.
}
public override Widget build(BuildContext context) {
Widget result = this.widget.home;
D.assert(() => {
if (WidgetInspectorService.instance.debugShowInspector) {
result = new WidgetInspector(null, result, this._InspectorSelectButtonBuilder);
result = new WindowProvider(
window: this.widget.window,
child: result
);
result = new MediaQuery(
data: MediaQueryData.fromWindow(this.widget.window),
child: result
);
private Widget _InspectorSelectButtonBuilder(BuildContext context, VoidCallback onPressed)
{
private Widget _InspectorSelectButtonBuilder(BuildContext context, VoidCallback onPressed) {
) : base(key: key)
{
) : base(key: key) {
this.onPressed = () => onPressed();
}

22
Runtime/widgets/binding.cs


namespace Unity.UIWidgets.widgets {
public interface WidgetsBindingObserver {
void didChangeMetrics();
void didChangeTextScaleFactor();
void didChangeLocales(List<Locale> locale);
}
public class WidgetsBinding : RendererBinding {

observer.didChangeMetrics();
}
}
protected override void handleTextScaleFactorChanged() {
base.handleTextScaleFactorChanged();
foreach (WidgetsBindingObserver observer in this._observers) {
observer.didChangeTextScaleFactor();
}
}
void handleLocaleChanged() {
// todo
// dispatchLocaleChanged(window.locale);
protected virtual void handleLocaleChanged() {
this.dispatchLocalesChanged(Window.instance.locales);
}
protected virtual void dispatchLocalesChanged(List<Locale> locales) {
foreach (WidgetsBindingObserver observer in this._observers) {
observer.didChangeLocales(locales);
}
}
void _handleBuildScheduled() {

38
Runtime/widgets/framework.cs


public virtual void didUpdateWidget(StatefulWidget oldWidget) {
}
protected void setState(VoidCallback fn) {
D.assert(fn != null);
protected void setState(VoidCallback fn = null) {
D.assert(() => {
if (this._debugLifecycleState == _StateLifecycle.defunct) {
throw new UIWidgetsError(

return true;
});
fn();
if (fn != null) {
fn();
}
this._element.markNeedsBuild();
}

D.assert(this.widget != newWidget);
base.update(newWidget);
D.assert(this.widget == newWidget);
this.notifyClients(oldWidget);
this.updated(oldWidget);
protected virtual void updated(ProxyWidget oldWidget) {
this.notifyClients(oldWidget);
}
public abstract void notifyClients(ProxyWidget oldWidget);
protected abstract void notifyClients(ProxyWidget oldWidget);
}
public class ParentDataElement : ProxyElement {

this._applyParentData(newWidget);
}
public override void notifyClients(ProxyWidget oldWidget) {
protected override void notifyClients(ProxyWidget oldWidget) {
this._applyParentData(this.widget);
}
}

}
public void setDependencies(Element dependent, object value) {
object existing;
if (this._dependents.TryGetValue(dependent, out existing)) {
if (object.Equals(existing, value)) {
return;
}
}
this._dependents[dependent] = value;
}

public void notifyDependent(InheritedWidget oldWidget, Element dependent) {
dependent.didChangeDependencies();
}
protected override void updated(ProxyWidget oldWidget) {
if (this.widget.updateShouldNotify((InheritedWidget) oldWidget)) {
base.updated(oldWidget);
}
}
public override void notifyClients(ProxyWidget oldWidgetRaw) {
protected override void notifyClients(ProxyWidget oldWidgetRaw) {
if (!this.widget.updateShouldNotify(oldWidget)) {
return;
}
D.assert(this._debugCheckOwnerBuildTargetExists("notifyClients"));
foreach (Element dependent in this._dependents.Keys) {

3
Runtime/widgets/image.cs


public static ImageConfiguration createLocalImageConfiguration(BuildContext context, Size size = null) {
return new ImageConfiguration(
bundle: DefaultAssetBundle.of(context),
//TODO: add MediaQuery & Localizations.
//devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0,
devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0,
//locale: Localizations.localeOf(context, nullOk: true),
size: size,
platform: Application.platform

10
Runtime/widgets/widget_inspector.cs


return new Stack(children: children);
}
public void didChangeMetrics()
{
throw new NotImplementedException();
public void didChangeMetrics() {
}
public void didChangeTextScaleFactor() {
}
public void didChangeLocales(List<Locale> locale) {
}
private void _selectionChangedCallback()

2
Tests/Editor/MouseHover.cs


{
public class MouseHoverWidget:StatefulWidget
{
public MouseHoverWidget(Key key) : base(key)
public MouseHoverWidget(Key key = null) : base(key)
{
}

19
Tests/Editor/Widgets.cs


if (this._selected != selected) {
this._selected = selected;
this.windowAdapter.attachRootWidget(null);
this._attachRootWidget(null);
this.windowAdapter.attachRootWidget(rootWidget);
this._attachRootWidget(rootWidget);
this.windowAdapter.attachRootWidget(rootWidget);
this._attachRootWidget(rootWidget);
}
if (GUILayout.Button("UnloadUnusedAssets")) {

var rootWidget = this._options[this._selected]();
this.windowAdapter.attachRootWidget(rootWidget);
this._attachRootWidget(rootWidget);
}
void _attachRootWidget(Widget widget) {
this.windowAdapter.attachRootWidget(new WidgetsApp(window: this.windowAdapter, home: widget));
}
private void Update() {

}
Widget asPage() {
return new WidgetsApp(null, new AsScreen(), windowAdapter);
return new WidgetsApp(home: new AsScreen(), window: this.windowAdapter);
Widget mouseHover()
{
return new WidgetsApp(null, new MouseHoverWidget(null), windowAdapter);
Widget mouseHover() {
return new WidgetsApp(home: new MouseHoverWidget(), window: this.windowAdapter);
}
}

310
Runtime/widgets/media_query.cs


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

11
Runtime/widgets/media_query.cs.meta


fileFormatVersion: 2
guid: e578bc0c4f03f48ef88045315c000575
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存