<commit_before>﻿using MatterHackers.Agg.VertexSource;
using MatterHackers.VectorMath;
using System;
using MatterHackers.Agg.Image;

namespace MatterHackers.Agg.UI
{
	public class RadioCircleWidget : GuiWidget
	{
		private double boxWidth = 10 * GuiWidget.DeviceScale;
		private double borderRadius;
		private Vector2 center;

		public RadioCircleWidget()
		{
			this.MinimumSize = new Vector2(boxWidth + 1, boxWidth + 1);
			this.DoubleBuffer = true;
			//this.BackBuffer.SetRecieveBlender(new BlenderPreMultBGRA());

			this.Margin = new BorderDouble(right: 10);

			center = this.LocalBounds.Center;
			borderRadius = boxWidth / 2;
		}

		public RadioButton RadioButton { get; set; }

		public override void OnDraw(Graphics2D graphics2D)
		{
			if (this.RadioButton == null)
			{
				return;
			}

			// Radio check
			if (true || this.RadioButton.Checked )
			{
				graphics2D.Circle(center, boxWidth / 4, this.RadioButton.TextColor);
			}

			// Radio border
			int strokeWidth = (this.RadioButton.MouseDownOnButton && this.RadioButton.FirstWidgetUnderMouse) ? 2 : 1;
			graphics2D.Render(
				new Stroke(new Ellipse(center, borderRadius), strokeWidth), 
				this.RadioButton.TextColor);

			base.OnDraw(graphics2D);
		}
	}
	
	public class RadioButtonViewText : FlowLayoutWidget
	{
		protected TextWidget labelTextWidget;

		protected RadioCircleWidget radioCircle;

		public RadioButtonViewText(string label, int fontSize=12)
		{
			radioCircle = new RadioCircleWidget();
			this.AddChild(radioCircle);

			labelTextWidget = new TextWidget(label, fontSize);
			this.AddChild(labelTextWidget);
		}

		public override void OnParentChanged(EventArgs e)
		{
			if (Parent is RadioButton radioButton)
			{
				radioButton.MouseEnter += redrawButtonIfRequired;
				radioButton.MouseDown += redrawButtonIfRequired;
				radioButton.MouseUp += redrawButtonIfRequired;
				radioButton.MouseLeave += redrawButtonIfRequired;

				radioCircle.RadioButton = radioButton;
				radioButton.TextColor = ActiveTheme.Instance.PrimaryTextColor;
			}
			base.OnParentChanged(e);
		}

		public void redrawButtonIfRequired(object sender, EventArgs e)
		{
			((GuiWidget)sender).Invalidate();
		}

		public override string Text
		{
			get => labelTextWidget.Text;
			set => labelTextWidget.Text = value;<commit_msg>Remove constant checked state, fix radio controls to reset on change<commit_after>﻿using System;
using MatterHackers.Agg.VertexSource;
using MatterHackers.VectorMath;

namespace MatterHackers.Agg.UI
{
	public class RadioCircleWidget : GuiWidget
	{
		private double boxWidth = 10 * GuiWidget.DeviceScale;
		private double borderRadius;
		private Vector2 center;

		public RadioCircleWidget()
		{
			this.MinimumSize = new Vector2(boxWidth + 1, boxWidth + 1);
			this.DoubleBuffer = true;
			this.Margin = new BorderDouble(right: 10);

			center = this.LocalBounds.Center;
			borderRadius = boxWidth / 2;
		}

		public RadioButton RadioButton { get; set; }

		public override void OnDraw(Graphics2D graphics2D)
		{
			if (this.RadioButton == null)
			{
				return;
			}

			// Radio check
			if (this.RadioButton.Checked)
			{
				graphics2D.Circle(center, boxWidth / 4, this.RadioButton.TextColor);
			}

			// Radio border
			int strokeWidth = (this.RadioButton.MouseDownOnButton && this.RadioButton.FirstWidgetUnderMouse) ? 2 : 1;
			graphics2D.Render(
				new Stroke(new Ellipse(center, borderRadius), strokeWidth), 
				this.RadioButton.TextColor);

			base.OnDraw(graphics2D);
		}
	}
	
	public class RadioButtonViewText : FlowLayoutWidget
	{
		protected TextWidget labelTextWidget;

		protected RadioCircleWidget radioCircle;

		protected RadioButton radioButton;

		public RadioButtonViewText(string label, int fontSize=12)
		{
			radioCircle = new RadioCircleWidget();
			this.AddChild(radioCircle);

			labelTextWidget = new TextWidget(label, fontSize);
			this.AddChild(labelTextWidget);
		}

		public override void OnParentChanged(EventArgs e)
		{
			if (Parent is RadioButton radioButton)
			{
				this.radioButton = radioButton;
				radioButton.MouseEnter += redrawButtonIfRequired;
				radioButton.MouseDown += redrawButtonIfRequired;
				radioButton.MouseUp += redrawButtonIfRequired;
				radioButton.MouseLeave += redrawButtonIfRequired;
				radioButton.CheckedStateChanged += (s, e2) =>
				{
					// Invalidate double buffered control
					radioCircle.Invalidate();
				};

				radioCircle.RadioButton = radioButton;
				radioButton.TextColor = ActiveTheme.Instance.PrimaryTextColor;
			}
			base.OnParentChanged(e);
		}

		public void redrawButtonIfRequired(object sender, EventArgs e)
		{
			((GuiWidget)sender).Invalidate();
		}

		public override string Text
		{
			get => labelTextWidget.Text;
			set => labelTextWidget.Text = value;
{'fraction_non_alphanumeric': 0.09180880185302169, 'fraction_numerical': 0.0082122552116235, 'mean_word_length': 4.03711558854719, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1673134', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1430, 'n_words': 313}