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
|
use layout;
use core:geometry;
/**
* Wrappers for using the layout library together with the Ui library.
*/
/**
* Wrapper around windows in the UI class.
*/
class UiComponent extends Component {
// The window we're wrapping.
Window window;
// Minimum width of the component.
Float minWidth;
// Minimum height of the component.
Float minHeight;
// Create.
init(Window window) {
init() { window = window; }
}
// Get position.
Rect pos() {
window.pos;
}
// Set position.
assign pos(Rect p) {
window.pos = p;
}
// Minimum size.
Size minSize() {
Size r = window.minSize();
r.w = max(r.w, minWidth);
r.h = max(r.h, minHeight);
r;
}
}
// Create components.
UiComponent component(Window window) {
UiComponent(window);
}
/**
* Custom subclass of Container for sub-layouts. This is approximately what "container X" would
* generate.
*/
class UiContainer extends Container {
init(Layout layout) {
init {
layout = layout;
}
}
Layout layout;
Size minSize() : override {
layout.minSize;
}
void resized(Size size) : override {
layout.pos = Rect(size);
}
}
|