Пример #1
0
        static IControl Create(IProperty <bool> enabled, Points circleRadius, Points additionalWidth)
        {
            double outlineThickness  = 1;
            Points backgroundPadding = 1;

            var enabledValue = enabled.Select(isEnabled => isEnabled ? 1.0 : 0.0).LowPass(0.3);

            var circleSize   = Size.Create(circleRadius);
            var cornerRadius = Observable.Return(new CornerRadius(circleRadius / 2.5));
            var circle       = Shapes.Circle(
                Stroke.Create(1.0, Theme.SwitchThumbStroke),
                Theme.SwitchThumbFill)
                               .WithSize(circleSize);

            var foreground = circle.WithPadding(
                enabledValue.Select(v => Thickness.Create <Points>(v * additionalWidth, 0, (1 - v) * additionalWidth, 0)));

            var backgroundStroke = Stroke.Create(
                Observable.Return(outlineThickness),
                Theme.SwitchInactiveStroke.Mix(Theme.SwitchActiveStroke, enabledValue),
                Observable.Return(StrokeDashArray.Solid));
            var backgroundBrush = Theme.SwitchInactiveBackground.Mix(Theme.SwitchActiveBackground, enabledValue);
            var background      = Shapes.Rectangle(
                backgroundStroke,
                backgroundBrush,
                cornerRadius);

            var content = foreground
                          .WithBackground((background.WithPadding(new Thickness <Points>(backgroundPadding))));

            return(Button.Create(
                       clicked: enabled.Toggle(),
                       content: buttonStates => content));
        }
Пример #2
0
 public static IObservable <Thickness <Points> > GetThickness(this PluginContext context, IObservable <object> observableUnoObject, string property)
 {
     return(context.ObservePerFrame(observableUnoObject, obj =>
     {
         var vector = context.Reflection.GetPropertyValue(obj, property) as dynamic;
         float l = vector.X;
         float t = vector.Y;
         float r = vector.Z;
         float b = vector.W;
         return Thickness.Create <Points>(l, t, r, b);
     })
            .Catch((Exception e) =>
     {
         Console.WriteLine(e);
         return Observable.Return(Thickness.Create <Points>(0, 0, 0, 0));
     })
            .DistinctUntilChanged()
            .Replay(1).RefCount());
 }
Пример #3
0
        public About(Version version, Debug debug)
        {
            var showAboutDialog = new BehaviorSubject <bool>(false);

            var thanksTo = "Created by:\n\n"
                           + "João Abecasis, Karina Asaevich, Christopher Bagley, Alexander Bladyko, Anders Bondehagen, Aaron Cohen, Liam Crouch, "
                           + "Håkon Martin Eide, Guro Faller, Erik Faye-Lund, Morten Daniel Fornes, Olle Fredriksson, Anette Gjetnes, Lorents Odin Gravås, "
                           + "Kristian Hasselknippe, Daniel Hollick, Erik Hvattum, Anders Schau Knatten, Anders Knive Lassen, Vegard Lende, Vika Lepeshinskaya, "
                           + "Sumi Lim, edA-qa mort-ora-y, Trond Arve Nordheim, Remi Johan Pedersen, Evgeny Razumov, Jonny Ree, Sebastian Reinhard, "
                           + "Jan Stefan Rimaila, Andreas Rønning, Emil Sandstø, Bent Stamnes, Karsten Nikolai Strand, Jake Taylor."
                           + "\n\n Fuse © 2017";

            Application.Desktop.CreateSingletonWindow(
                isVisible: showAboutDialog,
                window: dialog =>
                new Window
            {
                Title   = Observable.Return("About Fuse"),
                Content = Control.Lazy(() =>
                                       Layout.Dock()
                                       .Top(LogoAndVersion.Create(version).WithMacWindowStyleCompensation())
                                       .Bottom(CreateOkButton(Command.Enabled(() => dialog.Close())))
                                       .Bottom(Separator.Medium)
                                       .Fill(
                                           Label.Create(font: Theme.DefaultFont, color: Theme.DefaultText, lineBreakMode: LineBreakMode.Wrap, text: thanksTo)
                                           .OnMouse(debug.EnableDebugMenuByRapidClicking)
                                           .WithPadding(Thickness.Create(new Points(20), 10, 20, 10))
                                           ).WithBackground(Theme.PanelBackground)),
                Size       = Optional.Some(Property.Constant(Optional.Some(new Size <Points>(370, 520)))),
                Background = Theme.PanelBackground,
                Foreground = Theme.DefaultText,
                Border     = Separator.MediumStroke,
                Style      = WindowStyle.Fat
            }
                );

            Menu = Menu.Item("About Fuse", () => showAboutDialog.OnNext(true));
        }
Пример #4
0
        public static IControl WithPadding(
            this IControl control,
            IObservable <Points> left   = null,
            IObservable <Points> top    = null,
            IObservable <Points> right  = null,
            IObservable <Points> bottom = null)
        {
            var tmp = Thickness
                      .Create(left, top, right, bottom)
                      .FlipVerticallyOnMac();

            left   = tmp.Left;
            top    = tmp.Top;
            right  = tmp.Right;
            bottom = tmp.Bottom;

            control = control.WithFrame(
                frame =>
            {
                if (left != null)
                {
                    frame = Rectangle.FromPositionSize(frame.Position.X.Add(left), frame.Position.Y, frame.Width.Sub(left), frame.Height);
                }
                if (top != null)
                {
                    frame = Rectangle.FromPositionSize(frame.Position.X, frame.Position.Y.Add(top), frame.Width, frame.Height.Sub(top));
                }
                if (right != null)
                {
                    frame = Rectangle.FromPositionSize(frame.Position.X, frame.Position.Y, frame.Width.Sub(right), frame.Height);
                }
                if (bottom != null)
                {
                    frame = Rectangle.FromPositionSize(frame.Position.X, frame.Position.Y, frame.Width, frame.Height.Sub(bottom));
                }
                return(frame);
            },
                availableSize =>
            {
                if (left != null)
                {
                    availableSize = availableSize.WithAxis(Axis2D.Horizontal, p => p.Sub(left));
                }
                if (top != null)
                {
                    availableSize = availableSize.WithAxis(Axis2D.Vertical, p => p.Sub(top));
                }
                if (right != null)
                {
                    availableSize = availableSize.WithAxis(Axis2D.Horizontal, p => p.Sub(right));
                }
                if (bottom != null)
                {
                    availableSize = availableSize.WithAxis(Axis2D.Vertical, p => p.Sub(bottom));
                }
                return(availableSize);
            });

            var desiredSize = control.DesiredSize;

            if (left != null)
            {
                desiredSize = desiredSize.WithAxis(Axis2D.Horizontal, p => p.Add(left));
            }
            if (top != null)
            {
                desiredSize = desiredSize.WithAxis(Axis2D.Vertical, p => p.Add(top));
            }
            if (right != null)
            {
                desiredSize = desiredSize.WithAxis(Axis2D.Horizontal, p => p.Add(right));
            }
            if (bottom != null)
            {
                desiredSize = desiredSize.WithAxis(Axis2D.Vertical, p => p.Add(bottom));
            }

            return(control.WithSize(desiredSize));
        }