Jump to content

Setting Nested Window Layouts in Code


photo

Recommended Posts

I can't figure out how to set a layout for nested engine windows.
I've stacked some windows into columns and stacked them into a row.
I can't figure out how to change/set the column widths in code like you can from the running app.

I'm getting this:

image.png.d8e9d03fdb30c622a6ab96f191896bf6.png

When I want this:

image.png.82a8bb50cfd339f4ae2195b9dc25978d.png

Here is what I'm trying:

using System;
using Unigine;
using static Unigine.EngineWindow.FLAGS;
using static Unigine.EngineWindow.GROUP_TYPE;
using win = Unigine.EngineWindow;
using wins = Unigine.WindowManager;

static class EC {
    [STAThread]
    static void Main(string[] args) {
        Engine.Init(args);

        win og = wins.MainWindow; og.Main = false; og.Hide();

        win view = new win(Size.View, (int)(MAIN)) { Title = "Board" };
        win bar = new win(Size.Bar, snip.FixedBox) { Title = "Status" };
        win n = new win(Size.Box, snip.FixedBox) { Title = "N" };
        win s = new win(Size.Box, snip.FixedBox) { Title = "S" };
        win e = new win(Size.Box, snip.FixedBox) { Title = "E" };
        win w = new win(Size.Box, snip.FixedBox) { Title = "W" };

        win v_1 = wins.Stack(n, w, 1, VERTICAL);
        win v_2 = wins.Stack(bar, view, 1, VERTICAL);
        win v_3 = wins.Stack(s, e, 1, VERTICAL);

        win game = wins.StackGroups(v_1, wins.StackGroups(v_2, v_3, HORIZONTAL), HORIZONTAL);
        game.Title = "Game";
        game.Size = Size.Game;
        game.MoveToCenter();

        v_1.Size = Size.Column;
        v_2.Size = Size.Column;
        v_3.Size = Size.Column;

        bar.Size = Size.Bar;

        game.MoveToCenter();
        game.Show();
        game.Arrange();
        game.Expand();

        Engine.Main();

        Engine.Shutdown();
        }

    internal interface snip {
        internal const bool Borders = false;
        internal static int FixedBox => (int)(SHOWN | FIXED_SIZE);
        }
    internal interface Size {
        internal static ivec2 Game => new(1200, 800);
        internal static ivec2 Box => new(200, 400);
        internal static ivec2 View => new(800, 800);
        internal static ivec2 Column => new(200, 800);
        internal static ivec2 Bar => new(1200, 200);
        }
    }

 

 

 

Link to comment

Hello,

You can try setting tab sizes in groups. For example, in this way:

static void Main(string[] args)
{
	Engine.Init(args);

	win og = wins.MainWindow; og.Main = false; og.Hide();

	win view = new win(Size.View, (int)(MAIN)) { Title = "Board" };
	win bar = new win(Size.Bar, snip.FixedBox) { Title = "Status" };
	win n = new win(Size.Box, snip.FixedBox) { Title = "N" };
	win s = new win(Size.Box, snip.FixedBox) { Title = "S" };
	win e = new win(Size.Box, snip.FixedBox) { Title = "E" };
	win w = new win(Size.Box, snip.FixedBox) { Title = "W" };

	// create columns
	win n_w_group = wins.Stack(n, w, 1, VERTICAL);
	win bar_view_group = wins.Stack(bar, view, 1, VERTICAL);
	win s_e_group = wins.Stack(s, e, 1, VERTICAL);

	// merge columns into one row
	win game_group = wins.StackGroups(n_w_group, bar_view_group, HORIZONTAL);
	wins.StackToGroup(game_group, s_e_group);

	game_group.Size = Size.Game;
	game_group.Arrange();
	game_group.Expand();

	// set tabs in groups
	game_group.SetHorizontalTabWidth(0, Size.Column.x);
	game_group.SetHorizontalTabWidth(2, Size.Column.x);

	bar_view_group.SetVerticalTabHeight(0, Size.Bar.y);

	// show game group
	game_group.Title = "Game";
	game_group.MoveToCenter();
	game_group.Show();

	Engine.Main();

	Engine.Shutdown();
}

Here is the result of this example:

image.png

You can also try setting the separator values in the groups:

// set tabs in groups
game_group.SetSeparatorValue(0, 0.2f);
game_group.SetSeparatorValue(1, 0.8f);

bar_view_group.SetSeparatorValue(0, 0.2f);

 

  • Thanks 1
Link to comment

Thanks @karpych11 

