Debian Codegraph @

phoenix/core/layout/fixed-layout.cpp

raw
1 void FixedLayout::append(Sizable& sizable, Geometry geometry) {
2 children.append({&sizable, geometry});
3 synchronizeLayout();
4 if(window()) window()->synchronizeLayout();
5 }
6
7 void FixedLayout::append(Sizable& sizable) {
8 for(auto& child : children) if(child.sizable == &sizable) return;
9 Layout::append(sizable);
10 if(window()) window()->synchronizeLayout();
11 }
12
13 Size FixedLayout::minimumSize() {
14 unsigned width = Size::Minimum, height = Size::Minimum;
15 for(auto& child : children) {
16 width = max(width, child.sizable->minimumSize().width);
17 height = max(height, child.sizable->minimumSize().height);
18 }
19 return {width, height};
20 }
21
22 void FixedLayout::remove(Sizable& sizable) {
23 for(unsigned n = 0; n < children.size(); n++) {
24 if(children[n].sizable == &sizable) {
25 children.remove(n);
26 Layout::remove(sizable);
27 if(window()) window()->synchronizeLayout();
28 break;
29 }
30 }
31 }
32
33 void FixedLayout::reset() {
34 for(auto& child : children) {
35 if(window() && dynamic_cast<Widget*>(child.sizable)) window()->remove((Widget&)*child.sizable);
36 }
37 }
38
39 void FixedLayout::setEnabled(bool enabled) {
40 Sizable::state.enabled = enabled;
41 for(auto& child : children) {
42 child.sizable->setEnabled(child.sizable->enabled());
43 }
44 }
45
46 void FixedLayout::setGeometry(Geometry geometry) {
47 }
48
49 void FixedLayout::setVisible(bool visible) {
50 Sizable::state.visible = visible;
51 for(auto& child : children) {
52 child.sizable->setVisible(child.sizable->visible());
53 }
54 }
55
56 void FixedLayout::synchronizeLayout() {
57 for(auto& child : children) {
58 Layout::append(*child.sizable);
59 Geometry childGeometry = child.geometry;
60 if((signed)childGeometry.width < 1) childGeometry.width = 1;
61 if((signed)childGeometry.height < 1) childGeometry.height = 1;
62 child.sizable->setGeometry(childGeometry);
63 }
64 }
65
66 FixedLayout::~FixedLayout() {
67 while(children.size()) remove(*children[0].sizable);
68 }