/// <summary> /// Устанавливает способ выравнивания текста. /// </summary> public void SetHorizontalTextAlignment(HorizontalTextAlignment value) { if (_horizontalTextAlignment != value) { _horizontalTextAlignment = value; switch (value) { case HorizontalTextAlignment.Left: Control.TextAlignment = TextAlignment.Left; break; case HorizontalTextAlignment.Right: Control.TextAlignment = TextAlignment.Right; break; case HorizontalTextAlignment.Center: Control.TextAlignment = TextAlignment.Center; break; case HorizontalTextAlignment.Justify: Control.TextAlignment = TextAlignment.Justify; break; default: Control.TextAlignment = TextAlignment.Left; break; } } }
public TextAlignment(HorizontalTextAlignment horizontal, VerticalTextAlignment vertical, double horizontalContinuousAlignment, double verticalContinuousAlignment) : base(5, 18) { Horizontal = horizontal; Vertical = vertical; HorizontalContinuousAlignment = horizontalContinuousAlignment; VerticalContinuousAlignment = verticalContinuousAlignment; }
public TextDescriptor(string text = "CraftLie", string fontName = "Arial", float fontSize = 32, float extrude = 0, HorizontalTextAlignment textAlignment = HorizontalTextAlignment.Center, VerticalTextAlignment paragraphAlignment = VerticalTextAlignment.Center) : base(PrimitiveType.Text) { Text = text; FontName = fontName; FontSize = fontSize; Extrude = extrude; TextAlignment = textAlignment; ParagraphAlignment = paragraphAlignment; }
/// <summary> /// Get template of each attribute type /// it is used in TextRangeFindDialog. /// </summary> /// <returns></returns> public static IList <TemplateData> GetTemplate() { var boolList = new List <KeyValuePair <bool, string> >() { new KeyValuePair <bool, string>(false, "False"), new KeyValuePair <bool, string>(true, "True") }; return(new List <TemplateData> { CreateTemplateData <int>(UIA_AnimationStyleAttributeId, AnimationStyle.GetInstance()), CreateTemplateData <int>(UIA_BackgroundColorAttributeId), CreateTemplateData <int>(UIA_BulletStyleAttributeId, BulletStyle.GetInstance()), CreateTemplateData <int>(UIA_CapStyleAttributeId, CapStyle.GetInstance()), CreateTemplateData <int>(UIA_CultureAttributeId, CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures).Select(c => new KeyValuePair <int, string>(c.LCID, c.EnglishName)).ToList()), CreateTemplateData <string>(UIA_FontNameAttributeId), CreateTemplateData <double>(UIA_FontSizeAttributeId), CreateTemplateData <int>(UIA_FontWeightAttributeId, FontWeight.GetInstance()), CreateTemplateData <int>(UIA_ForegroundColorAttributeId), CreateTemplateData <int>(UIA_HorizontalTextAlignmentAttributeId, HorizontalTextAlignment.GetInstance()), CreateTemplateData <int>(UIA_IndentationFirstLineAttributeId), CreateTemplateData <int>(UIA_IndentationLeadingAttributeId), CreateTemplateData <int>(UIA_IndentationTrailingAttributeId), CreateTemplateData <bool>(UIA_IsHiddenAttributeId, boolList), CreateTemplateData <bool>(UIA_IsItalicAttributeId, boolList), CreateTemplateData <bool>(UIA_IsReadOnlyAttributeId, boolList), CreateTemplateData <bool>(UIA_IsSubscriptAttributeId, boolList), CreateTemplateData <bool>(UIA_IsSuperscriptAttributeId, boolList), CreateTemplateData <int>(UIA_MarginBottomAttributeId), CreateTemplateData <int>(UIA_MarginLeadingAttributeId), CreateTemplateData <int>(UIA_MarginTopAttributeId), CreateTemplateData <int>(UIA_MarginTrailingAttributeId), CreateTemplateData <int>(UIA_OutlineStylesAttributeId, OutlineStyle.GetInstance()), CreateTemplateData <int>(UIA_OverlineColorAttributeId), CreateTemplateData <int>(UIA_OverlineStyleAttributeId, TextDecorationLineStyle.GetInstance()), CreateTemplateData <int>(UIA_StrikethroughColorAttributeId), CreateTemplateData <int>(UIA_StrikethroughStyleAttributeId, TextDecorationLineStyle.GetInstance()), CreateTemplateData <int>(UIA_TabsAttributeId), CreateTemplateData <int>(UIA_TextFlowDirectionsAttributeId, FlowDirection.GetInstance()), CreateTemplateData <int>(UIA_UnderlineColorAttributeId), CreateTemplateData <int>(UIA_UnderlineStyleAttributeId, TextDecorationLineStyle.GetInstance()), CreateTemplateData <int>(UIA_AnnotationTypesAttributeId, AnnotationType.GetInstance()), //CreateTemplateData<int>(UIA_AnnotationObjectsAttributeId, AnimationStyles.GetInstance()), CreateTemplateData <string>(UIA_StyleNameAttributeId), CreateTemplateData <int>(UIA_StyleIdAttributeId, StyleId.GetInstance()), //CreateTemplateData<int>(UIA_LinkAttributeId, AnimationStyles.GetInstance()), CreateTemplateData <bool>(UIA_IsActiveAttributeId, boolList), CreateTemplateData <int>(UIA_SelectionActiveEndAttributeId, ActiveEnd.GetInstance()), CreateTemplateData <int>(UIA_CaretPositionAttributeId, CaretPosition.GetInstance()), CreateTemplateData <int>(UIA_CaretBidiModeAttributeId, CaretBidiMode.GetInstance()), CreateTemplateData <string>(UIA_LineSpacingAttributeId), CreateTemplateData <double>(UIA_BeforeParagraphSpacingAttributeId), CreateTemplateData <double>(UIA_AfterParagraphSpacingAttributeId), CreateTemplateData <int>(UIA_SayAsInterpretAsAttributeId, SayAsInterpretAs.GetInstance()), }); }
private static void SetVerticalAlignment(SerializedProperty alignment, VerticalTextAlignment verticalAlignment) { foreach (var obj in alignment.serializedObject.targetObjects) { Text text = obj as Text; HorizontalTextAlignment currentHorizontalAlignment = GetHorizontalAlignment(text.alignment); Undo.RecordObject(text, "Vertical Alignment"); text.alignment = GetAnchor(verticalAlignment, currentHorizontalAlignment); EditorUtility.SetDirty(obj); } }
/// <summary> /// Set Internal Text Display Settings /// </summary> /// <param name="value"></param> /// <param name="bold"></param> /// <param name="italic"></param> /// <param name="size"></param> /// <param name="fontFamilyName"></param> /// <param name="location"></param> /// <param name="alignment"></param> /// <param name="rotation"></param> internal void InternalSetTextSettings(string value, bool bold, bool italic, double size, string fontFamilyName, DS.Point location, HorizontalTextAlignment alignment, double rotation) { this.Value = value; this.Bold = bold; this.Italic = italic; this.FontSize = size; this.FontFamilyName = fontFamilyName; this.Location = location; this.Alignment = alignment; this.Rotation = rotation; }
public TextItem CreateTextItemFor( Player player, string text, Vector2 position, float scale = 1, Color?color = null, byte shadowAlpha = 0, HorizontalTextAlignment horizontalAlignment = HorizontalTextAlignment.Left, VerticalTextAlignment verticalAlignment = VerticalTextAlignment.Top ) { return(this.CreateTextItemFor(new Player[] { player }, text, position, scale, color, shadowAlpha, horizontalAlignment, verticalAlignment)); }
private static void DoHorizontalAligmentControl(Rect position, SerializedProperty alignment) { TextAnchor ta = (TextAnchor)alignment.intValue; HorizontalTextAlignment horizontalAlignment = GetHorizontalAlignment(ta); bool leftAlign = (horizontalAlignment == HorizontalTextAlignment.Left); bool centerAlign = (horizontalAlignment == HorizontalTextAlignment.Center); bool rightAlign = (horizontalAlignment == HorizontalTextAlignment.Right); if (alignment.hasMultipleDifferentValues) { foreach (var obj in alignment.serializedObject.targetObjects) { Text text = obj as Text; horizontalAlignment = GetHorizontalAlignment(text.alignment); leftAlign = leftAlign || (horizontalAlignment == HorizontalTextAlignment.Left); centerAlign = centerAlign || (horizontalAlignment == HorizontalTextAlignment.Center); rightAlign = rightAlign || (horizontalAlignment == HorizontalTextAlignment.Right); } } position.width = kAlignmentButtonWidth; EditorGUI.BeginChangeCheck(); EditorToggle(position, leftAlign, leftAlign ? Styles.m_LeftAlignTextActive : Styles.m_LeftAlignText, Styles.alignmentButtonLeft); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAlignment.Left); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, centerAlign, centerAlign ? Styles.m_CenterAlignTextActive : Styles.m_CenterAlignText, Styles.alignmentButtonMid); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAlignment.Center); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, rightAlign, rightAlign ? Styles.m_RightAlignTextActive : Styles.m_RightAlignText, Styles.alignmentButtonRight); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAlignment.Right); } }
public TestCase( TickBarPlacement placement, bool isDirectionReversed, HorizontalTextAlignment horizontalTextAlignment, VerticalTextAlignment verticalTextAlignment, double tickFrequency, DoubleCollection ticks, Thickness padding) { this.Placement = placement; this.IsDirectionReversed = isDirectionReversed; this.TickFrequency = tickFrequency; this.Ticks = ticks; this.Padding = padding; this.HorizontalTextAlignment = horizontalTextAlignment; this.VerticalTextAlignment = verticalTextAlignment; }
public TextItem CreateTextItemFor( IEnumerable <Player> players, string text, Vector2 position, float scale = 1, Color?color = null, byte shadowAlpha = 0, HorizontalTextAlignment horizontalAlignment = HorizontalTextAlignment.Left, VerticalTextAlignment verticalAlignment = VerticalTextAlignment.Top ) { var textItem = new TextItem(++this.textItemId); byte format = (byte)(((byte)horizontalAlignment) | ((byte)verticalAlignment)); var packet = new TextItemPacket(textItem.Id, position, text, scale, color, format, shadowAlpha); packet.SendTo(players); return(textItem); }
public DrawTextDescription(Matrix transformation, Color4 color, BlendMode blendMode = BlendMode.TextDefault, string text = "CraftLie", float size = 12, string fontName = "Arial", FontWeight weight = FontWeight.Normal, FontStyle style = FontStyle.Normal, HorizontalTextAlignment horizontalAlignment = HorizontalTextAlignment.Left, VerticalTextAlignment verticalAlignment = VerticalTextAlignment.Top, float textWidth = 100) { Transformation = transformation; Color = color; Blending = blendMode; Text = text; Size = size; FontName = fontName; Weight = weight; Style = style; HorizontalAlignment = horizontalAlignment; VerticalAlignment = verticalAlignment; TextWidth = textWidth; }
/// <summary> /// Uworzenie zawartości wiersza na podstawie tablicy pól i szerokości kolumn /// </summary> /// <param name="values">Tablica pól wiersza, pola wylądują w kolumnach</param> /// <param name="columnsWidths">Szerokości kolumn do których powędrują pola</param> /// <param name="horizontalTextAlignment">Sposób wyrównania tekstu w poziomie, domyślnie jest do lewej</param> /// <returns>Zawartość wiersza</returns> public static string GetRow(string[] values, int[] columnsWidths, HorizontalTextAlignment horizontalTextAlignment = HorizontalTextAlignment.Left) { string fieldContent; //Tutaj będzie tymczasowo porzechowywana zawartość danego pola wiersza int fieldContentWidth; //Tutaj będzie tymaczasowo przechowywana szerokość zawartości kolumny w której będzie pole StringBuilder rowContent = new StringBuilder("|"); //Utworzenie wstępnej zawartości wiersza, lewa krawędź wiersza. values.ForEach((x, index) => //Przejście po wszystkich polach { fieldContentWidth = columnsWidths[index]; //Ustawienie szerokości zawartości danego pola fieldContent = horizontalTextAlignment == HorizontalTextAlignment.Left ? x.PadRight(fieldContentWidth) : horizontalTextAlignment == HorizontalTextAlignment.Right ? x.PadLeft(fieldContentWidth) : x.PadBoth(fieldContentWidth); //Wybranie odpowiedniej techniki zapełniania wolnego miejsca spacjami w zależności od wybranego sposobu wyrównania tekstu rowContent.AppendFormat(" {0} |", fieldContent); //Dodanie do zawartości wiersza zawartość pola, oddzielenie spacją od lewej krawędzi i od prawej oraz dodanie prawej krawędzi pola /* * Zostaje pobrana szerokość zawartości kolumny do której powędruje pole. Jeśli pole ma mniejszą długość od zawartości kolumny, to z prawej strony zostaną dodane spacje, by * każda kolumna i wiersz miały takie same szerokości */ }); return(rowContent.ToString()); //Zwrócenie zawartości wiersza }
private void setCell(int col, int row, object content, int colSpan, int rowSpan, bool noWrap, HorizontalTextAlignment? alignment, ConsoleColor? background = null) { if (col < 0) throw new ArgumentOutOfRangeException("col", col, @"""col"" cannot be negative."); if (row < 0) throw new ArgumentOutOfRangeException("row", row, @"""row"" cannot be negative."); if (colSpan < 1) throw new ArgumentOutOfRangeException("colSpan", colSpan, @"""colSpan"" cannot be less than 1."); if (rowSpan < 1) throw new ArgumentOutOfRangeException("rowSpan", rowSpan, @"""rowSpan"" cannot be less than 1."); if (content == null) throw new ArgumentNullException("content"); // Complain if setting this cell would overlap with another cell due to its colspan or rowspan if (row >= _cells.Count || col >= _cells[row].Count || _cells[row][col] == null || _cells[row][col] is surrogateCell) { for (int x = 0; x < colSpan; x++) for (int y = 0; y < rowSpan; y++) if (row + y < _cells.Count && col + x < _cells[row + y].Count && _cells[row + y][col + x] is surrogateCell) { var sur = (surrogateCell) _cells[row][col]; var real = (trueCell) _cells[sur.RealRow][sur.RealCol]; throw new InvalidOperationException(@"The cell at column {0}, row {1} is already occupied because the cell at column {2}, row {3} has colspan {4} and rowspan {5}.".Fmt(col, row, sur.RealCol, sur.RealRow, real.ColSpan, real.RowSpan)); } } ensureCell(col, row); // If the cell contains a true cell, remove it with all its surrogates if (_cells[row][col] is trueCell) { var tr = (trueCell) _cells[row][col]; for (int x = 0; x < tr.ColSpan; x++) for (int y = 0; y < tr.RowSpan; y++) _cells[row + y][col + x] = null; } // Insert the cell in the right place _cells[row][col] = new trueCell { ColSpan = colSpan, RowSpan = rowSpan, Value = content, NoWrap = noWrap, Alignment = alignment, Background = background }; // For cells with span, insert the appropriate surrogate cells. for (int x = 0; x < colSpan; x++) for (int y = x == 0 ? 1 : 0; y < rowSpan; y++) { ensureCell(col + x, row + y); _cells[row + y][col + x] = new surrogateCell { RealCol = col, RealRow = row }; } }
public ExplicitLinearTextPosition(HorizontalTextAlignment horizontal, VerticalTextAlignment vertical) { this.Horizontal = horizontal; this.Vertical = vertical; }
public static void WriteDataTable(DataTable dt, HorizontalTextAlignment horizontalTextAlignment = HorizontalTextAlignment.Left) { List <string[]> rowsFields = dt.GetColumnsAndRowsStringArray().ToList(); WriteTableFromFields(rowsFields, true, horizontalTextAlignment); }
public void Text(Context context, string txt, HorizontalTextAlignment horizontal = HorizontalTextAlignment.Center, VerticalTextAlignment vertical = VerticalTextAlignment.Middle) { context.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Normal); //context.SetFontSize (_surface.Height / 10); context.SetFontSize (14); var extends = context.TextExtents (txt); double x, y; x = -(((double)horizontal) / 2 * extends.Width + extends.XBearing); y = -(((double)vertical) / 2 * extends.Height + extends.YBearing); context.RelMoveTo (x, y); context.ShowText (txt); }
public static List <TextLine> GetLines(string inText, GUIBase_FontEx inFont, HorizontalTextAlignment inAlignment, float inMaxlineWidth, Vector3 inScale, float inLineSpacePct, bool isForTextField = false) { if (string.IsNullOrEmpty(inText) == true) { return(null); } if (inMaxlineWidth <= 0.0f) { return(null); } if (inScale == Vector3.zero) { return(null); } List <TextLine> lines = new List <TextLine>(); TextLine newLine = null; int lastSpaceIndex = -1; float widthAtLastSpace = 0; float widthOfSpace = inFont.GetCharWidth((int)' ') * inScale.x; float charWidth = 0; float fontHeight = inFont.GetFontHeight(); for (int i = 0; i < inText.Length; ++i) { if (newLine == null) { newLine = new TextLine(); newLine.m_StartIndex = i; newLine.m_SpaceWidth = widthOfSpace; lastSpaceIndex = -1; widthAtLastSpace = 0; } int character = (int)inText[i]; if (!isForTextField && character == ' ') { lastSpaceIndex = i; widthAtLastSpace = newLine.m_Size.x; newLine.m_Size.x += widthOfSpace; newLine.m_NumOfSpaces++; continue; } switch (character) { case '\n': newLine.m_EndIndex = i; newLine.m_EndOfParagraph = true; lines.Add(newLine); newLine = null; break; default: charWidth = inFont.GetCharWidth(character) * inScale.x; if (newLine.m_Size.x + charWidth > inMaxlineWidth) { if (lastSpaceIndex >= 0) { newLine.m_NumOfSpaces--; newLine.m_Size.x = widthAtLastSpace; newLine.m_EndIndex = lastSpaceIndex; i = lastSpaceIndex; } else { newLine.m_EndIndex = i; i = i - 1; } newLine.m_EndOfParagraph = false; if ((newLine.m_EndIndex - newLine.m_StartIndex) < 1) { //this line is invalid. It looks that actual character is too width for inMaxlineWidth // skip it. Debug.LogWarning("Can't generate line for character: " + (char)character); } else { lines.Add(newLine); } newLine = null; } else { newLine.m_Size.x += charWidth; } break; } } if (newLine != null) { newLine.m_EndIndex = inText.Length; newLine.m_EndOfParagraph = true; if ((newLine.m_EndIndex - newLine.m_StartIndex) == 0) { Debug.LogWarning("Empty line"); } else { lines.Add(newLine); } } float yOffset = 0; // Compute x offset of lines by TextAlignment. foreach (TextLine line in lines) { #if !MADFINGER_KEYBOARD_MOUSE // remove spaces from start and end of line... TrimSpaces(inText, line, widthOfSpace); #endif // Check line validity... if ((line.m_EndIndex - line.m_StartIndex) == 0) { //Debug.LogWarning("Empty line"); continue; } // setup line x offset based on TextAlignment... float span = (inMaxlineWidth - line.m_Size.x); switch (inAlignment) { case HorizontalTextAlignment.Left: line.m_Offset.x = 0.0f; break; case HorizontalTextAlignment.Center: line.m_Offset.x = span * 0.5f; break; case HorizontalTextAlignment.Right: line.m_Offset.x = span; break; case HorizontalTextAlignment.Justify: if (line.m_EndOfParagraph == false && line.m_NumOfSpaces > 0) { line.m_SpaceWidth += span / (float)line.m_NumOfSpaces; } break; default: Debug.LogError("Unknown Horizontal text alignment !!!! " + inAlignment); break; } yOffset += 0.5f * fontHeight * inScale.y; line.m_Offset.y = yOffset; yOffset += 0.5f * fontHeight * inScale.y; yOffset += inLineSpacePct * fontHeight * inScale.y; } return(lines); }
private void AddTextAttribute(CG.List <Atk.Attribute> attrs, Atk.TextAttribute atkAttr, ITextRangeProvider textRange) { if (textRange == null) { return; } string name = Atk.TextAdapter.AttributeGetName(atkAttr); string val = null; object tmp; switch (atkAttr) { case Atk.TextAttribute.Style: if (IsAttrNotNullOrMultiValued(TextPattern.IsItalicAttribute.Id, textRange, out tmp)) { val = ((bool)tmp) ? "italic" : "normal"; } break; case Atk.TextAttribute.Justification: if (!IsAttrNotNullOrMultiValued(TextPattern.HorizontalTextAlignmentAttribute.Id, textRange, out tmp)) { break; } HorizontalTextAlignment align = (HorizontalTextAlignment)tmp; if (align == HorizontalTextAlignment.Left) { val = "left"; } else if (align == HorizontalTextAlignment.Right) { val = "right"; } else if (align == HorizontalTextAlignment.Centered) { val = "center"; } else if (align == HorizontalTextAlignment.Justified) { val = "fill"; } break; case Atk.TextAttribute.FgColor: if (IsAttrNotNullOrMultiValued(TextPattern.ForegroundColorAttribute.Id, textRange, out tmp)) { Color fgColor = Color.FromArgb((int)tmp); val = String.Format("{0},{1},{2}", fgColor.R, fgColor.G, fgColor.B); } break; case Atk.TextAttribute.BgColor: if (IsAttrNotNullOrMultiValued(TextPattern.BackgroundColorAttribute.Id, textRange, out tmp)) { Color fgColor = Color.FromArgb((int)tmp); val = String.Format("{0},{1},{2}", fgColor.R, fgColor.G, fgColor.B); } break; case Atk.TextAttribute.FamilyName: if (IsAttrNotNullOrMultiValued(TextPattern.FontNameAttribute.Id, textRange, out tmp)) { val = (string)tmp; } break; case Atk.TextAttribute.Weight: if (IsAttrNotNullOrMultiValued(TextPattern.FontWeightAttribute.Id, textRange, out tmp)) { val = ((int)tmp).ToString(); } break; case Atk.TextAttribute.Strikethrough: if (IsAttrNotNullOrMultiValued(TextPattern.StrikethroughStyleAttribute.Id, textRange, out tmp)) { TextDecorationLineStyle strikeStyle = (TextDecorationLineStyle)tmp; val = strikeStyle == TextDecorationLineStyle.None ? "false" : "true"; } break; case Atk.TextAttribute.Underline: if (!IsAttrNotNullOrMultiValued(TextPattern.UnderlineStyleAttribute.Id, textRange, out tmp)) { break; } TextDecorationLineStyle underlineStyle = (TextDecorationLineStyle)tmp; if (underlineStyle == TextDecorationLineStyle.None) { val = "none"; } else if (underlineStyle == TextDecorationLineStyle.Double || underlineStyle == TextDecorationLineStyle.DoubleWavy) { val = "double"; } else { val = "single"; } break; case Atk.TextAttribute.PixelsBelowLines: if (IsAttrNotNullOrMultiValued(TextPattern.IndentationTrailingAttribute.Id, textRange, out tmp)) { val = ((int)tmp).ToString(); } break; case Atk.TextAttribute.PixelsAboveLines: if (IsAttrNotNullOrMultiValued(TextPattern.IndentationLeadingAttribute.Id, textRange, out tmp)) { val = ((int)tmp).ToString(); } break; case Atk.TextAttribute.Editable: if (IsAttrNotNullOrMultiValued(TextPattern.IsReadOnlyAttribute.Id, textRange, out tmp)) { val = !((bool)tmp) ? "true" : "false"; } break; case Atk.TextAttribute.Invisible: if (IsAttrNotNullOrMultiValued(TextPattern.IsHiddenAttribute.Id, textRange, out tmp)) { val = ((bool)tmp) ? "true" : "false"; } break; case Atk.TextAttribute.Indent: if (IsAttrNotNullOrMultiValued(TextPattern.IndentationFirstLineAttribute.Id, textRange, out tmp)) { val = ((int)tmp).ToString(); } break; } if (val != null) { attrs.Add(new Atk.Attribute { Name = name, Value = val }); } }
///<summary> ///Draws text at a location in the 2d gui coordinates. ///</summary> ///<param name="font"> ///The font to draw with, usually specified by a GUIStyle. ///</param> ///<param name="offset"> ///Point where to start drawing the text. ///</param> ///<param name="size"> ///Margins used to calculate the text alignment. ///</param> ///<param name="horizontalAlignment"> ///Horizontal justification of the text relative to the offset. ///</param> ///<param name="color">The color to draw the text as.</param> ///<param name="text">The string to be drawn.</param> public static void JustifiedText( Resource<SpriteFont> font, Vector2 offset, Vector2 size, HorizontalTextAlignment horizontalAlignment, Color color, string text) { DrawUtil.JustifiedText( font, offset, size, horizontalAlignment, color, text); }
/// <summary> /// Wyświetlenie kolekcji pól wierszy w formie tabeli z nagłówkiem lub bez /// </summary> /// <param name="rowsFields">Kolekcja pól wierszów</param> /// <param name="hasHeader">Czy ma nagłówek. Jeśli tak, to zostanie wyróżniony ramką</param> /// <param name="horizontalTextAlignment">Sposób wyrównania tekstu w poziomie, domyślnie jest do lewej</param> public static void WriteTableFromFields(IList <string[]> rowsFields, bool hasHeader = true, HorizontalTextAlignment horizontalTextAlignment = HorizontalTextAlignment.Left) { if (rowsFields.IsEmpty()) //Czy kolekcja pól wierszy zawiera jakiekolwiek elementy { WriteLine(); //Wyświetlenie pustej linii return; //Wyjście z metody } string[] firstRowFields = rowsFields[0]; //Pobranie pól pierwszego elementu kolekcji int[] columnsWidths = StringUtils.GetColumnsWidths(rowsFields); //Pobranie szerokości zawartości kolumn na podstawie kolekcji pól wierszy WriteRowDelimiter(columnsWidths); //Wyświetlenie górnej krawędzi tabeli na o określonej szerokości, na podstawie obliczonych szerokości kolumn string firstRow = GetRow(firstRowFields, columnsWidths, horizontalTextAlignment); //Pobranie pól z pierwszego elementu kolekcji i na tej podstawie utworzenie zawartości wiersza biorąc pod uwagę maksymalną szerokość kolumn if (hasHeader) //Czy tabela ma posiadać nagłówek { WriteHeader(firstRow, columnsWidths); //Wyświetlenie nagłówka tabeli na podstawie zawartości pierwszego wiersza tabeli biorąc pod uwagę szerokości kolumn, pod nagłówkiemzostanie dodana krawędź } else { WriteRow(firstRow); //Wyświetlenie pierwszego wiersza tabeli } WriteRows(rowsFields, columnsWidths, horizontalTextAlignment); //Wyświetlenie pozostałych wierszy na podstawie kolekcji pól wierszy biorąc pod uwagę szerokość kolumn }
/// <summary> /// Wyświetlenie kolekcji obiektów w formie tabeli z nagłówkiem lub bez /// </summary> /// <typeparam name="T">Typ obiektu, który ma zostać przetworzony na dany wiersz tabeli. Musi być to typ referencyjny, czyli klasa</typeparam> /// <param name="collection">Kolekcja obiektów do przetworzenia</param> /// <param name="hasHeader">Czy ma nagłówek. Jeśli tak, to zostanie wyróżniony ramką</param> /// <param name="horizontalTextAlignment">Sposób wyrównania tekstu w poziomie, domyślnie jest do lewej</param> public static void WriteTableFromObjects <T>(IEnumerable <T> collection, bool hasHeader = true, HorizontalTextAlignment horizontalTextAlignment = HorizontalTextAlignment.Left) where T : class { List <string[]> rowsFields = collection.Select(x => ReflectionUtils.GetObjectPropertyStringValues(x).ToArray()).ToList(); //Zwrócenie kolekcji pól dla obiektów //Z każdego obiektu zostają pobrane wartości właściwości i zostają przekonwertowane na tablicę łańcuchów znaków - tablicę pól dla danego wiersza WriteTableFromFields(rowsFields, hasHeader, horizontalTextAlignment); //Wyświetlenie kolekcji pól w formie tabeli z nagłówkiem lub bez }
/// <summary> /// Wyświetlenie na konsoli tabeli z danymi z pliku CSV /// </summary> /// <param name="filePath">Ścieżka do pliku CSV</param> /// <param name="hasHeader">Czy ma nagłówek. Jeśli tak, to zostanie wyróżniony ramką</param> /// <param name="skipFirstLine">Czy pominąć pierwszą linię pliku CSV, zazwyczaj jest to nagłówek, a nie zawsze jest potrzebny</param> /// <param name="delimiter">Znak oddzielający dane w liniach pliku CSV</param> /// <param name="shouldSkipRecord">Warunek. który musi spełnić dana linia, by została wzięta pod uwagę</param> /// <param name="horizontalTextAlignment">Sposób wyrównania tekstu w poziomie, domyślnie jest do lewej</param> public static void WriteTableFromCSV(string filePath, bool hasHeader = true, bool skipFirstLine = false, string delimiter = ",", Func <string[], bool> shouldSkipRecord = null, HorizontalTextAlignment horizontalTextAlignment = HorizontalTextAlignment.Left) { List <string[]> rowsFields = CSVUtils.ParseCSVLines(filePath, skipFirstLine, delimiter, shouldSkipRecord).ToList(); //Zwrócenie kolekcji pól dla wybranych linii pliku CSV WriteTableFromFields(rowsFields, hasHeader, horizontalTextAlignment); //Wyświetlenie kolekcji pól w formie tabeli z nagłówkiem lub bez }
/// <summary> /// Writes the specified <see cref="FormattableString"/> to the console.</summary> /// <param name="value"> /// Formattable string. You can use an interpolated string literal here.</param> /// <param name="foreground"> /// Default foreground color when an interpolated variable isn’t a <see cref="ConsoleColoredString"/> or <see /// cref="ConsoleColoredChar"/> or a foreground color is unspecified.</param> /// <param name="background"> /// Default background color when an interpolated variable isn’t a <see cref="ConsoleColoredString"/> or <see /// cref="ConsoleColoredChar"/> or a background color is unspecified.</param> /// <param name="stdErr"> /// <c>true</c> to print to Standard Error instead of Standard Output.</param> /// <param name="align"> /// Horizontal alignment of the string within the remaining space of the current line. If the string does not fit, /// it will be printed as if left-aligned.</param> public static void WriteLine(FormattableString value, ConsoleColor?foreground = null, ConsoleColor?background = null, bool stdErr = false, HorizontalTextAlignment align = HorizontalTextAlignment.Left) { WriteLine(value.Format.Color(foreground, background).Fmt(value.GetArguments()), stdErr, align); }
/// <summary> /// Set Text /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <param name="location"></param> /// <param name="alignment"></param> /// <param name="angle"></param> private void InternalSetType(string value, RVT.TextNoteType type, XYZ location, HorizontalTextAlignment alignment, double angle) { int bold = type.LookupParameter("Bold").AsInteger(); int italic = type.LookupParameter("Italic").AsInteger(); string font = type.LookupParameter("Text Font").AsString(); double size = type.LookupParameter("Text Size").AsDouble(); bool isBold = (bold == 1) ? true : false; bool isItalic = (italic == 1) ? true : false; InternalSetTextSettings(value, isBold, isItalic, size, font, location.ToPoint(true), alignment, angle); }
/// <summary> /// Places the specified content into the cell at the specified co-ordinates.</summary> /// <param name="col"> /// Column where to place the content.</param> /// <param name="row"> /// Row where to place the content.</param> /// <param name="content"> /// The content to place.</param> /// <param name="colSpan"> /// The number of columns to span.</param> /// <param name="rowSpan"> /// The number of rows to span.</param> /// <param name="noWrap"> /// If true, indicates that this cell should not be automatically word-wrapped except at explicit newlines in /// <paramref name="content"/>. The cell is word-wrapped only if doing so is necessary to fit all no-wrap cells /// into the table's total width. If false, the cell is automatically word-wrapped to optimise the table's layout.</param> /// <param name="alignment"> /// How to align the contents within the cell, or null to use <see cref="DefaultAlignment"/>.</param> /// <param name="background"> /// Specifies a background color for the whole cell, including its empty space. Characters with background colors /// in the input string take precedence for those characters only.</param> public void SetCell(int col, int row, ConsoleColoredString content, int colSpan = 1, int rowSpan = 1, bool noWrap = false, HorizontalTextAlignment? alignment = null, ConsoleColor? background = null) { setCell(col, row, content, colSpan, rowSpan, noWrap, alignment, background); }
private static TextAnchor GetAnchor(VerticalTextAlignment verticalTextAlignment, HorizontalTextAlignment horizontalTextAlignment) { TextAnchor ac = TextAnchor.UpperLeft; switch (horizontalTextAlignment) { case HorizontalTextAlignment.Left: switch (verticalTextAlignment) { case VerticalTextAlignment.Bottom: ac = TextAnchor.LowerLeft; break; case VerticalTextAlignment.Middle: ac = TextAnchor.MiddleLeft; break; default: ac = TextAnchor.UpperLeft; break; } break; case HorizontalTextAlignment.Center: switch (verticalTextAlignment) { case VerticalTextAlignment.Bottom: ac = TextAnchor.LowerCenter; break; case VerticalTextAlignment.Middle: ac = TextAnchor.MiddleCenter; break; default: ac = TextAnchor.UpperCenter; break; } break; default: switch (verticalTextAlignment) { case VerticalTextAlignment.Bottom: ac = TextAnchor.LowerRight; break; case VerticalTextAlignment.Middle: ac = TextAnchor.MiddleRight; break; default: ac = TextAnchor.UpperRight; break; } break; } return(ac); }
///<summary> ///Draws text at a location in the 2d gui coordinates. ///</summary> ///<param name="font"> ///The font to draw with, usually specified by a GUIStyle. ///</param> ///<param name="offset"> ///Point where to start drawing the text. ///</param> ///<param name="size"> ///Margins used to calculate the text alignment. ///</param> ///<param name="horizontalAlignment"> ///Horizontal justification of the text relative to the offset. ///</param> ///<param name="horizontalPadding">left/right padding</param> ///<param name="verticalAlignment"> ///Vertical justification of the text relative to the offset. ///</param> ///<param name="verticalPadding">top/bottom padding</param> ///<param name="color">The color to draw the text as.</param> ///<param name="text">The string to be drawn.</param> public static void JustifiedText( Resource<SpriteFont> font, Vector2 offset, Vector2 size, HorizontalTextAlignment horizontalAlignment, float horizontalPadding, VerticalTextAlignment verticalAlignment, float verticalPadding, Color color, string text) { DrawUtil.JustifiedText( font, offset + Instance._defaultOffset, size, horizontalAlignment, 0, VerticalTextAlignment.Center, 0, color, text); }
/// <summary> /// Set Text /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <param name="location"></param> /// <param name="alignment"></param> /// <param name="angle"></param> private void InternalSetType(string value, RVT.TextNoteType type, XYZ location, HorizontalTextAlignment alignment, double angle) { int bold = type.get_Parameter(BuiltInParameter.TEXT_STYLE_BOLD).AsInteger(); int italic = type.get_Parameter(BuiltInParameter.TEXT_STYLE_ITALIC).AsInteger(); string font = type.get_Parameter(BuiltInParameter.TEXT_FONT).AsString(); double size = type.get_Parameter(BuiltInParameter.TEXT_SIZE).AsDouble(); bool isBold = (bold == 1) ? true : false; bool isItalic = (italic == 1) ? true : false; InternalSetTextSettings(value, isBold, isItalic, size, font, location.ToPoint(true), alignment, angle); }
/// <summary> /// Initializes a new instance of the <see cref="TextNode"/> class. /// </summary> /// <param name="text">The text you want to display.</param> /// <param name="name">The name of the SceneNode.</param> /// <param name="vs">The vertex shader you want to use..</param> /// <param name="ps">The pixel shader you want to use.</param> /// <param name="anchors">Anchors for the mesh. Influences the scaling of the object if the enclosing canvas is resized.</param> /// <param name="offsets">The offsets.</param> /// <param name="fontMap">Offsets for the mesh. Defines the position of the object relative to its enclosing UI element.</param> /// <param name="color">The color.</param> /// <param name="horizontalAlignment">The <see cref="HorizontalTextAlignment"/> defines the text's placement along the enclosing <see cref="MinMaxRect"/>'s x-axis.</param> /// <param name="verticalTextAlignment">The <see cref="HorizontalTextAlignment"/> defines the text's placement along the enclosing <see cref="MinMaxRect"/>'s y-axis.</param> public TextNode(string text, string name, string vs, string ps, MinMaxRect anchors, MinMaxRect offsets, FontMap fontMap, float4 color, HorizontalTextAlignment horizontalAlignment = HorizontalTextAlignment.Left, VerticalTextAlignment verticalTextAlignment = VerticalTextAlignment.Top) { var textMesh = new GUIText(fontMap, text, horizontalAlignment) { Name = name + "textMesh" }; var xFormText = new XFormText { Width = textMesh.Width, Height = textMesh.Height, HorizontalAlignment = textMesh.HorizontalAlignment, VerticalAlignment = verticalTextAlignment }; Name = name; Components = new List <SceneComponent> { new RectTransform { Name = name + "_RectTransform", Anchors = anchors, Offsets = offsets }, new XForm { Name = name + "_XForm", } }; Children = new ChildList() { new SceneNode() { Components = new List <SceneComponent>() { xFormText, new ShaderEffect(new[] { new EffectPassDeclaration { VS = vs, PS = ps, StateSet = new RenderStateSet { AlphaBlendEnable = true, SourceBlend = Blend.SourceAlpha, DestinationBlend = Blend.InverseSourceAlpha, BlendOperation = BlendOperation.Add, ZEnable = false } } }, new[] { new EffectParameterDeclaration { Name = "DiffuseTexture", Value = new Texture(fontMap.Image) }, new EffectParameterDeclaration { Name = "DiffuseColor", Value = color }, new EffectParameterDeclaration { Name = "DiffuseMix", Value = 0.0f }, new EffectParameterDeclaration { Name = "FUSEE_ITMV", Value = float4x4.Identity }, new EffectParameterDeclaration { Name = "FUSEE_MVP", Value = float4x4.Identity }, }), textMesh } } }; }
/// <summary> /// Wyświetlenie kolekcji pól wierszy w formie tabeli /// </summary> /// <param name="rowsFields">Kolekcja pól wierszy</param> /// <param name="columnsWidths">Szerokość zawartości kolumn</param> /// <param name="horizontalTextAlignment">Sposób wyrównania tekstu w poziomie, domyślnie jest do lewej</param> public static void WriteRows(IEnumerable <string[]> rowsFields, int[] columnsWidths, HorizontalTextAlignment horizontalTextAlignment = HorizontalTextAlignment.Left) { string row; //Tu będzie przechowywana tymaczasowo zawartość danego wiersza foreach (var item in rowsFields.Skip(1)) //Przejście po wszystkich kolekcjach pól wierszy pomijając pierwszy wiersz, pierwszy element kolekcji { row = GetRow(item, columnsWidths, horizontalTextAlignment); //Utworzenie zawartości wiersza na podstawie pól wiersza biorąc pod uwagę szerokość zawartości kolumn WriteRow(row); //Wyświetlenie zawartości wiersza bez oczkiwania na wciśnięcie klawisza } WriteRowDelimiter(columnsWidths); //Wyświetlenie dolnej krawędzi tabeli //WriteLine(); //Wyświetlenie pustej linii }
/// <summary> /// Writes the specified <see cref="ConsoleColoredString"/> followed by a newline to the console.</summary> /// <param name="value"> /// The string to print to the console.</param> /// <param name="stdErr"> /// <c>true</c> to print to Standard Error instead of Standard Output.</param> /// <param name="align"> /// Horizontal alignment of the string within the remaining space of the current line. If the string does not fit, /// it will be printed as if left-aligned.</param> public static void WriteLine(ConsoleColoredString value, bool stdErr = false, HorizontalTextAlignment align = HorizontalTextAlignment.Left) { var output = stdErr ? Console.Error : Console.Out; if (value != null) { var cursorLeft = 0; try { cursorLeft = Console.CursorLeft; } catch { } var width = WrapToWidth() - cursorLeft; if (align == HorizontalTextAlignment.Center && width > value.Length) { output.Write(new string(' ', (width - value.Length) / 2)); } else if (align == HorizontalTextAlignment.Right && width > value.Length) { output.Write(new string(' ', width - value.Length)); } value.writeTo(output); } output.WriteLine(); }
/// <summary> /// Writes the specified <see cref="ConsoleColoredString"/> followed by a newline to the console.</summary> /// <param name="value"> /// The string to print to the console.</param> /// <param name="stdErr"> /// <c>true</c> to print to Standard Error instead of Standard Output.</param> /// <param name="align"> /// Horizontal alignment of the string within the remaining space of the current line. If the string does not fit, /// it will be printed as if left-aligned.</param> public static void WriteLine(ConsoleColoredString value, bool stdErr = false, HorizontalTextAlignment align = HorizontalTextAlignment.Left) { var output = stdErr ? Console.Error : Console.Out; if (value != null) { var cursorLeft = 0; try { cursorLeft = Console.CursorLeft; } catch { } var width = WrapToWidth() - cursorLeft; if (align == HorizontalTextAlignment.Center && width > value.Length) output.Write(new string(' ', (width - value.Length) / 2)); else if (align == HorizontalTextAlignment.Right && width > value.Length) output.Write(new string(' ', width - value.Length)); value.writeTo(output); } output.WriteLine(); }