示例#1
0
        public static IControl Debug(this IControl ctrl, string name, [CallerFilePath] string filepath = "", [CallerLineNumber] int lineNumber = 0)
        {
#if DEBUG
            var location = new ReplaySubject <IMountLocation>(1);
            ctrl = ctrl.WithMountLocation(
                oldLocation =>
            {
                location.OnNext(oldLocation);
                return(oldLocation);
            });

            var debugCtrl = new DebugControl(
                name,
                ctrl,
                location.Select(l => l.NativeFrame).Switch(),
                location.Select(l => l.AvailableSize).Switch(),
                AbsoluteFilePath.Parse(filepath),
                lineNumber);

            DebugControls.OnNext(DebugControls.Value.SetItem(debugCtrl.Name, debugCtrl));

            var selected = Command.Enabled(action: () => SelectedControl.OnNext(name));

            return(ctrl.WithOverlay(
                       SelectedControl.StartWithNone()
                       .Select(selCtrl => selCtrl.MatchWith(n => n == name, () => false))
                       .Select(isSelected => isSelected
                                                ? Shapes.Rectangle(stroke: Stroke.Create(2, Color.FromBytes(0x6d, 0xc0, 0xd2)), fill: Color.FromBytes(0x6d, 0xc0, 0xd2, 50))
                                                : Shapes.Rectangle().OnMouse(pressed: selected))
                       .Switch()
                       ));
#else
            return(ctrl);
#endif
        }