Example #1
0
        private static void DisableAllBut(this ILayoutController page, View anchor)
        {
            foreach (var item in page.Children)
            {
                if (item != anchor)
                {
                    if (item.IsType <ScrollView>())
                    {
                        ((ScrollView)item).Orientation = ScrollOrientation.Neither;
                    }
                    else
                    {
                        if (!item.IsType <ILayoutController>() && item.IsType <View>())
                        {
                            ((View)item).IsEnabled = false;
                        }
                    }
                }

                if (item.IsType <ILayoutController>())
                {
                    ((ILayoutController)item).DisableAllBut(anchor);
                }
            }
        }
Example #2
0
        private void LoadFileLayout(INode rootNode)
        {
            LayoutRootNodeIndex RootIndex  = new LayoutRootNodeIndex(rootNode);
            ILayoutController   Controller = LayoutController.Create(RootIndex);

            layoutControl.Controller = Controller;
        }
Example #3
0
        public static void FindViewByStyleId(this ILayoutController container, string styleId, ref object obj)
        {
            if (container is Layout)
            {
                var layout = (Layout)container;
                if (layout.StyleId == styleId)
                {
                    obj = layout;
                    return;
                }
            }

            var view = container.Children.FirstOrDefault(x => x.StyleId == styleId);

            if (view != null)
            {
                obj = view;
                return;
            }
            else
            {
                foreach (var item in container.Children)
                {
                    if (item is ILayoutController)
                    {
                        ((ILayoutController)item).FindViewByAutomationId(styleId, ref obj);
                    }
                }
            }
        }
