예제 #1
0
        public static Element Create(Element parent, bool on = false, Action <Element> onToggled = null)
        {
            var toggleSwitch = Element.Create(parent);

            ButtonBehavior.Add(toggleSwitch);
            toggleSwitch.Size = new Vec2(36, 16);
            toggleSwitch.Draw = dc => Draw(dc);
            toggleSwitch.OnInserted(e => OnInserted(e));
            toggleSwitch.OnDepthDescent(e => OnDepthDescent(e));
            if (onToggled != null)
            {
                toggleSwitch.Set(new ButtonCallback {
                    OnClick = onToggled
                });
            }
            var state  = toggleSwitch.GetOrCreateState <ToggleSwitchState>();
            var target = on ? 1f : 0f;

            if (Math.Abs(target - state.Target) > 0.000001f)
            {
                state.Start  = state.Pos;
                state.Target = target;
                state.T0     = toggleSwitch.Context.Input.Time;
                state.T1     = state.T0 + Math.Abs(state.Target - state.Pos) * 0.15;
            }
            return(toggleSwitch);
        }
예제 #2
0
        public static Element Create(Element parent, string text, Action <Element> onClick = null)
        {
            var button = Label.Create(parent, text, Color.White, TextAlignment.Center);

            ButtonBehavior.Add(button);
            button.SizeToFit = false;
            button.Draw      = dc => Draw(dc);
            if (onClick != null)
            {
                button.Set(new ButtonCallback {
                    OnClick = onClick
                });
            }
            return(button);
        }