@using LibMatrix.Extensions
@Title
@ChildContent
@code { [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public string Title { get; set; } = "Untitled window"; [Parameter] public double X { get; set; } = 60; [Parameter] public double Y { get; set; } = 60; [Parameter] public double MinWidth { get; set; } = 100; [Parameter] public Action OnCloseClicked { get; set; } [Parameter] public bool Collapsed { get; set; } = false; private ElementReference _titleRef; private double _x = 60; private double _y = 60; protected override async Task OnInitializedAsync() { _x = X; _y = Y; await base.OnInitializedAsync(); } protected override async Task OnAfterRenderAsync(bool firstRender) { //set minwidth to title width MinWidth = await JSRuntime.InvokeAsync("getWidth", _titleRef) + 75; await base.OnAfterRenderAsync(firstRender); } private void WindowDrag(DragEventArgs obj) { Console.WriteLine("Drag: " + obj.ToJson()); _x += obj.MovementX; _y += obj.MovementY; StateHasChanged(); } private bool isDragging = false; private double dragX = 0; private double dragY = 0; private void MouseDown(MouseEventArgs obj) { isDragging = true; dragX = obj.ClientX; dragY = obj.ClientY; } private void MouseUp(MouseEventArgs obj) { isDragging = false; } private void MouseMove(MouseEventArgs obj) { if (!isDragging) return; _x += obj.ClientX - dragX; _y += obj.ClientY - dragY; dragX = obj.ClientX; dragY = obj.ClientY; StateHasChanged(); } }