TomaszRewak / C-sharp-console-gui-framework

A GUI framework for C# console applications
MIT License
1.08k stars 45 forks source link

correct formatting? #13

Closed kbilsted closed 4 years ago

kbilsted commented 4 years ago

Just learning the framework. Is this as expected?

class Program
{
    static void Main(string[] args)
    {
        ConsoleManager.Setup();
        ConsoleManager.Resize(new Size(150, 40));
        ConsoleManager.Content =
            new Box()
            {
                Content = new Border()
                {
                    Content =
                        new HorizontalStackPanel()
                        {
                            Children = new[] { new TextBlock { Text = "Hello world" }, new TextBlock { Text = "22Hello world22" }, }
                        }
                }
            };

        Console.ReadKey();
    }
}

image

TomaszRewak commented 4 years ago

Discussion in #14

kbilsted commented 4 years ago

why is this closed? it is clearly not showing any text "Hello world" or "22Hello world22" #14 is unrelated IMHO

TomaszRewak commented 4 years ago

Reopened. The format here is incorrect.

The HorizontalStackPanel will always:

That's by design, because some child components might rely on the size of the container when calculating their size and trying to adjust both based on each other might lead to an infinite looping. The Box by default centers content both vertically and horizontally. When in this mode, it tells its child components that they have infinite available space in both directions. And so the HorizontalStackPanel will have an infinite height in this configuration (even if there is a Border in between). If you want to achieve desired result, you have to restrict the height of the HorizontalStackPanel manually using a Boundry (either around the HorizontalStackPanel with MaxHeight set to 1 or around the border with MaxHeight set to 3 - to include the border).

static void Main(string[] args)
{
    ConsoleManager.Setup();
    ConsoleManager.Resize(new Size(150, 40));
    ConsoleManager.Content = new Box()
    {
        Content = new Boundary()
        {
            MaxHeight = 3,
            Content = new Border()
            {
                Content = new HorizontalStackPanel()
                {
                    Children = new[] { new TextBlock { Text = "Hello world" }, new TextBlock { Text = "22Hello world22" }, }
                }
            }
        }
    };

    Console.ReadKey();
}
TomaszRewak commented 4 years ago

image

kbilsted commented 4 years ago

The HorizontalStackPanel will always:

adjust its width to the width of its content,
take up the entire available space vertically

should this go into the documentation?

From reading the code, I would think I got a border taking up all the space of the console as displayed in #14. Perhaps the infinite should be limited to the size of the console? But I guess that is problematic when you use components with scrollbars.

if you don't think the example shows a buggy UI then close this issue.

TomaszRewak commented 4 years ago

Theoretically the size of the Box Content could be limited to the Size of this container. But there are two problems with this solution:

Also, if one would want to fill all of the available vertical/horizontal space while centering the item in the other axis, the VerticalContentPlacement or the HorizontalContentPlacement should be simply set to Stretch, which strictly defines this behavior.