Skip to content

Commit 8269742

Browse files
committed
adding samples, button bugfix, removed unused
1 parent 702ec4b commit 8269742

14 files changed

+123
-244
lines changed

GHUI/Classes/WebView2Wrapper.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,9 @@ private void HandleButtonClick(DomClickModel clickModel)
217217
//if (clickModel.targetType != "button") return;
218218
// TODO: need to ensure that there is a unique id for each button, even when users
219219
// are not using the id/name feature correctly. for now we loop over all the possible buttons
220-
var clickedButtons = _domInputModels.Where(m => m.type == clickModel.targetType &&
221-
m.id == clickModel.targetId ||
222-
m.name == clickModel.targetName);
223-
//if (clickedButtons == null) return;
220+
IEnumerable<DomInputModel> clickedButtons = _domInputModels.Where(m => m.type == clickModel.targetType);
221+
222+
clickedButtons = clickedButtons.Where(m => m.id == clickModel.targetId || m.name == clickModel.targetName);
224223
foreach (DomInputModel domInput in clickedButtons)
225224
{
226225
domInput.value = "true";

GHUI/GHUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
</Page>
176176
</ItemGroup>
177177
<ItemGroup>
178+
<Content Include="Web UI\InputWallPricingScript.html" />
178179
<EmbeddedResource Include="JS\QueryInputElementsInDOM.js" />
179180
<EmbeddedResource Include="JS\AddDocumentClickListener.js" />
180181
<Content Include="JS\SetValuesInDom.js" />

GHUI/GHUIInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class GhuiInfo : GH_AssemblyInfo
1414

1515
public override string Description =>
1616
//Return a short string describing the purpose of this GHA library.
17-
"Web-based user interface building.";
17+
"Package for building and serving web-based user interfaces (UI).";
1818

1919
public override Guid Id => new Guid("df3904bc-7b3e-4099-a88f-95ab4145e4b5");
2020

GHUI/HtmlUiComponent.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Windows.Threading;
44
using Grasshopper.Kernel;
55
using Grasshopper.Kernel.Types;
6+
using Microsoft.Web.WebView2.Core.DevToolsProtocolExtension;
67

78
namespace GHUI
89
{
@@ -17,6 +18,8 @@ public class HtmlUiComponent : GH_Component
1718
private Thread _uiThread;
1819

1920
private string _oldPath;
21+
private double _height = 800;
22+
private double _width = 500;
2023

2124
/// <summary>
2225
/// Launch a UI Window from a HTML file.
@@ -36,6 +39,10 @@ protected override void RegisterInputParams(GH_InputParamManager pManager)
3639
GH_ParamAccess.item, false);
3740
pManager.AddTextParameter("Title", "title", "The title name for the UI window.",
3841
GH_ParamAccess.item, "UI");
42+
pManager.AddNumberParameter("Height", "height", "The desired starting height of the UI window.",
43+
GH_ParamAccess.item, 800);
44+
pManager.AddNumberParameter("Width", "width", "The desired starting width of the UI window.",
45+
GH_ParamAccess.item, 500);
3946
}
4047

4148
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
@@ -58,6 +65,8 @@ protected override void SolveInstance(IGH_DataAccess da)
5865
if (!da.GetData(0, ref path)) return;
5966
if (!da.GetData<bool>(1, ref show)) return;
6067
da.GetData(2, ref title);
68+
da.GetData(3, ref _height);
69+
da.GetData(4, ref _width);
6170

6271

6372
if (!show) return;
@@ -101,6 +110,8 @@ private void LaunchWindow(string path, string title = "UI")
101110
_webWindow.Closed += _webWindow_Closed;
102111
_webWindow.Show();
103112
_webWindow.Title = title;
113+
_webWindow.Height = _height;
114+
_webWindow.Width = _width;
104115
Dispatcher.Run();
105116
});
106117

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<!DOCTYPE html>
2+
3+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
4+
5+
<head>
6+
<meta charset="utf-8" />
7+
<title>HTML Grasshopper Interface</title>
8+
<meta name="author" content="Petr Mitev">
9+
<style>
10+
html,
11+
body {
12+
margin: 5px;
13+
padding: 0;
14+
}
15+
16+
.grid-container {
17+
display: grid;
18+
grid-template-columns: auto auto;
19+
padding: 10px;
20+
}
21+
.grid-container-results {
22+
display: grid;
23+
grid-template-columns: auto auto auto;
24+
padding: 10px;
25+
}
26+
27+
.label-container {
28+
display: flex;
29+
align-items: center
30+
}
31+
32+
label {
33+
margin-right: 10px;
34+
}
35+
36+
#app {
37+
font-family: "Avenir", Helvetica, Arial, sans-serif;
38+
-webkit-font-smoothing: antialiased;
39+
-moz-osx-font-smoothing: grayscale;
40+
color: #2c3e50;
41+
}
42+
</style>
43+
44+
</head>
45+
46+
<body>
47+
<br>
48+
<div id="app">
49+
<img width="200"
50+
src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fmaxcdn.icons8.com%2FShare%2Ficon%2Fdotty%2FScience%2Fcalculator1600.png&f=1&nofb=1"
51+
alt="App Logo">
52+
<h1>Wall Pricing Calculator</h1>
53+
<div class="grid-container">
54+
<div class="label-container">
55+
<label for="length">Wall Length</label>
56+
<input type="range" id="length" min="1" max="200" step="1" value="50">
57+
</div>
58+
<div class="label-container">
59+
<label for="width">Wall Width</label>
60+
<input type="range" id="width" min="1" max="10" step="1" value="2">
61+
</div>
62+
</div>
63+
64+
<div class="grid-container">
65+
<div class="label-container">
66+
<label for="studSpace">Stud Spacing</label>
67+
<input type="range" id="studSpace" min="1" max="10" step="0.1" value="4">
68+
</div>
69+
<div class="label-container">
70+
<label for="studSize">Stud Sizing</label>
71+
<input type="range" id="studSize" min="0.1" max="2" step="0.1" value="0.5">
72+
</div>
73+
</div>
74+
75+
<!-- RESULTS -->
76+
<h2 style="margin-bottom: 0px;">Results</h2>
77+
<div class="grid-container-results">
78+
<div class="label-container">
79+
<label for="wallAreaLabel">Wall Area</label>
80+
<p id="wallAreaLabel">100</p>
81+
</div>
82+
<div class="label-container">
83+
<label for="wallVolumeLabel">Wall Volume</label>
84+
<p id="wallVolumeLabel">100</p>
85+
</div>
86+
<div class="label-container">
87+
<label for="studCountLabel">Stud Count</label>
88+
<p id="studCountLabel">100</p>
89+
</div>
90+
</div>
91+
<div>
92+
<input type="button" id="exportButton" value="Export Results">
93+
</div>
94+
95+
96+
</div>
97+
</body>
98+
99+
</html>

GHUI/Web UI/htmlTemplate.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

GHUI/Web UI/inputBootstrap copy.html

Lines changed: 0 additions & 191 deletions
This file was deleted.

0 commit comments

Comments
 (0)