about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/ModalWindow.razor
blob: 216f1f36e1e55005df470bfc6dd3a5186b2bc4cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<div class="r-modal" style="top: @(_y)px; left: @(_x)px;">
    <div class="titlebar" @onmousedown="MouseDown" @onmouseup="MouseUp" @onmousemove="MouseMove" @onmouseleave="MouseMove">
        <b class="title">@Title</b>
        <button class="btnclose" @onclick="OnCloseClicked">X</button>
        <button class="btncollapse" @onclick="@(() => Collapsed = !Collapsed)">_</button>
    </div>
        <div class="content" style="@(Collapsed ? "height: 0px;" : "")">
            @ChildContent
        </div>
</div>

@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 Action OnCloseClicked { get; set; }

    [Parameter]
    public bool Collapsed { get; set; } = false;

    private double _x = 60;
    private double _y = 60;

    protected override void OnInitialized() {
        _x = X;
        _y = Y;
    }

    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) {
            _x += obj.ClientX - dragX;
            _y += obj.ClientY - dragY;
            dragX = obj.ClientX;
            dragY = obj.ClientY;
            StateHasChanged();
        }
    }

}