-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0c9528
commit 3e9614d
Showing
5 changed files
with
141 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,7 @@ | ||
@page "/counter" | ||
|
||
<PageTitle>Counter</PageTitle> | ||
|
||
<h1>Counter</h1> | ||
|
||
<p role="status">Current count: @currentCount</p> | ||
|
||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button> | ||
|
||
@code { | ||
private int currentCount = 0; | ||
|
||
private void IncrementCount() | ||
{ | ||
currentCount++; | ||
} | ||
private int currentCount = 0; | ||
private void IncrementCount() => currentCount++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,17 @@ | ||
@page "/" | ||
@using ScriptContainer | ||
@inject IJSRuntime runtime | ||
|
||
<div class="element-container"> | ||
<button @onclick="Expand"> | ||
Setup | ||
</button> | ||
<div class="doc"> | ||
<h2>Document Bounds</h2> | ||
<ul> | ||
<li>@DocW</li> | ||
<li>@DocH</li> | ||
</ul> | ||
</div> | ||
<div class="element" @ref="ElementA"> | ||
<h2>Element A Bounds</h2> | ||
<ul> | ||
<li>@ItemAW</li> | ||
<li>@ItemAH</li> | ||
</ul> | ||
</div> | ||
<div class="element element-sm" @ref="ElementB"> | ||
<h2>Element B Bounds</h2> | ||
<ul> | ||
<li>@ItemBW</li> | ||
<li>@ItemBH</li> | ||
</ul> | ||
</div> | ||
@if (Rows.Any()) | ||
{ | ||
<ul> | ||
@foreach (var row in Rows) | ||
{ | ||
<li>@row</li> | ||
} | ||
</ul> | ||
} | ||
</div> | ||
|
||
@code | ||
{ | ||
public double DocW { get; set; } | ||
public double DocH { get; set; } | ||
public double ItemAW { get; set; } | ||
public double ItemAH { get; set; } | ||
public double ItemBW { get; set; } | ||
public double ItemBH { get; set; } | ||
public ScriptService ScaleService { get; set; } | ||
public ElementReference ElementA { get; set; } | ||
public ElementReference ElementB { get; set; } | ||
public ElementReference CanvasA { get; set; } | ||
public ElementReference CanvasB { get; set; } | ||
public IList<string> Rows { get; set; } = new string[0]; | ||
|
||
protected override async Task OnAfterRenderAsync(bool setup) | ||
{ | ||
if (setup) | ||
{ | ||
await Setup(); | ||
} | ||
|
||
await base.OnAfterRenderAsync(setup); | ||
} | ||
|
||
protected void Expand() | ||
{ | ||
Rows = Rows.Any() ? | ||
new string[0] : | ||
Enumerable.Range(0, 50).Select(o => $"{o}").ToList(); | ||
<style type="text/css"> | ||
.container { | ||
display: flex; | ||
flex-grow: 1; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> | ||
|
||
protected async Task Setup() | ||
{ | ||
ScaleService?.Dispose(); | ||
ScaleService = new ScriptService(runtime); | ||
ScaleService.Actions[nameof(MessageEnum.Size)] = async message => await GetBounds(); | ||
ScaleService.Actions["Demo"] = async message => await GetBounds(); | ||
|
||
await ScaleService.CreateModule(); | ||
await ScaleService.SubscribeToSize(ElementA, "Demo"); | ||
await GetBounds(); | ||
} | ||
|
||
protected async Task GetBounds() | ||
{ | ||
var docBounds = await ScaleService.GetDocBounds(); | ||
|
||
DocW = docBounds.Value.X; | ||
DocH = docBounds.Value.Y; | ||
|
||
var itemBoundsA = await ScaleService.GetElementBounds(ElementA); | ||
var itemBoundsB = await ScaleService.GetElementBounds(ElementB); | ||
|
||
ItemAW = itemBoundsA.Value.X; | ||
ItemAH = itemBoundsA.Value.Y; | ||
ItemBW = itemBoundsB.Value.X; | ||
ItemBH = itemBoundsB.Value.Y; | ||
|
||
await InvokeAsync(StateHasChanged); | ||
} | ||
} | ||
<div class="container"> | ||
<Measures></Measures> | ||
<div class="container"> | ||
<Measures></Measures> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
@using ScriptContainer | ||
@inject IJSRuntime runtime | ||
|
||
<div class="element-container"> | ||
<button @onclick="Expand"> | ||
Setup | ||
</button> | ||
<div class="doc"> | ||
<h2>Document Bounds</h2> | ||
<ul> | ||
<li>@DocW</li> | ||
<li>@DocH</li> | ||
</ul> | ||
</div> | ||
<div class="element" @ref="ElementA"> | ||
<h2>Element A Bounds</h2> | ||
<ul> | ||
<li>@ItemAW</li> | ||
<li>@ItemAH</li> | ||
</ul> | ||
</div> | ||
<div class="element element-sm" @ref="ElementB"> | ||
<h2>Element B Bounds</h2> | ||
<ul> | ||
<li>@ItemBW</li> | ||
<li>@ItemBH</li> | ||
</ul> | ||
</div> | ||
@if (Rows.Any()) | ||
{ | ||
<ul> | ||
@foreach (var row in Rows) | ||
{ | ||
<li>@row</li> | ||
} | ||
</ul> | ||
} | ||
</div> | ||
|
||
@code | ||
{ | ||
public double DocW { get; set; } | ||
public double DocH { get; set; } | ||
public double ItemAW { get; set; } | ||
public double ItemAH { get; set; } | ||
public double ItemBW { get; set; } | ||
public double ItemBH { get; set; } | ||
public ScriptService ScaleService { get; set; } | ||
public ElementReference ElementA { get; set; } | ||
public ElementReference ElementB { get; set; } | ||
public ElementReference CanvasA { get; set; } | ||
public ElementReference CanvasB { get; set; } | ||
public IList<string> Rows { get; set; } = new string[0]; | ||
|
||
protected override async Task OnAfterRenderAsync(bool setup) | ||
{ | ||
if (setup) | ||
{ | ||
await Setup(); | ||
} | ||
|
||
await base.OnAfterRenderAsync(setup); | ||
} | ||
|
||
protected async Task Expand() | ||
{ | ||
Rows = Rows.Any() ? | ||
new string[0] : | ||
Enumerable.Range(0, 50).Select(o => $"{o}").ToList(); | ||
|
||
await Setup(); | ||
} | ||
|
||
protected async Task Setup() | ||
{ | ||
ScaleService?.Dispose(); | ||
ScaleService = new ScriptService(runtime); | ||
|
||
await ScaleService.CreateModule(); | ||
await ScaleService.SubscribeToSize(ElementA, "Demo"); | ||
|
||
ScaleService.Actions["Demo"] = async message => await GetBounds(); | ||
|
||
await GetBounds(); | ||
} | ||
|
||
protected async Task GetBounds() | ||
{ | ||
var docBounds = await ScaleService.GetDocBounds(); | ||
|
||
DocW = docBounds.Value.X; | ||
DocH = docBounds.Value.Y; | ||
|
||
var itemBoundsA = await ScaleService.GetElementBounds(ElementA); | ||
var itemBoundsB = await ScaleService.GetElementBounds(ElementB); | ||
|
||
ItemAW = itemBoundsA.Value.X; | ||
ItemAH = itemBoundsA.Value.Y; | ||
ItemBW = itemBoundsB.Value.X; | ||
ItemBH = itemBoundsB.Value.Y; | ||
|
||
await InvokeAsync(StateHasChanged); | ||
} | ||
} |