public override void measure(Point inOffset) { base.measure(inOffset); // As we did in draw(), we must make sure to calculate all // Children as if they were one below the other Measure = new SUIMeasure(Margin.TotalWidth, Margin.TotalWidth); Point currentOffset = new Point(inOffset.X + Margin.Left, inOffset.Y + Margin.Top); foreach (var child in Children) { child.measure(currentOffset); switch (Style.Orientation) { default: case SUIStyle.STYLE_ORIENTATION.VERTICAL: currentOffset.Y = currentOffset.Y + child.getMeasuredHeight(); Measure.Height = Measure.Height + child.getMeasuredHeight(); Measure.Width = Math.Max(Measure.Width, child.getMeasuredWidth() + Margin.TotalWidth); break; case SUIStyle.STYLE_ORIENTATION.HORIZONTAL: currentOffset.X = currentOffset.X + child.getMeasuredWidth(); Measure.Width = Measure.Width + child.getMeasuredWidth(); Measure.Height = Math.Max(Measure.Height, child.getMeasuredHeight() + Margin.TotalHeight); break; } } }
public override void measure(Point inOffset) { base.measure(inOffset); // For the button, let's assume a fixed measure, ignoring // the content Measure = new SUIMeasure(BUTTON_WIDTH, BUTTON_HEIGHT); }
public override void measure(Point inOffset) { base.measure(inOffset); // How you measure your text is up to you really. // If you are rendering each character as a single // sprite, obviously the text will be the size // of all those sprites combined. // Here we use a method from StackOverflow (https://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters) // for our TextBlock-Cheat TextBlock lblText = new TextBlock(); // Declared as in the draw method to find out it's font, etc. var formattedText = new FormattedText( LabelText, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(lblText.FontFamily, lblText.FontStyle, lblText.FontWeight, lblText.FontStretch), lblText.FontSize, Brushes.Black); Measure = new SUIMeasure(formattedText.Width, formattedText.Height); }
public virtual void measure(Point inOffset) { AbsolutePosition = new Point(inOffset.X + Margin.Left, inOffset.Y + Margin.Top); Measure = new SUIMeasure(Margin.TotalWidth, Margin.TotalHeight); }
public SUIElement(object inContent) { Children = new List <SUIElement>(); Margin = new SUIMargin(0, 0, 0, 0); Measure = new SUIMeasure(0, 0); }