Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions GHUI/BuildCheckBoxComponent.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using GHUI.Classes;
using Grasshopper.Kernel;

namespace GHUI
{
public class BuildCheckBoxComponent : GH_Component
public class BuildCheckBoxComponent : GH_ComponentTemplate
{
private bool _value = false;
private string _label;

/// <summary>
/// Component for building a HTML checkbox input component.
/// </summary>
Expand All @@ -17,49 +21,29 @@ public BuildCheckBoxComponent()

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "name", "The name of the checkbox input component.", GH_ParamAccess.item,
"checkbox");
pManager.AddTextParameter("ID", "id", "The id of the checkbox input component.", GH_ParamAccess.item,
"checkbox");
RegisterDefaultInputParams(pManager);
pManager.AddBooleanParameter("Value", "val", "The starting value of the checkbox input component.",
GH_ParamAccess.item, false);
pManager.AddTextParameter("Label", "label", "The starting label of the checkbox input component.",
GH_ParamAccess.item, "");
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
GH_ParamAccess.item,
"");
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddTextParameter("HTML", "html", "The HTML code for the created checkbox input.",
GH_ParamAccess.list);
}

protected override void SolveInstance(IGH_DataAccess da)
{
// get input from gh component inputs
string name = null;
string id = null;
bool value = false;
string label = null;
string cssStyle = null;

da.GetData(0, ref name);
da.GetData(1, ref id);
da.GetData(2, ref value);
da.GetData(3, ref label);
da.GetData(4, ref cssStyle);
GetStandardInputs(da);
da.GetData("Value", ref _value);
da.GetData("Label", ref _label);

string textString =
$"<input type='checkbox' id='{id}' name='{name}' checked='{value}' style='{cssStyle}'>";
string checkboxHtml =
$"<input type='checkbox' id='{id}' name='{name}' checked='{_value}' style='{cssStyle}'>";

if (label != "")
if (_label != "")
{
textString = textString + $"<label for='{id}' id='{id}-label' >{label}</label>";
checkboxHtml += $"<label for='{id}' id='{id}-label' >{_label}</label>";
}

da.SetData(0, textString);
da.SetData(0, checkboxHtml);
}

protected override System.Drawing.Bitmap Icon => Properties.Resources.checkbox;
Expand Down
37 changes: 10 additions & 27 deletions GHUI/BuildColorComponent.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using GHUI.Classes;
using Grasshopper.Kernel;

namespace GHUI
{
public class BuildColorComponent : GH_Component
public class BuildColorComponent : GH_ComponentTemplate
{
private string _value;

/// <summary>
/// Component for building a HTML color input component.
/// </summary>
Expand All @@ -17,40 +20,20 @@ public BuildColorComponent()

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "name", "The name of the color input component.", GH_ParamAccess.item,
"color");
pManager.AddTextParameter("ID", "id", "The id of the color input component.", GH_ParamAccess.item,
"color");
RegisterDefaultInputParams(pManager);
pManager.AddTextParameter("Value", "val", "The starting value of the color input component.",
GH_ParamAccess.item, "");
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
GH_ParamAccess.item,
"");
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddTextParameter("HTML", "html", "The HTML code for the created color input.",
GH_ParamAccess.list);
}

protected override void SolveInstance(IGH_DataAccess da)
{
// get input from gh component inputs
string name = null;
string id = null;
string value = null;
string cssStyle = null;

da.GetData(0, ref name);
da.GetData(1, ref id);
da.GetData(2, ref value);
da.GetData(3, ref cssStyle);
GetStandardInputs(da);
da.GetData("Value", ref _value);

string textString =
$"<input type='color' id='{id}' name='{name}' value='{value}' style='{cssStyle}'>";
string colorInputHtml =
$"<input type='color' id='{id}' name='{name}' value='{_value}' style='{cssStyle}'>";

da.SetData(0, textString);
da.SetData(0, colorInputHtml);
}

protected override System.Drawing.Bitmap Icon => Properties.Resources.color;
Expand Down
41 changes: 12 additions & 29 deletions GHUI/BuildDateComponent.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System;
using GHUI.Classes;
using Grasshopper.Kernel;

namespace GHUI
{
public class BuildDateComponent : GH_Component
public class BuildDateComponent : GH_ComponentTemplate
{
private string _value;
private string _min;
private string _max;

/// <summary>
/// Component for building a HTML date input component.
/// </summary>
Expand All @@ -17,46 +22,24 @@ public BuildDateComponent()

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "name", "The name of the date input component.", GH_ParamAccess.item,
"date");
pManager.AddTextParameter("ID", "id", "The id of the date input component.", GH_ParamAccess.item,
"date");
RegisterDefaultInputParams(pManager);
pManager.AddTextParameter("Value", "val", "The starting value of the date input component.",
GH_ParamAccess.item, "");
pManager.AddTextParameter("Min", "min", "The min value of the date input component.",
GH_ParamAccess.item, "1900-12-31");
pManager.AddTextParameter("Max", "max", "The max value of the date input component.",
GH_ParamAccess.item, "2021-01-02");
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
GH_ParamAccess.item,
"");
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddTextParameter("HTML", "html", "The HTML code for the created date input.",
GH_ParamAccess.list);
}

