/// <remarks> /// Note: Design of a toggle /// |←16→| /// | |---------------+ /// | | | /// +----+ | /// | √ | label | /// +----+ | /// | | /// +---------------+ /// </remarks> public static void DrawToggle(Rect rect, string label, bool value, GUIState state) { GUIContext g = Form.current.uiContext; WindowManager w = g.WindowManager; Window window = w.CurrentWindow; GUIStyle style = GUIStyle.Basic; DrawList d = window.DrawList; var spacing = GUISkin.Instance.InternalStyle.Get <double>(GUIStyleName._ControlLabelSpacing); var boxRect = new Rect(rect.X, rect.Y + MathEx.ClampTo0(rect.Height - 16) / 2, 16, 16); var textRect = new Rect(rect.X + 16 + spacing, rect.Y, MathEx.ClampTo0(rect.Width - 16 - spacing), rect.Height); // box var filledBoxColor = Color.Rgb(0, 151, 167); var boxBorderColor = Color.White; var tickColor = Color.Rgb(48, 48, 48); d.AddRectFilled(boxRect.TopLeft, boxRect.BottomRight, filledBoxColor); //□ d.AddRect(boxRect.TopLeft, boxRect.BottomRight, boxBorderColor, 0, 0, 2); //□ if (value) //√ { var h = boxRect.Height; d.PathMoveTo(new Point(0.125f * h + boxRect.X, 0.50f * h + boxRect.Y)); d.PathLineTo(new Point(0.333f * h + boxRect.X, 0.75f * h + boxRect.Y)); d.PathLineTo(new Point(0.875f * h + boxRect.X, 0.25f * h + boxRect.Y)); d.PathStroke(tickColor, false, 2); } // label d.DrawBoxModel(textRect, label, style, state); }
/// <remarks> /// Note: Design of a toggle /// |←16→| /// | |---------------+ /// | | | /// +----+ | /// | √ | label | /// +----+ | /// | | /// +---------------+ /// </remarks> public static void DrawToggle(Node node, string label, bool value, GUIState state) { var rect = node.Rect; var spacing = StyleRuleSet.Global.Get <double>("ControlLabelSpacing"); var boxRect = new Rect(rect.X, rect.Y + MathEx.ClampTo0(rect.Height - 16) / 2, 16, 16); var labelRect = new Rect(rect.X + 16 + spacing, rect.Y, MathEx.ClampTo0(rect.Width - 16 - spacing), rect.Height); // box var filledBoxColor = Color.Rgb(0, 151, 167); var boxBorderColor = Color.White; var tickColor = Color.Rgb(48, 48, 48); using (var dc = node.RenderOpen()) { dc.DrawRectangle(new Brush(filledBoxColor), new Pen(boxBorderColor, 1), boxRect); //□ if (value) //√ { var h = boxRect.Height; var tick = new PathGeometry(); var figure = new PathFigure(); figure.StartPoint = new Point(0.125f * h + boxRect.X, 0.50f * h + boxRect.Y); figure.Segments.Add(new LineSegment(new Point(0.333f * h + boxRect.X, 0.75f * h + boxRect.Y), true)); figure.Segments.Add(new LineSegment(new Point(0.875f * h + boxRect.X, 0.25f * h + boxRect.Y), true)); figure.IsFilled = false; tick.Figures.Add(figure); dc.DrawGeometry(null, new Pen(tickColor, 2), tick); } // label dc.DrawBoxModel(label, node.RuleSet, labelRect); } }