alternetsoft / AlternetUI

MIT License
22 stars 2 forks source link

Control become uninteractable when using nested docking... #105

Closed Shadowblitz16 closed 5 months ago

Shadowblitz16 commented 6 months ago

After reporting the issue about the window position not being saved I tried to implement this as a panel... But my panel stops receiving input after about the forth click on the settings button...

<Window xmlns="http://schemas.alternetsoft.com/ui/2021"
        xmlns:x="http://schemas.alternetsoft.com/ui/2021/uixml"
        x:Class="SMBXR.MainView"
        xmlns:local="clr-namespace:SMBXR"
        Title="SMBXR Editor">
    <Window.Menu>
        <MainMenu>
            <MenuItem Text="_File">
                <MenuItem Text="_Open..." Name="openMenuItem" Click="OnOpen" Shortcut="Ctrl+O"/>
                <MenuItem Text="_Save..." Name="saveMenuItem" Click="OnSave" Shortcut="Ctrl+S"/>
                <MenuItem Text="-" Name="separatorMenuItem" />
                <MenuItem Text="E_xit" Name="exitMenuItem" Click="OnExit"/>
            </MenuItem>
        </MainMenu>
    </Window.Menu>
    <Panel Dock="Fill">
        <Panel Name="levelEdit" Dock="Fill" UserPaint="true" Paint="OnLevelPaint"/>
        <Panel Dock="Bottom" VerticalAlignment="Bottom"> 
            <local:LevelSettingsView Name="levelSettingsView" Dock="Fill" VerticalAlignment="Top"/>
            <Panel Name="levelTools" Dock="Bottom" VerticalAlignment="Bottom">
                <HorizontalStackPanel Dock="Fill">  
                    <Button Text="Select" Name="selectButton" Click="OnLevelSelect"/>
                    <Button Text="Eraser" Name="eraserButton" Click="OnLevelEraser"/>
                    <Button Text="Settings" Name="settingsButton" Click="OnLevelSettings"/>
                </HorizontalStackPanel>
            </Panel>
        </Panel>
    </Panel>
</Window>

using System;
using SMBXR.Engine;
using Alternet.UI;
using Alternet.Drawing;

namespace SMBXR;

public enum SectionResizeMode
{
    Edit,
    Top, 
    Left,
    Right,
    Bottom
}
public partial class MainView : Window 
{
    public Level Level { get; } = new();

    public PointD LastToolWindowPos { get; private set; }
    public SectionResizeMode ResizeMode { get; set; }

    public MainView()
    {
        InitializeComponent();

        var element = FindElement("levelSettingsView");
        if (element is LevelSettingsView view)
        {
            view.MainView = this;
        } 
    }

    private void OnSave(object sender, EventArgs args)
    {

    }
    private void OnOpen(object sender, EventArgs args)
    {

    }
    private void OnExit(object sender, EventArgs args)
    {

    }

    private void OnLevelPaint(object sender, PaintEventArgs args)
    {
        args.DrawingContext.FillRectangle(new SolidBrush(Color.Black), args.Bounds);
    }
    private void OnLevelSelect(object sender, EventArgs args)
    {

    }
    private void OnLevelEraser(object sender, EventArgs args)
    {

    }
    private void OnLevelSettings(object sender, EventArgs args)
    {
        var element = FindElement("levelSettingsView");
        if (element is LevelSettingsView view)
        {
            view.Visible = !view.Visible;
        }
    }
}
<Panel xmlns="http://schemas.alternetsoft.com/ui/2021"
        xmlns:x="http://schemas.alternetsoft.com/ui/2021/uixml"
        x:Class="SMBXR.LevelSettingsView"
        xmlns:local="clr-namespace:SMBXR">
    <VerticalStackPanel>
        <HorizontalStackPanel>
            <GroupBox Text="Section Mode">
                <VerticalStackPanel>
                    <Button Name="buttonSectionEdit" Text="Edit" Click="OnSectionBoundsEdit"/>
                    <Button Name="buttonSectionTop" Text="Top" Click="OnSectionBoundsTop"/>
                    <Button Name="buttonSectionLeft" Text="Left"  Click="OnSectionBoundsLeft"/>
                    <Button Name="buttonSectionRight" Text="Right" Click="OnSectionBoundsRight"/>
                    <Button Name="buttonSectionBottom" Text="Bottom"  Click="OnSectionBoundsBottom"/>
                </VerticalStackPanel>
            </GroupBox>
        </HorizontalStackPanel>
    </VerticalStackPanel>
</Panel>

using Alternet.UI;

namespace SMBXR;

public partial class LevelSettingsView : Panel 
{
    public MainView? MainView { get; set; }
    public LevelSettingsView()
    {
        InitializeComponent();
    }

    private void OnSectionBoundsEdit(object sender, EventArgs args)
    {
        if (MainView == null) return;
        MainView.ResizeMode = SectionResizeMode.Edit;
    }

    private void OnSectionBoundsTop(object sender, EventArgs args)
    {
        if (MainView == null) return;
        MainView.ResizeMode = SectionResizeMode.Top;
    }

    private void OnSectionBoundsLeft(object sender, EventArgs args)
    {
        if (MainView == null) return;
        MainView.ResizeMode = SectionResizeMode.Left;
    }
    private void OnSectionBoundsRight(object sender, EventArgs args)
    {
        if (MainView == null) return;
        MainView.ResizeMode = SectionResizeMode.Right;
    }
    private void OnSectionBoundsBottom(object sender, EventArgs args)
    {
        if (MainView == null) return;
        MainView.ResizeMode = SectionResizeMode.Bottom;
    }

}
generalloki commented 6 months ago

I have fixed uixml. It seems work fine with these changes. I removed all Dock settings as they are extra.

<Window xmlns="http://schemas.alternetsoft.com/ui/2021"
        xmlns:x="http://schemas.alternetsoft.com/ui/2021/uixml"
        x:Class="SMBXR.MainView"
        xmlns:local="clr-namespace:SMBXR"
        Title="SMBXR Editor">
  <Window.Menu>
    <MainMenu>
      <MenuItem Text="_File">
        <MenuItem Text="_Open..." Name="openMenuItem" Click="OnOpen" Shortcut="Ctrl+O"/>
        <MenuItem Text="_Save..." Name="saveMenuItem" Click="OnSave" Shortcut="Ctrl+S"/>
        <MenuItem Text="-" Name="separatorMenuItem" />
        <MenuItem Text="E_xit" Name="exitMenuItem" Click="OnExit"/>
      </MenuItem>
    </MainMenu>
  </Window.Menu>
  <VerticalStackPanel>
    <Panel Name="levelEdit" UserPaint="true" Paint="OnLevelPaint" VerticalAlignment="Fill"/>
    <VerticalStackPanel>
      <local:LevelSettingsView Name="levelSettingsView" VerticalAlignment="Fill"/>
      <Panel Name="levelTools">
        <HorizontalStackPanel>
          <Button Text="Select" Name="selectButton" Click="OnLevelSelect"/>
          <Button Text="Eraser" Name="eraserButton" Click="OnLevelEraser"/>
          <Button Text="Settings" Name="settingsButton" Click="OnLevelSettings"/>
        </HorizontalStackPanel>
      </Panel>
    </VerticalStackPanel>

  </VerticalStackPanel>
</Window>
generalloki commented 5 months ago

I am closing this issue as it seems to be not the problem in Alternet.UI.