protected override void SolveInstance(IGH_DataAccess da)
{
// get input from gh component inputs
string name = null;
string id = null;
string value = null;
string min = null;
string max = null;
string cssStyle = null;

da.GetData(0, ref name);
da.GetData(1, ref id);
da.GetData(2, ref value);
da.GetData(3, ref min);
da.GetData(4, ref max);
da.GetData(4, ref cssStyle);
GetStandardInputs(da);
da.GetData("Value", ref _value);
da.GetData("Min", ref _min);
da.GetData("Max", ref _max);

string textString =
$"<input type='date' id='{id}' name='{name}' value='{value}' min='{min}' max='{max}' style='{cssStyle}'>";
$"<input type='date' id='{id}' name='{name}' value='{_value}' min='{_min}' max='{_max}' style='{cssStyle}'>";

da.SetData(0, textString);
}
Expand Down
45 changes: 16 additions & 29 deletions GHUI/BuildImageComponent.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System;
using GHUI.Classes;
using Grasshopper.Kernel;

namespace GHUI
{
public class BuildImageComponent : GH_Component
public class BuildImageComponent : GH_ComponentTemplate
{
private string _url;
private double _width = 300;
private double _height = 300;

/// <summary>
/// Component for building a HTML image component.
/// </summary>
Expand All @@ -17,42 +22,24 @@ public BuildImageComponent()

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "name", "The name of the image component.", GH_ParamAccess.item,
"image");
pManager.AddTextParameter("ID", "id", "The id of the image component.", GH_ParamAccess.item,
"image");
RegisterDefaultInputParams(pManager);
pManager.AddTextParameter("URL", "url", "The url of the image to show.",
GH_ParamAccess.item, "https://vuejs.org/images/logo.png");
pManager.AddNumberParameter("Height", "height", "The desired height of the image (pixels).", GH_ParamAccess.item, 300);
pManager.AddNumberParameter("Width", "width", "The desired width of the image (pixels).", GH_ParamAccess.item, 300);
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
GH_ParamAccess.item, "");
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddTextParameter("HTML", "html", "The HTML code for the created image input.",
GH_ParamAccess.list);
pManager.AddNumberParameter("Height", "height", "The desired height of the image (pixels).",
GH_ParamAccess.item, 300);
pManager.AddNumberParameter("Width", "width", "The desired width of the image (pixels).",
GH_ParamAccess.item, 300);
}

protected override void SolveInstance(IGH_DataAccess da)
{
string name = null;
string id = null;
string url = null;
double height = 200;
double width = 200;
string cssStyle = null;

da.GetData(0, ref name);
da.GetData(1, ref id);
da.GetData(2, ref url);
da.GetData(3, ref height);
da.GetData(4, ref width);
da.GetData(5, ref cssStyle);
GetStandardInputs(da);
da.GetData("URL", ref _url);
da.GetData("Width", ref _width);
da.GetData("Height", ref _height);

string textString =
$"<img id='{id}' height='{height}' width='{width}' src='{url}' alt='{name}'>";
$"<img id='{id}' height='{_height}' width='{_width}' src='{_url}' alt='{name}'>";

da.SetData(0, textString);
}
Expand Down
37 changes: 10 additions & 27 deletions GHUI/BuildLabelComponent.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using GHUI.Classes;
using Grasshopper.Kernel;

namespace GHUI
{
public class BuildLabelComponent : GH_Component
public class BuildLabelComponent : GH_ComponentTemplate
{
private string _value;
private double _scale;

/// <summary>
/// Component for building a HTML header component.
/// </summary>
Expand All @@ -17,43 +21,22 @@ public BuildLabelComponent()

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("Name", "name", "The name of the header component.", GH_ParamAccess.item,
"header");
pManager.AddTextParameter("ID", "id", "The id of the header component.", GH_ParamAccess.item,
"header");
RegisterDefaultInputParams(pManager);
pManager.AddTextParameter("Value", "val", "The starting value of the header component.",
GH_ParamAccess.item, "header");
pManager.AddNumberParameter("Scale", "scale", "The scale of heading to create (1-4).",
GH_ParamAccess.item, 1);
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
GH_ParamAccess.item,
"");
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddTextParameter("HTML", "html", "The HTML code for the created header input.",
GH_ParamAccess.list);
}

protected override void SolveInstance(IGH_DataAccess da)
{
// get input from gh component inputs
string name = null;
string id = null;
string value = null;
double scale = 1;
string cssStyle = null;

da.GetData(0, ref name);
da.GetData(1, ref id);
da.GetData(2, ref value);
da.GetData(3, ref scale);
da.GetData(4, ref cssStyle);
GetStandardInputs(da);
da.GetData("Value", ref _value);
da.GetData("Scale", ref _scale);

// create a valid HTML string from the inputs for our header
string labelString =
$"<h{scale} id='{id}' name='{name}' style='{cssStyle}'>{value}</h{scale}>";
$"<h{_scale} id='{id}' name='{name}' style='{cssStyle}'>{_value}</h{_scale}>";

da.SetData(0, labelString);
}
Expand Down
Loading