Skip to content

Commit

Permalink
Added a helper for horizontal slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron C Robinson committed Sep 12, 2017
1 parent 16d40b5 commit b615a38
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions ModWindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,37 @@ public static class ModWindowHelper
{
static float topPad = 30f;
static float leftPad = 0f;
static float vspacing = 30f; // same as radioListItemHeight
static float textFieldPadding = 10f; // same as radioListItemHeight
static float vspacing = 30f;
static float textFieldPadding = 10f;
static float horizontalSliderPadding = 10f;
static float curY = topPad;
static float curX = leftPad;

static float horizontalSliderHeight = 60f;
static float radioListItemHeight = 30f;

// NOTE: could get away from this if went with an instance...
static public void Reset()
public static void Reset()
{
curY = topPad;
curX = leftPad;
}

static public void MakeLabel(Rect inRect, string label)
public static float HorizontalSlider(Rect rect, float value, float leftValue, float rightValue, bool middleAlignment = false, string label = null, string leftAlignedLabel = null, string rightAlignedLabel = null, float roundTo = -1f)
{
curY += horizontalSliderPadding;
Rect r = GetRect(horizontalSliderHeight, rect.width);
float val = Widgets.HorizontalSlider(r, value, leftValue, rightValue, middleAlignment, label, leftAlignedLabel, rightAlignedLabel, roundTo);
curY += horizontalSliderPadding;
return val;
}

public static void MakeLabel(Rect inRect, string label)
{
MakeLabel(inRect.width - 64f, label);
}

static public void MakeLabeledTextField(Rect inRect, string label, ref string val)
public static void MakeLabeledTextField(Rect inRect, string label, ref string val)
{
curY += textFieldPadding;
Widgets.Label(new Rect(0f, curY + 5f, inRect.width - 16f, 40f), label);
Expand All @@ -36,34 +49,33 @@ static public void MakeLabeledTextField(Rect inRect, string label, ref string va
}

// TODO: rewrite this -> it's ugly.
static public void MakeTextFieldNumericLabeled<T>(Rect inRect, string label, ref T val, ref string buffer, float min, float max) where T : struct
public static void MakeTextFieldNumericLabeled<T>(Rect inRect, string label, ref T val, ref string buffer, float min, float max) where T : struct
{
curY += textFieldPadding;
Widgets.TextFieldNumericLabeled<T>(new Rect(0f, curY + 5f, inRect.width - 16f, 40f), label, ref val, ref buffer, min, max);
curY += vspacing + textFieldPadding;
}

static private void MakeLabel(float width, string label)
private static void MakeLabel(float width, string label)
{
Widgets.Label(new Rect(0f, curY + 5f, width - 16f, 40f), label);
curY += vspacing;
}

static public void MakeLabeledCheckbox(Rect inRect, string label, ref bool val)
public static void MakeLabeledCheckbox(Rect inRect, string label, ref bool val)
{
MakeLabeledCheckbox(inRect.width, label, ref val);
}

static private void MakeLabeledCheckbox(float width, string label, ref bool val)
private static void MakeLabeledCheckbox(float width, string label, ref bool val)
{
// NOTE: consider breaking out more of these numbers
Widgets.Label(new Rect(0f, curY + 5f, width - 16f, 40f), label);
Widgets.Checkbox(width - 64f, curY + 6f, ref val);
curY += vspacing;
}

static float radioListItemHeight = 30f;
static public void MakeLabeledRadioList<T>(Rect inRect, List<LabeledRadioValue<T>> items, ref T val)
public static void MakeLabeledRadioList<T>(Rect inRect, List<LabeledRadioValue<T>> items, ref T val)
{
foreach (LabeledRadioValue<T> item in items)
{
Expand All @@ -78,12 +90,12 @@ static public void MakeLabeledRadioList<T>(Rect inRect, List<LabeledRadioValue<T
}

// NOTE: consider using an enum...
static public void MakeLabeledRadioList(Rect inRect, string[] labels, ref string val)
public static void MakeLabeledRadioList(Rect inRect, string[] labels, ref string val)
{
MakeLabeledRadioList<string>(inRect, GenerateLabeledRadioValues(labels), ref val);
}

static public List<LabeledRadioValue<string>> GenerateLabeledRadioValues(string[] labels)
public static List<LabeledRadioValue<string>> GenerateLabeledRadioValues(string[] labels)
{
List<LabeledRadioValue<string>> list = new List<LabeledRadioValue<string>>();
foreach (string label in labels)
Expand All @@ -93,13 +105,13 @@ static public List<LabeledRadioValue<string>> GenerateLabeledRadioValues(string[
return list;
}

static public void MakeLabeledRadioList<T>(Rect inRect, Dictionary<string, T> dict, ref T val)
public static void MakeLabeledRadioList<T>(Rect inRect, Dictionary<string, T> dict, ref T val)
{
MakeLabeledRadioList<T>(inRect, GenerateLabeledRadioValues<T>(dict), ref val);
}

// (label, value) => (key, value)
static public List<LabeledRadioValue<T>> GenerateLabeledRadioValues<T>(Dictionary<string, T> dict)
public static List<LabeledRadioValue<T>> GenerateLabeledRadioValues<T>(Dictionary<string, T> dict)
{
List<LabeledRadioValue<T>> list = new List<LabeledRadioValue<T>>();
foreach (KeyValuePair<string, T> entry in dict)
Expand Down Expand Up @@ -133,7 +145,7 @@ public T Value
}
}

static public Rect GetRect(float height, float width)
public static Rect GetRect(float height, float width)
{
// NOTE: come back to the concept of `ColumnWidth`
Rect result = new Rect(curX, curY, width, height);
Expand Down

0 comments on commit b615a38

Please sign in to comment.