Skip to content

Commit f2518c7

Browse files
committed
div, label, button components added. reload on change includes input.
1 parent 5701828 commit f2518c7

23 files changed

+1726
-1237
lines changed

GHUI/BuildButtonComponent.cs

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using Grasshopper.Kernel;
3+
4+
namespace GHUI
5+
{
6+
public class BuildButtonComponent : GH_Component
7+
{
8+
/// <summary>
9+
/// Component for building a HTML button input component.
10+
/// </summary>
11+
public BuildButtonComponent()
12+
: base("Create Button", "Button",
13+
"Create a HTML Button Input.",
14+
"UI", "Create")
15+
{
16+
}
17+
18+
protected override void RegisterInputParams(GH_InputParamManager pManager)
19+
{
20+
pManager.AddTextParameter("Name", "name", "The name of the button input component.", GH_ParamAccess.item,
21+
"button");
22+
pManager.AddTextParameter("ID", "id", "The id of the button input component.", GH_ParamAccess.item,
23+
"button");
24+
pManager.AddTextParameter("Value", "val", "The starting value of the button input component.",
25+
GH_ParamAccess.item, "Button");
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 button input.",
34+
GH_ParamAccess.list);
35+
}
36+
37+
protected override void SolveInstance(IGH_DataAccess da)
38+
{
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);
49+
50+
// create a valid HTML string from the inputs for our button
51+
string buttonString =
52+
$"<input type='button' id='{id}' name='{name}' value='{value}' style='{cssStyle}'>";
53+
54+
da.SetData(0, buttonString);
55+
56+
GH_Document doc = OnPingDocument();
57+
doc?.ScheduleSolution(500, ScheduleCallback);
58+
}
59+
60+
61+
private void ScheduleCallback(GH_Document document)
62+
{
63+
ExpireSolution(false);
64+
}
65+
66+
protected override System.Drawing.Bitmap Icon => Properties.Resources.button;
67+
68+
public override Guid ComponentGuid => new Guid("6a8a21e2-2e48-2a7b-f37e-a2612de312b7");
69+
}
70+
}

GHUI/BuildDivComponent.cs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using Grasshopper.Kernel;
3+
4+
namespace GHUI
5+
{
6+
public class BuildDivComponent : GH_Component
7+
{
8+
private string _oldString = null;
9+
10+
/// <summary>
11+
/// Component for wrapping some HTML into a <div></div>.
12+
/// </summary>
13+
public BuildDivComponent()
14+
: base("Wrap in <div>", "<div>",
15+
"Wrap HTML within a <div> component.",
16+
"UI", "Create")
17+
{
18+
}
19+
20+
protected override void RegisterInputParams(GH_InputParamManager pManager)
21+
{
22+
pManager.AddTextParameter("HTML", "html", "The HTML to wrap within a <div> element.", GH_ParamAccess.item,
23+
"");
24+
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the <div> and its children elements.", GH_ParamAccess.item,
25+
"");
26+
}
27+
28+
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
29+
{
30+
pManager.AddTextParameter("HTML", "html", "The HTML code wrapped within a <div> element.",
31+
GH_ParamAccess.list);
32+
}
33+
34+
protected override void SolveInstance(IGH_DataAccess da)
35+
{
36+
// get input from gh component inputs
37+
string htmlToWrap = null;
38+
string cssStyle = null;
39+
40+
if (!da.GetData(0, ref htmlToWrap)) return;
41+
da.GetData(1, ref cssStyle);
42+
43+
44+
string sliderString = $"<div style='{cssStyle}'>{htmlToWrap}</div>";
45+
da.SetData(0, sliderString);
46+
47+
GH_Document doc = OnPingDocument();
48+
doc?.ScheduleSolution(500, ScheduleCallback);
49+
}
50+
51+
52+
private void ScheduleCallback(GH_Document document)
53+
{
54+
ExpireSolution(false);
55+
}
56+
57+
protected override System.Drawing.Bitmap Icon => Properties.Resources.div;
58+
59+
public override Guid ComponentGuid => new Guid("9a2c42e6-2f48-2d5b-c17a-b6621dc312e3");
60+
}
61+
}

