/// <summary> /// Create a vertical slider that user can drag to select a value. /// </summary> /// <param name="rect">position and size of the control</param> /// <param name="label">label</param> /// <param name="value">The value the slider shows.</param> /// <param name="minValue">The value at the top end of the slider.</param> /// <param name="maxValue">The value at the bottom end of the slider.</param> /// <returns>The value set by the user.</returns> /// <remarks>minValue <= value <= maxValue</remarks> public static double VSlider(Rect rect, string label, double value, double minValue, double maxValue) { var g = GetCurrentContext(); var window = GetCurrentWindow(); if (window.SkipItems) { return(0); } //get or create the root node var id = window.GetID(label); var container = window.AbsoluteVisualList; var node = (Node)container.Find(visual => visual.Id == id); var text = Utility.FindRenderedText(label); if (node == null) { node = new Node(id, $"VSlider<{label}>"); container.Add(node); node.UseBoxModel = true; node.RuleSet.Replace(GUISkin.Current[GUIControlName.Slider]); } node.ActiveSelf = true; // rect node.Rect = window.GetRect(rect); // interact var spacing = node.RuleSet.Get <double>("ControlLabelSpacing"); var labelHeight = node.RuleSet.Get <double>("LabelHeight"); var sliderHeight = rect.Height - spacing - labelHeight; if (sliderHeight <= 0) { sliderHeight = 1; } var sliderRect = new Rect(node.Rect.X, node.Rect.Y, node.Rect.Width, sliderHeight); value = GUIBehavior.SliderBehavior(sliderRect, id, false, value, minValue, maxValue, out var hovered, out _); // render var state = GUIState.Normal; if (hovered) { state = GUIState.Hover; } if (g.ActiveId == id && Mouse.Instance.LeftButtonState == KeyState.Down) { state = GUIState.Active; } GUIAppearance.DrawVSlider(node, label, value, minValue, maxValue, state, sliderRect, labelHeight); return(value); }
/// <summary> /// Create a vertical slider that user can drag to select a value. /// </summary> /// <param name="rect">position and size of the control</param> /// <param name="label">label</param> /// <param name="value">The value the slider shows.</param> /// <param name="minValue">The value at the top end of the slider.</param> /// <param name="maxValue">The value at the bottom end of the slider.</param> /// <returns>The value set by the user.</returns> /// <remarks>minValue <= value <= maxValue</remarks> public static double VSlider(Rect rect, string label, double value, double minValue, double maxValue) { GUIContext g = GetCurrentContext(); Window window = GetCurrentWindow(); if (window.SkipItems) { return(value); } int id = window.GetID(label); // rect rect = window.GetRect(rect); // interact var spacing = GUISkin.Instance.InternalStyle.Get <double>(GUIStyleName._ControlLabelSpacing); var labelHeight = GUISkin.Instance.InternalStyle.Get <double>(GUIStyleName._LabelHeight); var sliderHeight = rect.Height - spacing - labelHeight; if (sliderHeight <= 0) { sliderHeight = 1; } var sliderRect = new Rect(rect.X, rect.Y, rect.Width, sliderHeight); bool hovered, held; value = GUIBehavior.SliderBehavior(sliderRect, id, false, value, minValue, maxValue, out hovered, out held); // render var state = GUIState.Normal; if (hovered) { state = GUIState.Hover; } if (g.ActiveId == id && Mouse.Instance.LeftButtonState == KeyState.Down) { state = GUIState.Active; } GUIAppearance.DrawVSlider(rect, label, value, minValue, maxValue, state, sliderRect, labelHeight); return(value); }
/// <summary> /// Create an auto-layout vertical slider that user can drag to select a value. /// </summary> /// <param name="label">label of the slider</param> /// <param name="value">The value the slider shows.</param> /// <param name="minValue">The value at the top end of the slider.</param> /// <param name="maxValue">The value at the bottom end of the slider.</param> /// <returns>The value set by the user.</returns> /// <remarks>minValue <= value <= maxValue</remarks> public static double VSlider(string label, double value, double minValue, double maxValue) { GUIContext g = GetCurrentContext(); Window window = GetCurrentWindow(); if (window.SkipItems) { return(value); } var id = window.GetID(label); // style apply var style = GUIStyle.Basic; // rect Size size = style.CalcSize(label, GUIState.Normal); style.PushStretchFactor(true, 1);//+1 { var minSilderHeight = 200; size.Width = 20; size.Height += minSilderHeight; } var rect = window.GetRect(id); // interact var spacing = GUISkin.Instance.InternalStyle.Get <double>(GUIStyleName._ControlLabelSpacing); var labelHeight = GUISkin.Instance.InternalStyle.Get <double>(GUIStyleName._LabelHeight); var sliderHeight = rect.Height - spacing - labelHeight; if (sliderHeight <= 0) { sliderHeight = 1; } var sliderRect = new Rect(rect.X, rect.Y, rect.Width, sliderHeight); bool hovered, held; value = GUIBehavior.SliderBehavior(sliderRect, id, false, value, minValue, maxValue, out hovered, out held); // render var state = GUI.Normal; if (hovered) { state = GUI.Hover; } if (g.ActiveId == id && Mouse.Instance.LeftButtonState == KeyState.Down) { state = GUI.Active; } GUIAppearance.DrawVSlider(rect, label, value, minValue, maxValue, state, sliderRect, labelHeight); // style restore style.PopStyle();//-1 return(value); }
/// <summary> /// Create an auto-layout vertical slider that user can drag to select a value. /// </summary> /// <param name="label">label of the slider</param> /// <param name="value">The value the slider shows.</param> /// <param name="minValue">The value at the top end of the slider.</param> /// <param name="maxValue">The value at the bottom end of the slider.</param> /// <returns>The value set by the user.</returns> /// <remarks>minValue <= value <= maxValue</remarks> public static double VSlider(string label, double value, double minValue, double maxValue) { var g = GetCurrentContext(); var window = GetCurrentWindow(); if (window.SkipItems) { return(0); } //get or create the root node var id = window.GetID(label); var container = window.RenderTree.CurrentContainer; var node = container.GetNodeById(id); var text = Utility.FindRenderedText(label); if (node == null) { node = new Node(id, $"Slider<{label}>"); node.UseBoxModel = true; node.RuleSet.Replace(GUISkin.Current[GUIControlName.Slider]); var size = node.RuleSet.CalcContentBoxSize(text, GUIState.Normal); var minSilderHeight = 200; size.Width = 20; size.Height += minSilderHeight; node.AttachLayoutEntry(size); } container.AppendChild(node); node.ActiveSelf = true; // rect node.Rect = window.GetRect(id); // interact var spacing = node.RuleSet.Get <double>("ControlLabelSpacing"); var labelHeight = node.RuleSet.Get <double>("LabelHeight"); var sliderHeight = node.Rect.Height - spacing - labelHeight; if (sliderHeight <= 0) { sliderHeight = 1; } var sliderRect = new Rect(node.Rect.Location, node.Rect.Width, sliderHeight); value = GUIBehavior.SliderBehavior(sliderRect, id, false, value, minValue, maxValue, out var hovered, out var held); var state = GUI.Normal; if (hovered) { state = GUI.Hover; } if (g.ActiveId == id && Mouse.Instance.LeftButtonState == KeyState.Down) { state = GUI.Active; } // last item state window.TempData.LastItemState = node.State; // render GUIAppearance.DrawVSlider(node, label, value, minValue, maxValue, state, sliderRect, labelHeight); return(value); }