I had played with some of those setting and ended up with something similar, but setting tabs doesn't quite do it.
The cardinal boxes need to be the same size. Ideally fixed (x.px, y.px).
Even though you set c1 & c3 to the same value, c1 is wider than c3. (Bug?)  

The approach of setting the Separator works better but requires recomputing to keep a fixed width when the (outer) window changes size. 

Some of my problem was the way I was grouping. I'm not clear on "decompose". 

I had tried this:

StackGroups(v_1, wins.StackGroups(v_2, v_3, HORIZONTAL), HORIZONTAL, true) 

It seems to say, Stack Groups G2 & G3 (to new returned "Gtemp"), then Stack Groups G1 with Gtemp(decomposed).
Shouldn't decompose split Gtemp back into two groups?  Giving a Group of [v_1, v_2, v_3].

How does that differ from:

win game_group = wins.StackGroups(n_w_group, bar_view_group, HORIZONTAL);
wins.StackToGroup(game_group, s_e_group);
Edited by Tessalator
Add differfrom..
Link to comment

Window refactoring is currently planned. This will also affect the size of the tabs. It is planned to add the following:

  1. setting the minimum and maximum sizes
  2. using fixed sizes
  3. change the size of the group depending on the size of the tabs

 

The decompose_second flag in all grouping methods in the WindowManager was left by accident. All the logic related to this is already missing.

 

In your case, I would still recommend using setSeparatorValue() because it's probably the most stable option. But if you need to work in pixels, you can try using setSeparatorPosition(). Unfortunately, resizing the group will change the size of the tabs anyway. This behavior will only be configurable in a future update.

 

In the updated example, the tab sizes will be the same in pixels. Also, these sizes will be restored when the group size is changed.

class UnigineApp
{
	static win game_group = null;
	static win bar_view_group = null;

	const int DEFAULT_SEPARATOR_SIZE = 8;

	[STAThread]
	static void Main(string[] args)
	{
		Engine.Init(args);

		win og = wins.MainWindow; og.Main = false; og.Hide();

		win view = new win(Size.View, (int)(MAIN)) { Title = "Board" };
		win bar = new win(Size.Bar, snip.FixedBox) { Title = "Status" };
		win n = new win(Size.Box, snip.FixedBox) { Title = "N" };
		win s = new win(Size.Box, snip.FixedBox) { Title = "S" };
		win e = new win(Size.Box, snip.FixedBox) { Title = "E" };
		win w = new win(Size.Box, snip.FixedBox) { Title = "W" };

		// create columns
		win n_w_group = wins.Stack(n, w, 1, VERTICAL);
		bar_view_group = wins.Stack(bar, view, 1, VERTICAL);
		win s_e_group = wins.Stack(s, e, 1, VERTICAL);

		// merge columns into one row
		game_group = wins.StackGroups(n_w_group, bar_view_group, HORIZONTAL);
		wins.StackToGroup(game_group, s_e_group);

		game_group.Size = Size.Game;
		game_group.Arrange();
		game_group.Expand();

		// set tabs in groups
		SetGameLayout(Size.Game.x, Size.Game.y);
		game_group.AddCallback(win.CALLBACK_INDEX.WINDOW_EVENT, OnWindowEvent);

		// show game group
		game_group.Title = "Game";
		game_group.MoveToCenter();
		game_group.Show();

		Engine.Main();

		Engine.Shutdown();
	}

	static void SetGameLayout(int width, int height)
	{
		game_group.SetSeparatorPosition(0, Size.Column.x);
		game_group.SetSeparatorPosition(1, width - Size.Column.x - DEFAULT_SEPARATOR_SIZE);

		bar_view_group.SetSeparatorPosition(0, Size.Bar.y);
	}

	static void OnWindowEvent(WindowEvent e)
	{
		WindowEventGeneric generic_event = e as WindowEventGeneric;
		if (generic_event == null || generic_event.Action != WindowEventGeneric.ACTION.RESIZED)
			return;

		SetGameLayout(e.Size.x, e.Size.y);
	}

	internal interface snip
	{
		internal const bool Borders = false;
		internal static int FixedBox => (int)(SHOWN | FIXED_SIZE);
	}
	internal interface Size
	{
		internal static ivec2 Game => new(1200, 800);
		internal static ivec2 Box => new(200, 400);
		internal static ivec2 View => new(800, 800);
		internal static ivec2 Column => new(200, 800);
		internal static ivec2 Bar => new(1200, 200);
	}

}

separator_position.png

  • Like 1
Link to comment
×
×
  • Create New...