1
1
using System ;
2
+ using GHUI . Classes ;
2
3
using Grasshopper . Kernel ;
3
4
4
5
namespace GHUI
5
6
{
6
- public class BuildImageComponent : GH_Component
7
+ public class BuildImageComponent : GH_ComponentTemplate
7
8
{
9
+ private string _url ;
10
+ private double _width = 300 ;
11
+ private double _height = 300 ;
12
+
8
13
/// <summary>
9
14
/// Component for building a HTML image component.
10
15
/// </summary>
@@ -17,42 +22,24 @@ public BuildImageComponent()
17
22
18
23
protected override void RegisterInputParams ( GH_InputParamManager pManager )
19
24
{
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 ) ;
24
26
pManager . AddTextParameter ( "URL" , "url" , "The url of the image to show." ,
25
27
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 ) ;
36
32
}
37
33
38
34
protected override void SolveInstance ( IGH_DataAccess da )
39
35
{
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 ) ;
53
40
54
41
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 } '>";
56
43
57
44
da . SetData ( 0 , textString ) ;
58
45
}
0 commit comments