Skip to content

Commit c7e726a

Browse files
authored
Merge pull request #5 from mitevpi/web-view-2
Documentation, BugFixes
2 parents a5727ba + 8269742 commit c7e726a

26 files changed

+252
-548
lines changed

GHUI/BuildCheckBoxComponent.cs

+14-30
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using System;
2+
using GHUI.Classes;
23
using Grasshopper.Kernel;
34

45
namespace GHUI
56
{
6-
public class BuildCheckBoxComponent : GH_Component
7+
public class BuildCheckBoxComponent : GH_ComponentTemplate
78
{
9+
private bool _value = false;
10+
private string _label;
11+
812
/// <summary>
913
/// Component for building a HTML checkbox input component.
1014
/// </summary>
@@ -17,49 +21,29 @@ public BuildCheckBoxComponent()
1721

1822
protected override void RegisterInputParams(GH_InputParamManager pManager)
1923
{
20-
pManager.AddTextParameter("Name", "name", "The name of the checkbox input component.", GH_ParamAccess.item,
21-
"checkbox");
22-
pManager.AddTextParameter("ID", "id", "The id of the checkbox input component.", GH_ParamAccess.item,
23-
"checkbox");
24+
RegisterDefaultInputParams(pManager);
2425
pManager.AddBooleanParameter("Value", "val", "The starting value of the checkbox input component.",
2526
GH_ParamAccess.item, false);
2627
pManager.AddTextParameter("Label", "label", "The starting label of the checkbox input component.",
2728
GH_ParamAccess.item, "");
28-
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
29-
GH_ParamAccess.item,
30-
"");
3129
}
3230

33-
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
34-
{
35-
pManager.AddTextParameter("HTML", "html", "The HTML code for the created checkbox input.",
36-
GH_ParamAccess.list);
37-
}
3831

3932
protected override void SolveInstance(IGH_DataAccess da)
4033
{
41-
// get input from gh component inputs
42-
string name = null;
43-
string id = null;
44-
bool value = false;
45-
string label = null;
46-
string cssStyle = null;
47-
48-
da.GetData(0, ref name);
49-
da.GetData(1, ref id);
50-
da.GetData(2, ref value);
51-
da.GetData(3, ref label);
52-
da.GetData(4, ref cssStyle);
34+
GetStandardInputs(da);
35+
da.GetData("Value", ref _value);
36+
da.GetData("Label", ref _label);
5337

54-
string textString =
55-
$"<input type='checkbox' id='{id}' name='{name}' checked='{value}' style='{cssStyle}'>";
38+
string checkboxHtml =
39+
$"<input type='checkbox' id='{id}' name='{name}' checked='{_value}' style='{cssStyle}'>";
5640

57-
if (label != "")
41+
if (_label != "")
5842
{
59-
textString = textString + $"<label for='{id}' id='{id}-label' >{label}</label>";
43+
checkboxHtml += $"<label for='{id}' id='{id}-label' >{_label}</label>";
6044
}
6145

62-
da.SetData(0, textString);
46+
da.SetData(0, checkboxHtml);
6347
}
6448

6549
protected override System.Drawing.Bitmap Icon => Properties.Resources.checkbox;

GHUI/BuildColorComponent.cs

+10-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
2+
using GHUI.Classes;
23
using Grasshopper.Kernel;
34

45
namespace GHUI
56
{
6-
public class BuildColorComponent : GH_Component
7+
public class BuildColorComponent : GH_ComponentTemplate
78
{
9+
private string _value;
10+
811
/// <summary>
912
/// Component for building a HTML color input component.
1013
/// </summary>
@@ -17,40 +20,20 @@ public BuildColorComponent()
1720

1821
protected override void RegisterInputParams(GH_InputParamManager pManager)
1922
{
20-
pManager.AddTextParameter("Name", "name", "The name of the color input component.", GH_ParamAccess.item,
21-
"color");
22-
pManager.AddTextParameter("ID", "id", "The id of the color input component.", GH_ParamAccess.item,
23-
"color");
23+
RegisterDefaultInputParams(pManager);
2424
pManager.AddTextParameter("Value", "val", "The starting value of the color input component.",
2525
GH_ParamAccess.item, "");
26-
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
27-
GH_ParamAccess.item,
28-
"");
29-
}
30-
31-
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
32-
{
33-
pManager.AddTextParameter("HTML", "html", "The HTML code for the created color input.",
34-
GH_ParamAccess.list);
3526
}
3627

3728
protected override void SolveInstance(IGH_DataAccess da)
3829
{
39-
// get input from gh component inputs
40-
string name = null;
41-
string id = null;
42-
string value = null;
43-
string cssStyle = null;
44-
45-
da.GetData(0, ref name);
46-
da.GetData(1, ref id);
47-
da.GetData(2, ref value);
48-
da.GetData(3, ref cssStyle);
30+
GetStandardInputs(da);
31+
da.GetData("Value", ref _value);
4932

50-
string textString =
51-
$"<input type='color' id='{id}' name='{name}' value='{value}' style='{cssStyle}'>";
33+
string colorInputHtml =
34+
$"<input type='color' id='{id}' name='{name}' value='{_value}' style='{cssStyle}'>";
5235

53-
da.SetData(0, textString);
36+
da.SetData(0, colorInputHtml);
5437
}
5538

5639
protected override System.Drawing.Bitmap Icon => Properties.Resources.color;

GHUI/BuildDateComponent.cs

+12-29
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using System;
2+
using GHUI.Classes;
23
using Grasshopper.Kernel;
34

45
namespace GHUI
56
{
6-
public class BuildDateComponent : GH_Component
7+
public class BuildDateComponent : GH_ComponentTemplate
78
{
9+
private string _value;
10+
private string _min;
11+
private string _max;
12+
813
/// <summary>
914
/// Component for building a HTML date input component.
1015
/// </summary>
@@ -17,46 +22,24 @@ public BuildDateComponent()
1722

1823
protected override void RegisterInputParams(GH_InputParamManager pManager)
1924
{
20-
pManager.AddTextParameter("Name", "name", "The name of the date input component.", GH_ParamAccess.item,
21-
"date");
22-
pManager.AddTextParameter("ID", "id", "The id of the date input component.", GH_ParamAccess.item,
23-
"date");
25+
RegisterDefaultInputParams(pManager);
2426
pManager.AddTextParameter("Value", "val", "The starting value of the date input component.",
2527
GH_ParamAccess.item, "");
2628
pManager.AddTextParameter("Min", "min", "The min value of the date input component.",
2729
GH_ParamAccess.item, "1900-12-31");
2830
pManager.AddTextParameter("Max", "max", "The max value of the date input component.",
2931
GH_ParamAccess.item, "2021-01-02");
30-
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
31-
GH_ParamAccess.item,
32-
"");
33-
}
34-
35-
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
36-
{
37-
pManager.AddTextParameter("HTML", "html", "The HTML code for the created date input.",
38-
GH_ParamAccess.list);
3932
}
4033

4134
protected override void SolveInstance(IGH_DataAccess da)
4235
{
43-
// get input from gh component inputs
44-
string name = null;
45-
string id = null;
46-
string value = null;
47-
string min = null;
48-
string max = null;
49-
string cssStyle = null;
50-
51-
da.GetData(0, ref name);
52-
da.GetData(1, ref id);
53-
da.GetData(2, ref value);
54-
da.GetData(3, ref min);
55-
da.GetData(4, ref max);
56-
da.GetData(4, ref cssStyle);
36+
GetStandardInputs(da);
37+
da.GetData("Value", ref _value);
38+
da.GetData("Min", ref _min);
39+
da.GetData("Max", ref _max);
5740

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

6144
da.SetData(0, textString);
6245
}

GHUI/BuildImageComponent.cs

+16-29
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using System;
2+
using GHUI.Classes;
23
using Grasshopper.Kernel;
34

45
namespace GHUI
56
{
6-
public class BuildImageComponent : GH_Component
7+
public class BuildImageComponent : GH_ComponentTemplate
78
{
9+
private string _url;
10+
private double _width = 300;
11+
private double _height = 300;
12+
813
/// <summary>
914
/// Component for building a HTML image component.
1015
/// </summary>
@@ -17,42 +22,24 @@ public BuildImageComponent()
1722

1823
protected override void RegisterInputParams(GH_InputParamManager pManager)
1924
{
20-
pManager.AddTextParameter("Name", "name", "The name of the image component.", GH_ParamAccess.item,
21-
"image");
22-
pManager.AddTextParameter("ID", "id", "The id of the image component.", GH_ParamAccess.item,
23-
"image");
25+
RegisterDefaultInputParams(pManager);
2426
pManager.AddTextParameter("URL", "url", "The url of the image to show.",
2527
GH_ParamAccess.item, "https://vuejs.org/images/logo.png");
26-
pManager.AddNumberParameter("Height", "height", "The desired height of the image (pixels).", GH_ParamAccess.item, 300);
27-
pManager.AddNumberParameter("Width", "width", "The desired width of the image (pixels).", GH_ParamAccess.item, 300);
28-
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
29-
GH_ParamAccess.item, "");
30-
}
31-
32-
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
33-
{
34-
pManager.AddTextParameter("HTML", "html", "The HTML code for the created image input.",
35-
GH_ParamAccess.list);
28+
pManager.AddNumberParameter("Height", "height", "The desired height of the image (pixels).",
29+
GH_ParamAccess.item, 300);
30+
pManager.AddNumberParameter("Width", "width", "The desired width of the image (pixels).",
31+
GH_ParamAccess.item, 300);
3632
}
3733

3834
protected override void SolveInstance(IGH_DataAccess da)
3935
{
40-
string name = null;
41-
string id = null;
42-
string url = null;
43-
double height = 200;
44-
double width = 200;
45-
string cssStyle = null;
46-
47-
da.GetData(0, ref name);
48-
da.GetData(1, ref id);
49-
da.GetData(2, ref url);
50-
da.GetData(3, ref height);
51-
da.GetData(4, ref width);
52-
da.GetData(5, ref cssStyle);
36+
GetStandardInputs(da);
37+
da.GetData("URL", ref _url);
38+
da.GetData("Width", ref _width);
39+
da.GetData("Height", ref _height);
5340

5441
string textString =
55-
$"<img id='{id}' height='{height}' width='{width}' src='{url}' alt='{name}'>";
42+
$"<img id='{id}' height='{_height}' width='{_width}' src='{_url}' alt='{name}'>";
5643

5744
da.SetData(0, textString);
5845
}

GHUI/BuildLabelComponent.cs

+10-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using System;
2+
using GHUI.Classes;
23
using Grasshopper.Kernel;
34

45
namespace GHUI
56
{
6-
public class BuildLabelComponent : GH_Component
7+
public class BuildLabelComponent : GH_ComponentTemplate
78
{
9+
private string _value;
10+
private double _scale;
11+
812
/// <summary>
913
/// Component for building a HTML header component.
1014
/// </summary>
@@ -17,43 +21,22 @@ public BuildLabelComponent()
1721

1822
protected override void RegisterInputParams(GH_InputParamManager pManager)
1923
{
20-
pManager.AddTextParameter("Name", "name", "The name of the header component.", GH_ParamAccess.item,
21-
"header");
22-
pManager.AddTextParameter("ID", "id", "The id of the header component.", GH_ParamAccess.item,
23-
"header");
24+
RegisterDefaultInputParams(pManager);
2425
pManager.AddTextParameter("Value", "val", "The starting value of the header component.",
2526
GH_ParamAccess.item, "header");
2627
pManager.AddNumberParameter("Scale", "scale", "The scale of heading to create (1-4).",
2728
GH_ParamAccess.item, 1);
28-
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.",
29-
GH_ParamAccess.item,
30-
"");
31-
}
32-
33-
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
34-
{
35-
pManager.AddTextParameter("HTML", "html", "The HTML code for the created header input.",
36-
GH_ParamAccess.list);
3729
}
3830

3931
protected override void SolveInstance(IGH_DataAccess da)
4032
{
41-
// get input from gh component inputs
42-
string name = null;
43-
string id = null;
44-
string value = null;
45-
double scale = 1;
46-
string cssStyle = null;
47-
48-
da.GetData(0, ref name);
49-
da.GetData(1, ref id);
50-
da.GetData(2, ref value);
51-
da.GetData(3, ref scale);
52-
da.GetData(4, ref cssStyle);
33+
GetStandardInputs(da);
34+
da.GetData("Value", ref _value);
35+
da.GetData("Scale", ref _scale);
5336

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

5841
da.SetData(0, labelString);
5942
}

0 commit comments

Comments
 (0)