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+ }
0 commit comments