GHUI/BuildLabelComponent.cs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using Grasshopper.Kernel;
3+
4+
namespace GHUI
5+
{
6+
public class BuildLabelComponent : GH_Component
7+
{
8+
/// <summary>
9+
/// Component for building a HTML label input component.
10+
/// </summary>
11+
public BuildLabelComponent()
12+
: base("Create Label", "Label",
13+
"Create a HTML Label Input.",
14+
"UI", "Create")
15+
{
16+
}
17+
18+
protected override void RegisterInputParams(GH_InputParamManager pManager)
19+
{
20+
pManager.AddTextParameter("Name", "name", "The name of the label component.", GH_ParamAccess.item,
21+
"label");
22+
pManager.AddTextParameter("ID", "id", "The id of the label component.", GH_ParamAccess.item,
23+
"label");
24+
pManager.AddTextParameter("Value", "val", "The starting value of the label component.",
25+
GH_ParamAccess.item, "label");
26+
pManager.AddNumberParameter("Scale", "scale", "The scale of heading to create (1-4).",
27+
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 label input.",
36+
GH_ParamAccess.list);
37+
}
38+
39+
protected override void SolveInstance(IGH_DataAccess da)
40+
{
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);
53+
54+
// create a valid HTML string from the inputs for our label
55+
string labelString =
56+
$"<h{scale} id='{id}' name='{name}' style='{cssStyle}'>{value}</h{scale}>";
57+
58+
da.SetData(0, labelString);
59+
60+
GH_Document doc = OnPingDocument();
61+
doc?.ScheduleSolution(500, ScheduleCallback);
62+
}
63+
64+
65+
private void ScheduleCallback(GH_Document document)
66+
{
67+
ExpireSolution(false);
68+
}
69+
70+
protected override System.Drawing.Bitmap Icon => Properties.Resources.label;
71+
72+
public override Guid ComponentGuid => new Guid("8f3e21c9-3e16-2a7e-f37e-e2392da362c7");
73+
}
74+
}

GHUI/BuildSliderComponent.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
using System;
2-
using System.IO;
32
using Grasshopper.Kernel;
43

54
namespace GHUI
65
{
76
public class BuildSliderComponent : GH_Component
87
{
9-
private string _oldString = null;
10-
118
/// <summary>
12-
/// Component for building a Vue.js UI into a HTML file within
13-
/// Grasshopper.
9+
/// Component for building a HTML slider input component.
1410
/// </summary>
1511
public BuildSliderComponent()
1612
: base("Create Slider", "Slider",
@@ -31,6 +27,8 @@ protected override void RegisterInputParams(GH_InputParamManager pManager)
3127
GH_ParamAccess.item, 0);
3228
pManager.AddNumberParameter("Max", "max", "The max value of the slider input component.",
3329
GH_ParamAccess.item, 100);
30+
pManager.AddTextParameter("CSS", "css", "The `style` attribute to apply to the element and its children.", GH_ParamAccess.item,
31+
"");
3432
}
3533

3634
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
@@ -47,16 +45,18 @@ protected override void SolveInstance(IGH_DataAccess da)
4745
double value = 50;
4846
double min = 0;
4947
double max = 100;
48+
string cssStyle = null;
5049

5150
da.GetData(0, ref name);
5251
da.GetData(1, ref id);
5352
da.GetData(2, ref value);
5453
da.GetData(3, ref min);
5554
da.GetData(4, ref max);
55+
da.GetData(5, ref cssStyle);
5656

5757
// create a valid HTML string from the inputs for our slider
5858
string sliderString =
59-
$"<input type='range' id='{id}' name='{name}' value='{value}' min='{min}' max='{max}'>";
59+
$"<input type='range' id='{id}' name='{name}' value='{value}' min='{min}' max='{max}' style='{cssStyle}'>";
6060

6161
da.SetData(0, sliderString);
6262

GHUI/Classes/GrasshopperUtil.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace GHUI.Classes
8+
{
9+
class GrasshopperUtil
10+
{
11+
}
12+
}

GHUI/Classes/Models/DomClickModel.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace GHUI.Classes.Models
2+
{
3+
class DomClickModel
4+
{
5+
public string type;
6+
public string targetId;
7+
public string targetName;
8+
public string targetType;
9+
public string targetValue;
10+
public string targetTagName;
11+
}
12+
}

0 commit comments

Comments
 (0)