Example #4
0
        public static IEnumerable <T> FindVisualChildren <T>(Element element, bool recursive = true) where T : View
        {
            if (element != null && element is Layout)
            {
                ILayoutController childrenProperty = element as ILayoutController;

                if (childrenProperty != null)
                {
                    foreach (var child in childrenProperty.Children)
                    {
                        if (child != null && child is T)
                        {
                            yield return((T)child);
                        }
                        if (recursive)
                        {
                            foreach (T childOfChild in FindVisualChildren <T>(child))
                            {
                                yield return(childOfChild);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        private IDisposable FindAllCommandHolder(ILayoutController content, InterceptState state)
        {
            if (content == null)
            {
                return(null);
            }

            return(FindAllCommandHolder(content.Children.ToArray(), state));
        }
Example #6
0
        /// <summary>
        /// Reads <paramref name="sourceStream"/> as an easly source code and from it create a bitmap using the BMP format in <paramref name="destinationStream"/>.
        /// </summary>
        /// <param name="sourceStream">The source code.</param>
        /// <param name="destinationStream">The destination bitmap.</param>
        /// <returns></returns>
        private static int PreviewFile(FileStream sourceStream, FileStream destinationStream)
        {
            // Create a serializer than can read text or binary formats.
            Serializer Serializer = new Serializer();

            Serializer.Format = SerializationFormat.BinaryPreferred;

            // Reads the source stream as an easly source code.
            INode RootNode = Serializer.Deserialize(sourceStream) as INode;

            // Create a controller for this source code.
            ILayoutRootNodeIndex RootIndex  = new LayoutRootNodeIndex(RootNode);
            ILayoutController    Controller = LayoutController.Create(RootIndex);

            Size ViewSize;

            // Create and open a visual on which to render.
            DrawingVisual DrawingVisual = new DrawingVisual();

            using (DrawingContext dc = DrawingVisual.RenderOpen())
            {
                // Create a draw context using default fonts and brushes.
                DrawContext DrawContext = DrawContext.CreateDrawContext(new Typeface("Consolas"), 10, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, null, null, hasCommentIcon: true, displayFocus: true);

                // Create a view using custom frames (for how code is organized).
                ILayoutControllerView ControllerView = LayoutControllerView.Create(Controller, EaslyEdit.CustomLayoutTemplateSet.LayoutTemplateSet, DrawContext);
                ControllerView.SetCommentDisplayMode(EaslyController.Constants.CommentDisplayModes.All);

                // Run the measure step to obtain the bitmap size.
                ControllerView.MeasureAndArrange();
                ViewSize = ControllerView.ViewSize;

                // Draw a white background.
                dc.DrawRectangle(Brushes.White, null, new System.Windows.Rect(0, 0, ViewSize.Width.Draw, ViewSize.Height.Draw));

                // Draw the source code.
                DrawContext.SetWpfDrawingContext(dc);
                ControllerView.Draw(ControllerView.RootStateView);
            }

            // At this stage, the visual is ready with drawing data.

            // Create a bitmap and renders the visual on it.
            RenderTargetBitmap Bitmap = new RenderTargetBitmap((int)ViewSize.Width.Draw, (int)ViewSize.Height.Draw, Dpi, Dpi, PixelFormats.Default);

            Bitmap.Render(DrawingVisual);

            // Save the bitmap to the destination file with a BMP format encoder.
            BmpBitmapEncoder Encoder = new BmpBitmapEncoder();
            BitmapFrame      Frame   = BitmapFrame.Create(Bitmap);

            Encoder.Frames.Add(Frame);
            Encoder.Save(destinationStream);

            return(0);
        }
 /// <summary>
 /// Scans a layout view for it's children. If the child view is a layout, it scans those views as well.
 /// </summary>
 /// <param name="rootView"></param>
 /// <param name="includeLayouts"></param>
 private void ScanLayout(ILayoutController rootView, bool includeLayouts)
 {
     foreach (var view in rootView.Children)
     {
         if (includeLayouts || !(view is Layout) && view is View)
         {
             MonitorView((View)view);
         }
         if (view is Layout <View> )
         {
             ScanLayout((Layout <View>)view, includeLayouts);
         }
     }
 }
Example #8
0
        /// <summary>
        /// Habilita / Desabilita os controles da página enquanta a mesma está processando os dados
        /// </summary>
        /// <param name="state"></param>
        public static void ChangeState(ILayoutController layout, ActivityIndicator ind, bool busyState)
        {
            ind.IsRunning = busyState;

            if (layout == null)
            {
                return;
            }

            foreach (VisualElement child in layout.Children)
            {
                child.IsEnabled = !busyState;
            }
        }
    public static int SetLayoutVertical(IntPtr l)
    {
        int result;

        try
        {
            ILayoutController layoutController = (ILayoutController)LuaObject.checkSelf(l);
            layoutController.SetLayoutVertical();
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Example #10
0
        /// <summary>
        /// Recursivelye rebuilds layout
        /// </summary>
        static private void RecursiveMarkForRebuild(RectTransform inTransform)
        {
            for (int i = 0, count = inTransform.childCount; i < count; i++)
            {
                RectTransform r = inTransform.GetChild(i) as RectTransform;
                if (r != null)
                {
                    RecursiveMarkForRebuild(r);
                }
            }

            ILayoutController controller = inTransform.GetComponent <ILayoutController>();

            if (controller != null)
            {
                LayoutRebuilder.MarkLayoutForRebuild(inTransform);
            }
        }
Example #11
0
        private static void EnableAll(this ILayoutController page)
        {
            foreach (var item in page.Children)
            {
                if (item is View)
                {
                    ((View)item).IsEnabled = true;
                }
                if (item.IsType <ScrollView>())
                {
                    ((ScrollView)item).Orientation = ScrollOrientation.Vertical;
                }

                if (item is ILayoutController)
                {
                    ((ILayoutController)item).EnableAll();
                }
            }
        }
Example #12
0
        private static void VisitChildren(ILayoutController controller, Func <GestureRecognizer> factoryMethod)
        {
            if (controller == null || controller.Children.Count == 0)
            {
                return;
            }

            foreach (var child in controller.Children)
            {
                /**
                 * All controls should get a TapGestureRecognizer, in the event they are touched.
                 */

                if (child is ILayoutController)
                {
                    VisitChildren(child as ILayoutController, factoryMethod);
                }

                var view = child as View;
                if (view == null)
                {
                    return;
                }

                if (view is Button)
                {
                    return;
                }

                var behavior    = factoryMethod();
                var tapBehavior = behavior as TapGestureRecognizer;

                if (tapBehavior != null)
                {
                    tapBehavior.CommandParameter = view;
                }

                view.GestureRecognizers.Add(behavior);
            }
        }
        private static void VisitChildren(ILayoutController controller, Func<GestureRecognizer> factoryMethod)
        {
            if (controller == null || controller.Children.Count == 0)
            {
                return;
            }

            foreach (var child in controller.Children)
            {
                /**
                 * All controls should get a TapGestureRecognizer, in the event they are touched.
                */

                if (child is ILayoutController)
                {
                    VisitChildren(child as ILayoutController, factoryMethod);
                }

                var view = child as View;
                if (view == null)
                {
                    return;
                }

                if (view is Button)
                {
                    return;
                }

                var behavior = factoryMethod();
                var tapBehavior = behavior as TapGestureRecognizer;

                if (tapBehavior != null)
                {
                    tapBehavior.CommandParameter = view;
                }

                view.GestureRecognizers.Add(behavior);
            }
        }
Example #14
0
        /// <summary>
        /// Find IParallaxSource child using recursion
        /// </summary>
        public static IParallaxSource FindParallaxSourceRecursive(View view)
        {
            if (view is IParallaxSource)
            {
                return(view as IParallaxSource);
            }
            else if (view is ILayoutController)
            {
                ILayoutController layout = view as ILayoutController;
                foreach (View child in layout.Children)
                {
                    IParallaxSource source = FindParallaxSourceRecursive(child);

                    if (source != null)
                    {
                        return(source);
                    }
                }
            }

            return(null);
        }
Example #15
0
 public static IEnumerable <Element> GetChildren(this ILayoutController source)
 {
     return(source.Children);
 }
Example #16
0
        //private int loopCountB = 0;
        //private int loopCountC = 0;
        //private int loopCountD = 0;
        //private int loopCountE = 0;

       
        protected override void Awake()
        {
            //base.Awake();
            //Debug.Log("***** Awake() *****"); // on Object ID:" + GetInstanceID());      

            m_isAwake = true;      
            // Cache Reference to the Canvas
            m_canvas = GetComponentInParent(typeof(Canvas)) as Canvas;          

            // Cache Reference to RectTransform.
            m_rectTransform = gameObject.GetComponent<RectTransform>();
            if (m_rectTransform == null)   
                m_rectTransform = gameObject.AddComponent<RectTransform>();
            

                          
            // Cache a reference to the UIRenderer.
            m_uiRenderer = GetComponent<CanvasRenderer>();
            if (m_uiRenderer == null) 
				m_uiRenderer = gameObject.AddComponent<CanvasRenderer> ();

			//m_uiRenderer.hideFlags = HideFlags.HideInInspector;

            // Determine if the RectTransform is Driven         
            m_layoutController = GetComponent(typeof(ILayoutController)) as ILayoutController ?? (transform.parent != null ? transform.parent.GetComponent(typeof(ILayoutController)) as ILayoutController : null);           
            if (m_layoutController != null) IsRectTransformDriven = true;

            // Cache reference to Mask Component if one is present         
            //m_stencilID = MaterialManager.GetStencilID(gameObject);
            //m_mask = GetComponentInParent<Mask>();
                       

            // Load the font asset and assign material to renderer.
            LoadFontAsset();

            // Allocate our initial buffers.          
            m_char_buffer = new int[m_max_characters];           
            m_cached_GlyphInfo = new GlyphInfo();
            m_uiVertices = new UIVertex[0]; // 
            m_isFirstAllocation = true;          
            
            m_textInfo = new TMP_TextInfo();
            //m_textInfo.wordInfo = new List<TMP_WordInfo>();
            //m_textInfo.lineInfo = new TMP_LineInfo[m_max_numberOfLines];
            //m_textInfo.pageInfo = new TMP_PageInfo[16];
            //m_textInfo.meshInfo = new TMP_MeshInfo();
            //m_textInfo.meshInfo.meshArrays = new UIVertex[17][];
          

            // TODO : Add support for inline sprites and other fonts.
            m_fontAssetArray = new TextMeshProFont[16];
            
               
            // Check if we have a font asset assigned. Return if we don't because no one likes to see purple squares on screen.
            if (m_fontAsset == null)
            {
                Debug.LogWarning("Please assign a Font Asset to this " + transform.name + " gameobject.");
                return;
            }

            // Set Defaults for Font Auto-sizing
            if (m_fontSizeMin == 0) m_fontSizeMin = m_fontSize / 2;
            if (m_fontSizeMax == 0) m_fontSizeMax = m_fontSize * 2;

            //// Set flags to ensure our text is parsed and text re-drawn. 
            isInputParsingRequired = true;
            havePropertiesChanged = true;
            m_rectTransformDimensionsChanged = true;
            //m_isCalculateSizeRequired = true;

            ForceMeshUpdate(); // Added to force OnWillRenderObject() to be called in case object is not visible so we get initial bounds for the mesh.
        }
Example #17
0
        public static IReadOnlyList <Element> GetChildren(this ILayoutController source)
        {
            _ = source ?? throw new ArgumentNullException(nameof(source));

            return(source.Children);
        }
Example #18
0
    /// <summary>
    /// 计算容器大小
    /// </summary>
    protected virtual void CaculateLayoutContainerSize()
    {
        Vector2 vec2 = Vector2.zero;

        totalWidth  = 0.0f;
        totalHeight = 0.0f;
        float maxWidth  = 0.0f;
        float maxHeight = 0.0f;

        foreach (var item in usingChildren)
        {
            //兼容LayoutElement
            ILayoutController layoutCtrl = item.GetComponent <ILayoutController>();
            if (layoutCtrl != null)
            {
                layoutCtrl.SetLayoutHorizontal();
                layoutCtrl.SetLayoutVertical();
            }

            Vector2       size    = item.rect.size;
            LayoutElement element = item.GetComponent <LayoutElement>();
            if (element != null)
            {
                size = new Vector2(element.preferredWidth, element.preferredHeight);
            }

            totalWidth  += size.x;
            totalHeight += size.y;
            maxWidth     = Mathf.Max(maxWidth, size.x);
            maxHeight    = Mathf.Max(maxHeight, size.y);
        }


        if (m_Direction == LayoutRule.Direction.Horizontal)
        {
            vec2.x = totalWidth + padding.horizontal + spacing.x * (usingChildren.Count - 1);
            vec2.y = maxHeight + padding.vertical;

            if (this.m_Stretch)
            {
                vec2.y = rectTransform.rect.size.y;
            }
        }

        else if (m_Direction == LayoutRule.Direction.Vertical)
        {
            vec2.x = maxWidth + padding.horizontal;
            vec2.y = totalHeight + padding.vertical + spacing.y * (usingChildren.Count - 1);

            if (this.m_Stretch)
            {
                vec2.x = rectTransform.rect.size.x;
            }
        }

        vec2 = Vector2.Max(minSize, vec2);

        if (ChildControlWidth)
        {
            rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, vec2.x);
        }

        if (ChildControlHeight)
        {
            rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, vec2.y);
        }
    }
Example #19
0
 public static IReadOnlyList <Element> GetChildren(this ILayoutController source) => source.Children;