10 years ago I wrote a GUI layout engine in C++ and I'm curious how its functionality could be best approximated in the browser.
1. C++
In older GUI libraries (like Microsoft Windows'), the position and size of widgets is usually given by four numbers: left, top, width and height. My engine is different in that each of these numbers is doubled, so you have to specify eight numbers: relative left, absolute left; relative top, absolute top; relative width, absolute width; relative height and absolute height. The relative values should be given in percents of the width or height of the parent widget, and the absolute values should be given in pixels. In case of top-level windows, the "parent widget" is the desktop.
Examples:
a) 400 x 300 px window, centered on screen:
const int WINDOW_WIDTH = 400;
const int WINDOW_HEIGHT = 300;
CWindow mainWindow;
mainWindow.setPosition(0.5, -WINDOW_WIDTH / 2, 0.5, -WINDOW_HEIGHT / 2);
mainWindow.setSize(0.0, WINDOW_WIDTH, 0.0, WINDOW_HEIGHT);
b) 150 px wide button container panel at the right edge of the main window:
const int PANEL_WIDTH = 150;
CPanel buttonPanel(mainWindow);
buttonPanel.setPosition(1.0, -PANEL_WIDTH, 0.0, 0);
buttonPanel.setSize(0.0, PANEL_WIDTH, 1.0, 0);
c) Three buttons (New, Open, Save) at the top of the container panel, and one button (Exit) at the bottom:
const int BUTTON_HEIGHT = 30;
CButton newButton(buttonPanel, "New");
newButton.setPosition(0.0, 0, 0.0, 0 * BUTTON_HEIGHT);
newButton.setSize(1.0, 0, 0.0, BUTTON_HEIGHT);
CButton openButton(buttonPanel, "Open");
openButton.setPosition(0.0, 0, 0.0, 1 * BUTTON_HEIGHT);
openButton.setSize(1.0,