Beispiel #1
0
        public void Render(IRenderable rootRenderable)
        {
            DebugMsg($"Rendering from {rootRenderable}", setDebugFlag: 1);

            var  newRoot    = rootRenderable.FinalizeRendering(_ => Render(rootRenderable));
            bool anyUpdates = false;

            Reconcile(ref root, newRoot, ref anyUpdates);

            root.Display.ParentFont = DisplaySystem.Fonts.Default;

            if (anyUpdates)
            {
                Walk(element =>
                {
                    element.OnReconciliationCompleted();
                    return(true);
                });
            }

            Style.Apply(root, DefaultTheme);

            Walk(element =>
            {
                element.Display.System = DisplaySystem;
                return(true);
            });
        }
Beispiel #2
0
 public static void Apply(this Style style, BindableObject bindable)
 {
     if (style == null)
     {
         throw new ArgumentNullException("style");
     }
     style.Apply(bindable);
 }
Beispiel #3
0
        public static void Init()
        {
            if (_hasInitialized)
            {
                return;
            }
            _hasInitialized = true;

            // Controls
            Registrar.Handlers.Register <ActivityIndicator, ActivityIndicatorHandler>();
            Registrar.Handlers.Register <Button, ButtonHandler>();
            Registrar.Handlers.Register <Image, ImageHandler>();
            Registrar.Handlers.Register <ProgressBar, ProgressBarHandler>();
            Registrar.Handlers.Register <SecureField, SecureFieldHandler>();
            Registrar.Handlers.Register <Slider, SliderHandler>();
            Registrar.Handlers.Register <RadioButton, RadioButtonHandler>();
            // Stepper
            Registrar.Handlers.Register <Text, TextHandler>();
            Registrar.Handlers.Register <TextField, TextFieldHandler>();
            Registrar.Handlers.Register <Toggle, ToggleHandler>();
            //Registrar.Handlers.Register<WebView, WebViewHandler> ();

            // Containers
            Registrar.Handlers.Register <ContentView, ContentViewHandler>();
            Registrar.Handlers.Register <ListView, ListViewHandler>();
            Registrar.Handlers.Register <ScrollView, ScrollViewHandler>();
            Registrar.Handlers.Register <View, ViewHandler>();
            Registrar.Handlers.Register <ViewRepresentable, ViewRepresentableHandler>();
            Registrar.Handlers.Register <TabView, TabViewHandler>();
            Registrar.Handlers.Register <NavigationView, NavigationViewHandler>();
            Registrar.Handlers.Register <RadioGroup, RadioGroupHandler>();

            // Layouts
            Registrar.Handlers.Register <HStack, HStackHandler>();
            Registrar.Handlers.Register <VStack, VStackHandler>();
            Registrar.Handlers.Register <ZStack, ZStackHandler>();
            Registrar.Handlers.Register <Grid, GridHandler>();
            Registrar.Handlers.Register <Spacer, SpacerHandler>();

            // Modal Support
            ModalView.PerformPresent = ModalManager.ShowModal;
            ModalView.PerformDismiss = ModalManager.DismisModal;

            // Device Services
            ThreadHelper.JoinableTaskContext = new Microsoft.VisualStudio.Threading.JoinableTaskContext();
            Device.GraphicsService           = new AndroidGraphicsService();
            Device.BitmapService             = new AndroidBitmapService();


            AnimationManger.SetTicker(new AndroidTicker());

            //Set Default Style
            var style = new Style();

            style.Apply();
        }
Beispiel #4
0
        private static void ApplyEnabledOrDisabled(Cell cell, Style enabled, Style disabled, Style selected)
        {
            if (cell.IsEnabled)
            {
                enabled.Apply(cell);

                return;
            }

            disabled.Apply(cell);
        }
Beispiel #5
0
 public static T ApplyStyle <T>(this T view, Style style) where T : ContextualObject
 {
     style.Apply(view);
     return(view);
 }
Beispiel #6
0
 public void ApplyStyle()
 {
     Style.Apply(this);
     Style.Apply(dataGridView1);
 }
