internal YogaSize Measure(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { Debug.Assert(node == yogaNode, "YogaNode instance mismatch"); Vector2 size = DoMeasure(width, (MeasureMode)widthMode, height, (MeasureMode)heightMode); return(MeasureOutput.Make(Mathf.RoundToInt(size.x), Mathf.RoundToInt(size.y))); }
/// <summary> /// Measures the width and height of a <see cref="ProgressRing"/>. /// </summary> /// <param name="node">The css style of the rendered <see cref="ProgressRing"/>.</param> /// <param name="width">The parameterized native width of the control.</param> /// <param name="widthMode">The width measurement mode.</param> /// <param name="height">The parameterized native height of the control.</param> /// <param name="heightMode">The height measurement mode.</param> /// <returns>The measurement <see cref="MeasureOutput"/> for the <see cref="ProgressRing"/> component.</returns> private static YogaSize MeasureProgressRing(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var normalizedWidth = !YogaConstants.IsUndefined(width) ? width : 20f; var normalizedHeight = !YogaConstants.IsUndefined(height) ? height : 20f; return(MeasureOutput.Make(normalizedWidth, normalizedHeight)); }
public override YogaSize MeasureElement(YogaNode node, float width, YogaMeasureMode widthmode, float height, YogaMeasureMode heightmode) { var text = (Text)behaviour; if (string.IsNullOrWhiteSpace(text.text)) { return new YogaSize { width = 0, height = 0 } } ; var horizontalSettings = text.GetGenerationSettings(Vector2.zero); var textWidth = text.cachedTextGeneratorForLayout.GetPreferredWidth( text.text, horizontalSettings) / text.pixelsPerUnit; var resultWidth = widthmode != YogaMeasureMode.Undefined ? Mathf.Min(textWidth, width) : textWidth; var verticalSettings = text.GetGenerationSettings(new Vector2(resultWidth, 0)); var textHeight = text.cachedTextGeneratorForLayout.GetPreferredHeight( text.text, verticalSettings) / text.pixelsPerUnit; var resultHeight = heightmode != YogaMeasureMode.Undefined ? Mathf.Min(textHeight, height) : textHeight; return(new YogaSize { width = resultWidth, height = resultHeight }); } }
public override YogaSize MeasureElement(YogaNode node, float width, YogaMeasureMode widthmode, float height, YogaMeasureMode heightmode) { var layout = Layout; var component = (Component)layout; var measuredRectTransform = (RectTransform)component.transform; var originalSize = measuredRectTransform.sizeDelta; var size = originalSize; layout.CalculateLayoutInputHorizontal(); var preferredWidth = layout.preferredWidth; size.x = Mathf.Min(preferredWidth, width); measuredRectTransform.sizeDelta = size; layout.CalculateLayoutInputVertical(); var preferredHeight = layout.preferredHeight; size.y = Mathf.Min(preferredHeight, height); measuredRectTransform.sizeDelta = originalSize; return(new YogaSize { width = size.x, height = size.y }); }
private static YogaSize MeasureCanvas(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var adjustedHeight = YogaConstants.IsUndefined(height) ? 4f : height; var adjustedWidth = YogaConstants.IsUndefined(width) ? 4f : width; return(MeasureOutput.Make(adjustedWidth, adjustedHeight)); }
private static YogaSize _measure2(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { return(new YogaSize { Width = 279, Height = 126, }); }
private static YogaSize _measure1(YogaNode node, float?width, YogaMeasureMode widthMode, float?height, YogaMeasureMode heightMode) { return(new YogaSize { Width = 42, Height = 50, }); }
private static YogaSize MeasureSwitch(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { // TODO: figure out how to properly measure the switch. // We are currently blocked until we switch to a UWP-specific React // JavaScript library as the iOS library we currently use specifies // an exact width and height for switch nodes. return(MeasureOutput.Make(56f, 40f)); }
public void Clear() { AvailableWidth = 0; AvailableHeight = 0; WidthMeasureMode = (YogaMeasureMode)(-1); HeightMeasureMode = (YogaMeasureMode)(-1); ComputedWidth = -1; ComputedHeight = -1; }
public void CopyFrom(YogaCachedMeasurement other) { AvailableWidth = other.AvailableWidth; AvailableHeight = other.AvailableHeight; WidthMeasureMode = other.WidthMeasureMode; HeightMeasureMode = other.HeightMeasureMode; ComputedWidth = other.ComputedWidth; ComputedHeight = other.ComputedHeight; }
public YogaCachedMeasurement() { AvailableWidth = 0; AvailableHeight = 0; WidthMeasureMode = (YogaMeasureMode)(-1); HeightMeasureMode = (YogaMeasureMode)(-1); ComputedWidth = -1; ComputedHeight = -1; }
public static YogaSize MeasureInternal(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { bool flag = node == null || node._measureFunction == null; if (flag) { throw new InvalidOperationException("Measure function is not defined."); } return(node._measureFunction(node, width, widthMode, height, heightMode)); }
public YogaSize Measure(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var values = tmpro.GetPreferredValues(width, height); return(new YogaSize { width = Mathf.Ceil(values.x), height = Mathf.Ceil(values.y), }); }
private static YogaSize MeasureInternalAOT( IntPtr ygNodePtr, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var node = Native.YGNodeHandle.GetManaged(ygNodePtr); return(node.MeasureInternal(IntPtr.Zero, width, widthMode, height, heightMode)); }
private YogaSize SelfSize(YogaNode item, float width, YogaMeasureMode wmode, float height, YogaMeasureMode hmode) { if (item is Layout layout) { var measured = layout.view.Measure(new SKSize(width, height)); width = measured.Width; height = measured.Height; } return(new YogaSize() { width = width, height = height }); }
private YogaSize MeasureInternal( IntPtr node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { if (_measureFunction == null) { throw new InvalidOperationException("Measure function is not defined."); } return(_measureFunction(this, width, widthMode, height, heightMode)); }
private static YogaSize MeasureInternal( IntPtr unmanagedNodePtr, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var node = YGNodeHandle.GetManaged(unmanagedNodePtr); if (node == null || node._measureFunction == null) { throw new InvalidOperationException("Measure function is not defined."); } return(node._measureFunction(node, width, widthMode, height, heightMode)); }
private YogaSize MeasureInternal( IntPtr node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { if (_measureFunction == null) { throw new InvalidOperationException("Measure function is not defined."); } long output = _measureFunction(this, width, widthMode, height, heightMode); return(new YogaSize { width = MeasureOutput.GetWidth(output), height = MeasureOutput.GetHeight(output) }); }
static float SanitizeMeasurement(float constrainedSize, float measuredSize, YogaMeasureMode measureMode) { float result; if (measureMode == YogaMeasureMode.Exactly) { result = (float)constrainedSize; } else if (measureMode == YogaMeasureMode.AtMost) { result = (float)Math.Min(constrainedSize, measuredSize); } else { result = (float)measuredSize; } return(result); }
private static YogaSize MeasureText(ReactTextShadowNode textNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { Log.Info(ReactConstants.Tag, "MeasureText node=" + textNode.ReactTag); // This is not a terribly efficient way of projecting the height of // the text elements. It requires that we have access to the // dispatcher in order to do measurement, which, for obvious // reasons, can cause perceived performance issues as it will block // the UI thread from handling other work. // // TODO: determine another way to measure text elements. var task = DispatcherHelpers.CallOnDispatcher(() => { if (textView == null) { textView = new ReactTextView(ReactProgram.RctWindow); textView.LineWrapType = WrapType.Mixed; } var normalizedWidth = YogaConstants.IsUndefined(width) ? ReactProgram.RctWindow.ScreenSize.Width : width; var normalizedHeight = YogaConstants.IsUndefined(height) ? ReactProgram.RctWindow.ScreenSize.Height : height; textView.Resize((int)normalizedWidth, (int)normalizedHeight); textView.Text = textNode._preparedSpannableText; var textPartObject = textView.EdjeObject["elm.text"]; if (textPartObject == null) { throw new Exception("Invalid ReactTextView.EdjeObject[\"elm.text\"]"); } Size size = textPartObject.TextBlockFormattedSize; Log.Info(ReactConstants.Tag, "MeasureText result : width: " + size.Width + " height:" + size.Height); //textView.Unrealize(); return(MeasureOutput.Make( (float)size.Width, (float)size.Height)); }); return(task.Result); }
static YogaSize MeasureView(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var constrainedWidth = (widthMode == YogaMeasureMode.Undefined) ? float.MaxValue : width; var constrainedHeight = (heightMode == YogaMeasureMode.Undefined) ? float.MaxValue : height; NativeView view = null; if (YogaKit.Bridges.ContainsKey(node)) { view = YogaKit.Bridges[node] as NativeView; } float sizeThatFitsWidth = 0; float sizeThatFitsHeight = 0; MeasureNativeView(view, constrainedWidth, constrainedHeight, out sizeThatFitsWidth, out sizeThatFitsHeight); var finalWidth = SanitizeMeasurement(constrainedWidth, sizeThatFitsWidth, widthMode); var finalHeight = SanitizeMeasurement(constrainedHeight, sizeThatFitsHeight, heightMode); return(MeasureOutput.Make(finalWidth, finalHeight)); }
private YogaSize MeasureButton(ReactButtonShadowNode textNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { Log.Info(ReactConstants.Tag, "[1] MeasureButton node=" + textNode.ReactTag + " with=" + width + " height=" + height + " content=" + _preparedSpannableText); // This is not a terribly efficient way of projecting the height of // the text elements. It requires that we have access to the // dispatcher in order to do measurement, which, for obvious // reasons, can cause perceived performance issues as it will block // the UI thread from handling other work. // // TODO: determine another way to measure text elements. var task = DispatcherHelpers.CallOnDispatcher(() => { var btnView = new Button(ReactProgram.RctWindow); var normalizedWidth = YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width; var normalizedHeight = YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height; btnView.Resize((int)normalizedWidth, (int)normalizedHeight); btnView.Text = _preparedSpannableText; var btnPartObject = btnView.EdjeObject["elm.text"]; if (btnPartObject == null) { throw new Exception("Invalid Button.EdjeObject[\"elm.text\"]"); } Size size = btnPartObject.TextBlockFormattedSize; Log.Info(ReactConstants.Tag, "[2] EDC conf info ={ width: " + size.Width + " height:" + size.Height + "}"); btnView.Unrealize(); return(MeasureOutput.Make( (float)(size.Width + 80), (float)(size.Height < 80 ? 80 : size.Height))); }); return(task.Result); }
private static YogaSize MeasureText(ReactTextShadowNode textNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { // TODO: Measure text with DirectWrite or other API that does not // require dispatcher access. Currently, we're instantiating a // second CoreApplicationView (that is never activated) and using // its Dispatcher thread to calculate layout. var textBlock = new TextBlock { TextAlignment = TextAlignment.Left, TextWrapping = TextWrapping.Wrap, TextTrimming = TextTrimming.CharacterEllipsis, }; textNode.UpdateTextBlockCore(textBlock, true); for (var i = 0; i < textNode.ChildCount; ++i) { var child = textNode.GetChildAt(i); textBlock.Inlines.Add(ReactInlineShadowNodeVisitor.Apply(child)); } var normalizedWidth = YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width; var normalizedHeight = YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height; textBlock.Measure(new Size(normalizedWidth, normalizedHeight)); return(MeasureOutput.Make( (float)Math.Ceiling(textBlock.DesiredSize.Width), (float)Math.Ceiling(textBlock.DesiredSize.Height))); }
private static YogaSize MeasureTextInput(ReactTextInputShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var normalizedWidth = Math.Max(0, (YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width)); var normalizedHeight = Math.Max(0, (YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height)); var normalizedText = string.IsNullOrEmpty(textInputNode._text) ? " " : textInputNode._text; var textBlock = new TextBlock { Text = normalizedText, TextWrapping = textInputNode._multiline ? TextWrapping.Wrap : TextWrapping.NoWrap, }; ApplyStyles(textInputNode, textBlock); textBlock.Measure(new Size(normalizedWidth, normalizedHeight)); return(MeasureOutput.Make( (float)Math.Ceiling(width), (float)Math.Ceiling(textBlock.ActualHeight))); }
unsafe public static void YGNodeMeasureInvoke(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode, IntPtr returnValueAddress) { (*(YogaSize *)returnValueAddress) = YogaNode.MeasureInternal(node, width, widthMode, height, heightMode); }
private static YogaSize MeasurePicker(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { return(MeasureOutput.Make(width, 40f)); }
private static YogaSize MeasureProgressBar(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var adjustedHeight = YogaConstants.IsUndefined(height) ? 4f : height; return(MeasureOutput.Make(width, adjustedHeight)); }
private static YogaSize MeasureTextInput(ReactTextInputShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { textInputNode._computedPadding = textInputNode.GetComputedPadding(); var borderLeftWidth = textInputNode.GetBorder(YogaEdge.Left); var borderRightWidth = textInputNode.GetBorder(YogaEdge.Right); var normalizedWidth = Math.Max(0, (YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width) - textInputNode._computedPadding[0] - textInputNode._computedPadding[2] - (YogaConstants.IsUndefined(borderLeftWidth) ? 0 : borderLeftWidth) - (YogaConstants.IsUndefined(borderRightWidth) ? 0 : borderRightWidth)); var normalizedHeight = Math.Max(0, YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height); var textBlock = new TextBlock { TextWrapping = TextWrapping.Wrap, }; var normalizedText = string.IsNullOrEmpty(textInputNode._text) ? " " : textInputNode._text; var inline = new Run { Text = normalizedText }; FormatInline(textInputNode, inline); textBlock.Inlines.Add(inline); textBlock.Measure(new Size(normalizedWidth, normalizedHeight)); var borderTopWidth = textInputNode.GetBorder(YogaEdge.Top); var borderBottomWidth = textInputNode.GetBorder(YogaEdge.Bottom); var finalizedHeight = (float)textBlock.DesiredSize.Height; finalizedHeight += textInputNode._computedPadding[1]; finalizedHeight += textInputNode._computedPadding[3]; finalizedHeight += YogaConstants.IsUndefined(borderTopWidth) ? 0 : borderTopWidth; finalizedHeight += YogaConstants.IsUndefined(borderBottomWidth) ? 0 : borderBottomWidth; return(MeasureOutput.Make( (float)Math.Ceiling(width), (float)Math.Ceiling(finalizedHeight))); }
private static YogaSize MeasurePasswordBox(ReactPasswordBoxShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { var normalizedWidth = Math.Max(0, (YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width)); var normalizedHeight = Math.Max(0, (YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height)); var passwordChar = GetDefaultPasswordChar(); var normalizedText = !string.IsNullOrEmpty(textInputNode._text) ? new string(passwordChar[0], textInputNode._text.Length) : passwordChar; var textBlock = new TextBlock { Text = normalizedText, }; ApplyStyles(textInputNode, textBlock); textBlock.Measure(new Size(normalizedWidth, normalizedHeight)); return(MeasureOutput.Make( (float)Math.Ceiling(width), (float)Math.Ceiling(textBlock.ActualHeight))); }
private static YogaSize MeasureText(ReactTextShadowNode textNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { // This is not a terribly efficient way of projecting the height of // the text elements. It requires that we have access to the // dispatcher in order to do measurement, which, for obvious // reasons, can cause perceived performance issues as it will block // the UI thread from handling other work. // // TODO: determine another way to measure text elements. var task = DispatcherHelpers.CallOnDispatcher(() => { var textBlock = new RichTextBlock { TextWrapping = TextWrapping.Wrap, TextAlignment = TextAlignment.DetectFromContent, TextTrimming = TextTrimming.CharacterEllipsis, }; textNode.UpdateTextBlockCore(textBlock, true); var block = new Paragraph(); for (var i = 0; i < textNode.ChildCount; ++i) { var child = textNode.GetChildAt(i); block.Inlines.Add(ReactInlineShadowNodeVisitor.Apply(child)); } textBlock.Blocks.Add(block); var normalizedWidth = YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width; var normalizedHeight = YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height; textBlock.Measure(new Size(normalizedWidth, normalizedHeight)); return(MeasureOutput.Make( (float)Math.Ceiling(textBlock.DesiredSize.Width), (float)Math.Ceiling(textBlock.DesiredSize.Height))); }); return(task.Result); }