private int GetPageCountInSection(LayoutBox box) { SectionLayoutBox fieldSectionBox = (box as SectionLayoutBox) ?? box.GetCurrentSectionBox(); int pagesNumber = fieldSectionBox.AssociatedSection.GetAssociatedLayoutBoxes().Count(); return(pagesNumber); }
public void AdapterBorderProperties() { const string image = "abc123.png"; LayoutBox borderSlice = new LayoutBox { Left = 2, Top = 3, Right = 4, Bottom = 5 }; InitializeBorder(image, borderSlice); var facet = new ResourceManagerInitializer.TestFacet(); uiManager.InitializeFacet(facet); var adapter = facet.InterfaceRoot.Renderer.Adapter; var style = adapter.StyleOf(facet.WindowA); Assert.AreEqual(image, style.Border.Image); Assert.AreEqual(borderSlice, style.Border.ImageSlice); //Assert.AreEqual("ui_back_1.png", style.Border.Left.Width); //Assert.AreEqual("ui_back_1.png", style.Border.Left.Color); //Assert.AreEqual("ui_back_1.png", style.Border.Top.Width); //Assert.AreEqual("ui_back_1.png", style.Border.Top.Color); //Assert.AreEqual("ui_back_1.png", style.Border.Right.Width); //Assert.AreEqual("ui_back_1.png", style.Border.Right.Color); //Assert.AreEqual("ui_back_1.png", style.Border.Bottom.Width); //Assert.AreEqual("ui_back_1.png", style.Border.Bottom.Color); }
/// <summary>Finds the index of the nearest character to x pixels.</summary> /// <param name="x">The number of pixels from the left edge of the screen.</param> /// <param name="y">The number of pixels from the top edge of the screen.</param> /// <returns>The index of the nearest letter.</returns> public int LetterIndex(float x, float y) { // First, find which box the x/y point is in: LayoutBox box = BestBox(y); return(LetterIndex(x, box)); // <- fitting! }
/// <summary>Finds the best box for the given y coordinate.</summary> public LayoutBox BestBox(float y) { // First, find which box the y point is in: LayoutBox box = RenderData_.FirstBox; if (box == null) { return(null); } if (y < box.Y) { return(box); } // For each one.. while (box != null) { if (y < box.MaxY) { return(box); } // Next box: box = box.NextInElement; } return(RenderData_.LastBox); }
public void CenterVertically() { var lb = new LayoutBox(new RectangleF(0, 0, 375, 44)); lb.Left(20).CenterVertically().Height(18).Right(0); Assert.AreEqual(new RectangleF(20, 13, 355, 18), lb.LayoutBounds); }
public ConfigDialog(IPluginHost pluginHost) { InitializeComponent(); m_PluginHost = pluginHost; if (File.Exists("StrengthReportLayouts.xml")) { m_LayoutBox = LayoutBox.LoadFromFile("StrengthReportLayouts.xml"); } else { m_LayoutBox = LayoutBox.LoadFromString(Resources.LayoutsDefault); } foreach (Layout l in m_LayoutBox) layoutBoxBindingSource.Add(l); if (File.Exists("StrengthReportTemplates.xml")) { m_TemplateBox = TemplateBox.LoadFromFile("StrengthReportTemplates.xml"); } else { m_TemplateBox = TemplateBox.LoadFromString(Resources.TemplatesDefault); } foreach (Template l in m_TemplateBox) templatesBinginSource.Add(l); tabFormat.SelectedIndex = 1; }
private int GetPageCountInSection(LayoutBox box) { SectionLayoutBox fieldSectionBox = (box as SectionLayoutBox) ?? box.GetCurrentSectionBox(); int pagesNumber = fieldSectionBox.AssociatedSection.GetAssociatedLayoutBoxes().Count(); return pagesNumber; }
public void CenterHorizontaly() { var lb = new LayoutBox(new RectangleF(20, 20, 100, 100)); lb.CenterHorizontally().Height(20.Dp()).Width(20.Dp()).Top(0); Assert.Equal(new RectangleF(60, 20, 20, 20), lb.Frame()); }
public ConfigDialog(IPluginHost pluginHost) { InitializeComponent(); m_PluginHost = pluginHost; if (File.Exists("StrengthReportLayouts.xml")) { m_LayoutBox = LayoutBox.LoadFromFile("StrengthReportLayouts.xml"); } else { m_LayoutBox = LayoutBox.LoadFromString(Resources.LayoutsDefault); } foreach (Layout l in m_LayoutBox) { layoutBoxBindingSource.Add(l); } if (File.Exists("StrengthReportTemplates.xml")) { m_TemplateBox = TemplateBox.LoadFromFile("StrengthReportTemplates.xml"); } else { m_TemplateBox = TemplateBox.LoadFromString(Resources.TemplatesDefault); } foreach (Template l in m_TemplateBox) { templatesBinginSource.Add(l); } tabFormat.SelectedIndex = 1; }
/// <summary>Called when a selection starts using the given input pointer (typically a mouse).</summary> public static void BeginSelect(PowerUI.InputPointer pointer, Css.Value mode) { // Selection starting at the position the pointer started dragging // Firstly, resolve our doc coords to a selection range start. // Get as first containing child node (should be text or null): NodeList kids = pointer.ActivePressed.childNodes_; if (kids != null) { for (int i = 0; i < kids.length; i++) { IRenderableNode irn = (kids[i] as IRenderableNode); if (irn != null) { // Contains it? LayoutBox box = irn.RenderData.BoxAt(pointer.DownDocumentX, pointer.DownDocumentY); if (box == null) { // Use the last one: box = irn.RenderData.LastBox; } if (box != null) { // Great! Try it as a text node (should always be one): PowerUI.RenderableTextNode htn = (kids[i] as PowerUI.RenderableTextNode); if (htn != null) { // Awesome - get the letter indices: int startIndex = htn.LetterIndex(pointer.DownDocumentX, box); int endIndex = htn.LetterIndex(pointer.DocumentX, pointer.DocumentY); // Create a range: Range range = new Range(); range.startOffset = startIndex; range.endOffset = endIndex; range.startContainer = htn; range.endContainer = htn; // Get the current selection: Selection s = (kids[i].document as HtmlDocument).getSelection(); // Clear all: s.removeAllRanges(); // Add range: s.addRange(range); } break; } } } } }
/// <summary>Drops this select box down.</summary> public void Drop() { if (Dropped) { return; } // Focus if it isn't already: focus(); // Get the CS of the HTML node: ComputedStyle computed = htmlDocument.html.Style.Computed; // Get/create it: Dropdown = computed.GetOrCreateVirtual(HtmlDropdownElement.Priority, "dropdown") as HtmlDropdownElement; // Act like the options are kids of the dropdown: Dropdown.childNodes_ = RawOptions; // Get my computed style: computed = Style.Computed; // Locate it to the select: LayoutBox box = computed.FirstBox; Dropdown.style.left = box.X + "px"; Dropdown.style.width = box.Width + "px"; Dropdown.style.top = (box.Y + box.PaddedHeight) + "px"; }
public void CenterVertically() { var lb = new LayoutBox(new RectangleF(0, 0, 375, 44)); lb.Left(20.Dp()).CenterVertically().Height(18.Dp()).Right(0); Assert.Equal(new RectangleF(20, 13, 355, 18), lb.Frame()); }
/// <summary>Makes the thumb a percentage size relative to the length of the bar.</summary> /// <param name="percentSize">A value from 0->1 that represents how visible the content /// is and as a result how long the thumb is.</param> public void ApplyTabSize(float percentSize, LayoutBox box) { // How wide is the border/padding of the thumb? float styleSize = StyleSize; // How big should the new thumb be? float newSize = (percentSize * BarSize) - styleSize; if (newSize == ThumbSize) { // It didn't change. return; } // Apply the new thumb size: if (IsVertical) { // For this pass: box.InnerHeight = newSize; // Future passes: style.Computed.ChangeTagProperty("height", new Css.Units.DecimalUnit(newSize), false); } else { // This pass: box.InnerWidth = newSize; // Future passes: style.Computed.ChangeTagProperty("width", new Css.Units.DecimalUnit(newSize), false); } }
public override void OnRender(Renderman renderer) { // Get the target: HtmlElement target = ScrollBar.scrollTarget; if (target == null) { return; } ComputedStyle computed = target.style.Computed; LayoutBox box = computed.FirstBox; if (box == null) { // Not visible or hasn't been drawn yet. return; } int overflowMode = IsVertical?box.OverflowY : box.OverflowX; float visible = IsVertical?box.VisiblePercentageY() : box.VisiblePercentageX(); if (visible > 1f) { visible = 1f; } else if (visible < 0f) { visible = 0f; } // Handle auto next: if (overflowMode == VisibilityMode.Auto && visible == 1f) { // Hide it: ScrollBar.Style.display = "none"; // Make sure it's not scrolled: if (IsVertical && box.Scroll.Top != 0f) { if (box.Scroll.Top != 0f) { // Clear it: computed.ChangeTagProperty("scroll-top", new Css.Units.DecimalUnit(0f)); } } else if (box.Scroll.Left != 0f) { computed.ChangeTagProperty("scroll-left", new Css.Units.DecimalUnit(0f)); } // Mark as hidden so the informer can watch out for it: ScrollBar.Hidden = true; return; } ApplyTabSize(visible, Style.Computed.FirstBox); }
private void InitializeBorder(string image, LayoutBox borderSlice) { WindowTheme.Border = new WidgetBorderModel { Image = image, Size = borderSlice }; }
/// <summary>Called just before the image is about to be drawn (only ever when it's actually visible). /// Note that everything else - e.g. ImageMaterial or Width/Height - is always called after this.</summary> public override void OnLayout(Css.RenderableData context, LayoutBox box, out float width, out float height) { // Get the shape of the element: width = box.PaddedWidth; height = box.PaddedHeight; // Tell the context which may trigger a redraw: Context.SetSize((int)width, (int)height); }
/// <summary> /// Gets the maximum content size for an item, given the max dimensions of its parent. /// </summary> /// <param name="itemBox"></param> /// <param name="parentMaxWidth"></param> /// <param name="parentMaxHeight"></param> /// <returns></returns> public static Size ItemContentMaxSize(LayoutBox itemBox, Size parentMaxSize) { int itemMaxWidth = parentMaxSize.Width; int itemMaxHeight = parentMaxSize.Height; itemMaxWidth -= itemBox.Width; itemMaxHeight -= itemBox.Height; return(new Size(itemMaxWidth, itemMaxHeight)); }
public void WriteLayoutBoxTwoValues() { var layoutBox = new LayoutBox { Left = 123, Top = 45, Right = 123, Bottom = 45 }; converter.WriteYaml(emitter.Object, layoutBox, typeof(LayoutBox)); Assert.AreEqual("123 45", scalar.Value); }
public void WriteLayoutBoxSingleValue() { var layoutBox = new LayoutBox { Left = 123, Top = 123, Right = 123, Bottom = 123 }; converter.WriteYaml(emitter.Object, layoutBox, typeof(LayoutBox)); Assert.AreEqual("123", scalar.Value); }
// This method returns the current glyph run. GlyphRun BeginGlyphRun(Rect rectangle, float advance, LayoutBox currentLayoutBox, FormattingSpan formattingSpan, int lineNumber) { GlyphRun glyphRun = new GlyphRun(); glyphRun.FormattingSpan = formattingSpan; glyphRun.Glyphs = new List <CanvasGlyph>(); currentLayoutBox.AddGlyphRun(glyphRun); return(glyphRun); }
/// <summary>Called just before the image is about to be drawn (only ever when it's actually visible). /// Note that everything else - e.g. ImageMaterial or Width/Height - is always called after this.</summary> public override void OnLayout(Css.RenderableData context, LayoutBox box, out float width, out float height) { // Get the shape of the element: width = box.PaddedWidth; height = box.PaddedHeight; if (width != Image.width || height != Image.height) { Resize((int)width, (int)height); } }
private void ConfigDialog_FormClosing(object sender, FormClosingEventArgs e) { LayoutBox lb = new LayoutBox(); foreach (Object o in layoutBoxBindingSource) { Layout l = (Layout)o; lb.Add(l); } lb.SaveToFile(); m_TemplateBox.SaveToFile("StrengthReportTemplates.xml"); }
void SplitJustifiedGlyphsIntoRuns(CanvasTextAnalyzer textAnalyzer, LayoutBox layoutBox, CanvasGlyph[] justifiedGlyphs, bool needsAdditionalJustificationCharacters) { int glyphIndex = 0; float xPosition = (float)layoutBox.Rectangle.Right; for (int i = 0; i < layoutBox.GlyphRuns.Count; i++) { if (layoutBox.GlyphRuns[i].Glyphs.Count == 0) { continue; } int originalGlyphCountForThisRun = layoutBox.GlyphRuns[i].Glyphs.Count; if (needsAdditionalJustificationCharacters) { // Replace the glyph data, since justification can modify glyphs CanvasGlyph[] justifiedGlyphsForThisGlyphRun = new CanvasGlyph[layoutBox.GlyphRuns[i].Glyphs.Count]; for (int j = 0; j < layoutBox.GlyphRuns[i].Glyphs.Count; j++) { justifiedGlyphsForThisGlyphRun[j] = justifiedGlyphs[glyphIndex + j]; } CanvasCharacterRange range = layoutBox.GlyphRuns[i].GetRange(); var glyphRunClusterMap = layoutBox.GlyphRuns[i].GetClusterMap(range); var glyphRunShaping = layoutBox.GlyphRuns[i].GetShaping(); CanvasGlyph[] newSetOfGlyphs = textAnalyzer.AddGlyphsAfterJustification( layoutBox.GlyphRuns[i].FormattingSpan.FontFace, layoutBox.GlyphRuns[i].FormattingSpan.FontSize, layoutBox.GlyphRuns[i].FormattingSpan.Script, glyphRunClusterMap, layoutBox.GlyphRuns[i].Glyphs.ToArray(), justifiedGlyphsForThisGlyphRun, glyphRunShaping); layoutBox.GlyphRuns[i].Glyphs = new List <CanvasGlyph>(newSetOfGlyphs); } else { for (int j = 0; j < layoutBox.GlyphRuns[i].Glyphs.Count; j++) { layoutBox.GlyphRuns[i].Glyphs[j] = justifiedGlyphs[glyphIndex + j]; } } glyphIndex += originalGlyphCountForThisRun; } }
void JustifyLine(CanvasTextAnalyzer textAnalyzer, LayoutBox layoutBox) { CanvasGlyph[] allGlyphs; var justificationOpportunities = GetJustificationOpportunities(textAnalyzer, layoutBox, out allGlyphs); CanvasGlyph[] justifiedGlyphs = textAnalyzer.ApplyJustificationOpportunities( (float)layoutBox.Rectangle.Width, justificationOpportunities, allGlyphs); bool needsJustificationCharacters = layoutBox.GlyphRuns[0].FormattingSpan.NeedsAdditionalJustificationCharacters; SplitJustifiedGlyphsIntoRuns(textAnalyzer, layoutBox, justifiedGlyphs, needsJustificationCharacters); }
/// <summary>Gets the renderable data at the given point (may be null).</summary> public RenderableData Get(float x, float y) { InputGridEntry ige = Front; while (ige != null) { // Get the render data: RenderableData renderData = ige.RenderData; // Get the zone: ScreenRegion screenBox = renderData.OnScreenRegion; // Is this node visible and is the point within it? if (screenBox != null && screenBox.Contains(x, y)) { // At this point, the mouse could still be outside it. // This happens with inline elements - their clipping boundary can contain multiple sub-boxes. // So, time to check how many boxes it has, then the individual boxes if we've got more than one. LayoutBox box = renderData.FirstBox; if (box != null && box.NextInElement != null) { // Multiple boxes. Must be contained in one of them to win. while (box != null) { if (box.Contains(x, y)) { // Ok! return(renderData); } // Advance to the next one: box = box.NextInElement; } } else { // Yep! return(renderData); } } ige = ige.Previous; } return(null); }
/// <summary>Finds the index of the nearest character to x pixels.</summary> /// <param name="x">The number of pixels from the left edge of the screen.</param> public int LetterIndex(float x, LayoutBox box) { if (box == null) { // Nope! return(0); } // Get the text renderer: TextRenderingProperty trp = RenderData_.Text; if (trp == null) { // It's not been rendered at all yet. return(0); } // Walk the characters in the box until we've walked at least x units. float left = box.X; float fontSize = trp.FontSize; for (int i = box.TextStart; i < box.TextEnd; i++) { // Get the char: InfiniText.Glyph glyph = trp.Characters[i]; if (glyph == null) { continue; } // Move width along: left += glyph.AdvanceWidth * fontSize; if (left >= x) { // Got it! return(i); } // Advance over spacing: left += trp.LetterSpacing; } // End of the box. return(box.TextEnd); }
/// <summary>Applies the image data so it's ready for rendering.</summary> public void UpdateDimensions(LayoutBox box) { int w = (int)box.InnerWidth; int h = (int)box.InnerHeight; DynamicTexture img = ImageData_; if (w == img.Width && h == img.Height) { // No change. Stop there. return; } // Resize the texture (clearing it): img.Resize(w, h, true); }
private int GetCurrentPageFromSectionPages(LayoutBox box) { int pageCounter = 1; SectionLayoutBox fieldLayotBox = (box as SectionLayoutBox) ?? box.GetCurrentSectionBox(); foreach (SectionLayoutBox layoutBox in fieldLayotBox.AssociatedSection.GetAssociatedLayoutBoxes()) { if (layoutBox.PageNumber == fieldLayotBox.PageNumber) { break; } pageCounter++; } return pageCounter; }
private int GetCurrentPageFromSectionPages(LayoutBox box) { int pageCounter = 1; SectionLayoutBox fieldLayotBox = (box as SectionLayoutBox) ?? box.GetCurrentSectionBox(); foreach (SectionLayoutBox layoutBox in fieldLayotBox.AssociatedSection.GetAssociatedLayoutBoxes()) { if (layoutBox.PageNumber == fieldLayotBox.PageNumber) { break; } pageCounter++; } return(pageCounter); }
/// <summary> /// Creates the default theme which requires no assets. /// </summary> /// <returns></returns> public static Theme CreateDefaultTheme() { var data = new ThemeData { new ThemeStyle { Pattern = "*", Background = new ThemeWidgetBackground { Color = Color.Black, }, Font = new FontStyleProperties { Color = Color.White, }, Animation = new ThemeWidgetAnimation { TransitionIn = "fade-in", TransitionOut = "fade-out" } }, new ThemeStyle { Pattern = "menu.*", Padding = LayoutBox.SameAllAround(8), }, new ThemeStyle { Pattern = "menu.*", WidgetState = "selected", Padding = LayoutBox.SameAllAround(8), Background = new ThemeWidgetBackground { Color = Color.White }, Font = new FontStyleProperties { Color = Color.Black } } }; return(new Theme { Data = data }); }
/// <summary>The union of all client rects.</summary> public BoxRegion getBoundingClientRect() { // Get the first box: LayoutBox box = RenderData.FirstBox; // Get the first rect: float x = box.X; float y = box.Y; float maxX = box.MaxX; float maxY = box.MaxY; // Go to next one: box = box.NextInElement; while (box != null) { // Combine it in: if (box.X < x) { x = box.X; } if (box.Y < y) { y = box.Y; } if (box.MaxX > maxX) { maxX = box.MaxX; } if (box.MaxY > maxY) { maxY = box.MaxY; } // Go to next one: box = box.NextInElement; } return(new BoxRegion(x, y, maxX - x, maxY - y)); }
// // Returns the current glyph run, or null if there's no more layout boxes. // GlyphRun BeginNewLayoutBox(ref int rectangleIndex, List <Rect> rectangles, ref float glyphRunAdvance, ref int wordsPerLine, FormattingSpan formattingSpan, List <LayoutBox> layoutBoxes) { rectangleIndex++; if (rectangleIndex >= rectangles.Count) { return(null); } LayoutBox layoutBox = new LayoutBox(rectangles[rectangleIndex]); layoutBoxes.Add(layoutBox); glyphRunAdvance = 0; wordsPerLine = 0; GlyphRun newGlyphRun = BeginGlyphRun(rectangles[rectangleIndex], glyphRunAdvance, layoutBox, formattingSpan, rectangleIndex); return(newGlyphRun); }
protected override DocumentFragment GetResultFragment() { int totalPageCount = 1; int totalPageInCurrentSection = 1; int currentPageInCurrentSection = 1; if (this.EvaluationContext != null) { totalPageCount = this.GetTotalPageCount(); LayoutBox box = this.EvaluationContext.AssociatedLayoutBoxInMainDocument ?? this.FieldStart.FirstLayoutBox; currentPageInCurrentSection = this.GetCurrentPageFromSectionPages(box); totalPageInCurrentSection = this.GetPageCountInSection(box); } return(DocumentFragment.CreateFromInline(new Span( string.Format("Total pages in the document: {0}. Pages in current section: {1} / {2}", totalPageCount, currentPageInCurrentSection, totalPageInCurrentSection)))); }
private void ConfigDialog_FormClosing(object sender, FormClosingEventArgs e) { LayoutBox lb = new LayoutBox(); foreach (Object o in layoutBoxBindingSource) { Layout l = (Layout)o; lb.Add(l); } lb.SaveToFile(); m_TemplateBox.SaveToFile("StrengthReportTemplates.xml"); }