Beispiel #7
0
		void AddElement (IList<Element> list, XElement e, Pen inheritPen, Brush inheritBrush)
		{
			//
			// Style
			//
			Element r = null;
            Style eStyle = new Style();
			ApplyStyle (e.Attributes ().ToDictionary (k => k.Name.LocalName, v => v.Value), eStyle);
			var style = ReadString (e.Attribute ("style"));
			if (!string.IsNullOrWhiteSpace (style)) {
				ApplyStyle (style, eStyle);
			}
            if (!eStyle.hasPen) eStyle.pen = inheritPen;
            if (!eStyle.hasBrush) eStyle.brush = inheritBrush;
            //var id = ReadString (e.Attribute ("id"));

            //
            // Elements
            //
            switch (e.Name.LocalName) {
			case "text":
				{
					var x = ReadNumber (e.Attribute ("x"));
					var y = ReadNumber (e.Attribute ("y"));
					var font = new Font ();
					var fontFamily = ReadTextFontFamily(e);
					if (!string.IsNullOrEmpty(fontFamily))
						font.Family = fontFamily;
					var fontSize = ReadTextFontSize(e);
					if (fontSize >= 0)
						font.Size = fontSize;
					TextAlignment textAlignment = ReadTextAlignment(e);
					var txt = new Text (new Rect (new Point (x, y), new Size (double.MaxValue, double.MaxValue)), font, textAlignment, eStyle.pen, eStyle.brush);
					ReadTextSpans (txt, e);
					r = txt;
				}
				break;
			case "rect":
				{
					var x = ReadNumber (e.Attribute ("x"));
					var y = ReadNumber (e.Attribute ("y"));
					var width = ReadNumber (e.Attribute ("width"));
					var height = ReadNumber (e.Attribute ("height"));
					var rx = ReadNumber (e.Attribute ("rx"));
					var ry = ReadNumber (e.Attribute ("ry"));
					if (ry == 0) {
						ry = rx;
					}
					r = new Rectangle (new Rect (new Point (x, y), new Size (width, height)), new Size (rx, ry), eStyle.pen, eStyle.brush);
				}
				break;
			case "ellipse":
				{
					var cx = ReadNumber (e.Attribute ("cx"));
					var cy = ReadNumber (e.Attribute ("cy"));
					var rx = ReadNumber (e.Attribute ("rx"));
					var ry = ReadNumber (e.Attribute ("ry"));
					r = new Ellipse (new Point (cx - rx, cy - ry), new Size (2 * rx, 2 * ry), eStyle.pen, eStyle.brush);
				}
				break;
			case "circle":
				{
					var cx = ReadNumber (e.Attribute ("cx"));
					var cy = ReadNumber (e.Attribute ("cy"));
					var rr = ReadNumber (e.Attribute ("r"));
					r = new Ellipse (new Point (cx - rr, cy - rr), new Size (2 * rr, 2 * rr), eStyle.pen, eStyle.brush);
				}
				break;

			case "path":
				{
					var dA = e.Attribute ("d");
					if (dA != null && !string.IsNullOrWhiteSpace (dA.Value)) {
						var p = new Path (eStyle.pen, eStyle.brush);
						ReadPath (p, dA.Value);
						r = p;
					}
				}
				break;
			case "polygon":
				{
					var pA = e.Attribute ("points");
					if (pA != null && !string.IsNullOrWhiteSpace (pA.Value)) {
						var path = new Path (eStyle.pen, eStyle.brush);
						ReadPoints (path, pA.Value, true);
						r = path;
					}
				}
				break;
			case "polyline":
				{
					var pA = e.Attribute ("points");
					if (pA != null && !string.IsNullOrWhiteSpace (pA.Value)) {
						var path = new Path (eStyle.pen, eStyle.brush);
						ReadPoints (path, pA.Value, false);
						r = path;
					}
				}
			break;
			case "g":
				{
					var g = new Group ();
					var groupId = e.Attribute("id");
					if (groupId != null && !string.IsNullOrEmpty(groupId.Value))
						g.Id = groupId.Value;
					AddElements (g.Children, e.Elements (), eStyle.pen, eStyle.brush);
					r = g;
				}
				break;
			case "use":
				{
					var href = ReadString (e.Attributes ().FirstOrDefault (x => x.Name.LocalName == "href"));
					if (!string.IsNullOrWhiteSpace (href)) {
						XElement useE;
						if (defs.TryGetValue (href.Trim ().Replace ("#", ""), out useE)) {
							var useList = new List<Element> ();
							AddElement (useList, useE, eStyle.pen, eStyle.brush);
							r = useList.FirstOrDefault ();
						}
					}
				}
				break;
			case "title":
				Graphic.Title = ReadString (e);
				break;
			case "desc":
			case "description":
				Graphic.Description = ReadString (e);
				break;
			case "defs":
				// Already read in earlier pass
				break;
			case "namedview":
			case "metadata":
			case "image":
				// Ignore
				break;

				case "line":
				{
					var x1 = ReadNumber ( e.Attribute("x1") );
					var x2 = ReadNumber ( e.Attribute("x2") );
					var y1 = ReadNumber ( e.Attribute("y1") );
					var y2 = ReadNumber ( e.Attribute("y2") );
					var p = new Path (eStyle.pen, null);
					p.MoveTo (x1, y1);
					p.LineTo (x2, y2);
					r = p;
				}
				break;

				case "foreignObject":
				{
					var x = ReadNumber ( e.Attribute("x") );
					var y = ReadNumber ( e.Attribute("y") );
					var width = ReadNumber ( e.Attribute("width") );
					var height = ReadNumber ( e.Attribute("height") );
					r = new ForeignObject(new Point(x, y), new Size(width, height));
				}
				break;

				case "pgf":
				{
					var id = e.Attribute("id");
					System.Diagnostics.Debug.WriteLine("Ignoring pgf element" + (id != null ? ": '" + id.Value + "'" : ""));
				}
				break;

				case "switch":
				{
					// Evaluate requiredFeatures, requiredExtensions and systemLanguage
					foreach (var ee in e.Elements())
					{
						var requiredFeatures = ee.Attribute("requiredFeatures");
						var requiredExtensions = ee.Attribute("requiredExtensions");
						var systemLanguage = ee.Attribute("systemLanguage");
						// currently no support for any of these restrictions
						if (requiredFeatures == null && requiredExtensions == null && systemLanguage == null)
							AddElement (list, ee, eStyle.pen, eStyle.brush);
					}
				}
				break;


				// color definition that can be referred to by other elements
				case "linearGradient":
				break;


			default:
				throw new NotSupportedException ("SVG element \"" + e.Name.LocalName + "\" is not supported");
			}

			if (r != null) {
                eStyle.Apply(r);
				r.Transform = ReadTransform (ReadString (e.Attribute ("transform")));
				var ida = e.Attribute("id");
				if (ida != null && !string.IsNullOrEmpty (ida.Value)) {
					r.Id = ida.Value.Trim ();
				}
				list.Add (r);
			}
		}
Beispiel #8
0
 private static void ApplySelected(Cell cell, Style enabled, Style disabled, Style selected)
 {
     selected.Apply(cell);
 }
Beispiel #9
0
 public void ApplyStyle()
 {
     Style.Apply(this);
 }
Beispiel #10
0
 protected override object InnerRun(List <Variable> variables)
 {
     style.Apply((Element)(element.SingleRun(variables)));
     return(null);
 }