|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + osparc - the simcore frontend |
| 4 | +
|
| 5 | + https://osparc.io |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2025 IT'IS Foundation, https://itis.swiss |
| 9 | +
|
| 10 | + License: |
| 11 | + MIT: https://opensource.org/licenses/MIT |
| 12 | +
|
| 13 | + Authors: |
| 14 | + * Odei Maiz (odeimaiz) |
| 15 | +
|
| 16 | +************************************************************************ */ |
| 17 | + |
| 18 | + |
| 19 | +qx.Class.define("osparc.widget.SectionBox", { |
| 20 | + extend: qx.ui.core.Widget, |
| 21 | + include: [qx.ui.core.MRemoteChildrenHandling, qx.ui.core.MLayoutHandling], |
| 22 | + |
| 23 | + /** |
| 24 | + * @param legend {String?} Initial title |
| 25 | + */ |
| 26 | + construct: function(legend) { |
| 27 | + this.base(arguments); |
| 28 | + |
| 29 | + this._setLayout(new qx.ui.layout.Canvas()); |
| 30 | + |
| 31 | + if (legend) { |
| 32 | + this.setLegend(legend); |
| 33 | + } |
| 34 | + |
| 35 | + // ensure child controls exist |
| 36 | + this.getChildControl("frame"); |
| 37 | + this.getChildControl("legend"); |
| 38 | + }, |
| 39 | + |
| 40 | + properties: { |
| 41 | + /** Title text shown on top of the border */ |
| 42 | + legend: { |
| 43 | + check: "String", |
| 44 | + init: "", |
| 45 | + event: "changeLegend", |
| 46 | + }, |
| 47 | + |
| 48 | + /** Background for the title; should match panel bg token */ |
| 49 | + legendBackgroundColor: { |
| 50 | + check: "Color", |
| 51 | + init: "background-pane", |
| 52 | + event: "changeLegendBackgroundColor", |
| 53 | + }, |
| 54 | + }, |
| 55 | + |
| 56 | + members: { |
| 57 | + _frame: null, |
| 58 | + |
| 59 | + // Children you add to this widget will be forwarded into the frame: |
| 60 | + _getChildrenContainer: function() { |
| 61 | + return this._frame || this.getChildControl("frame"); |
| 62 | + }, |
| 63 | + |
| 64 | + _createChildControlImpl: function(id) { |
| 65 | + let control; |
| 66 | + switch (id) { |
| 67 | + case "frame": |
| 68 | + control = this._frame = new qx.ui.container.Composite(new qx.ui.layout.VBox(10)).set({ |
| 69 | + decorator: new qx.ui.decoration.Decorator().set({ |
| 70 | + width: 1, |
| 71 | + style: "solid", |
| 72 | + color: "background-main-2", |
| 73 | + radius: 4, |
| 74 | + }), |
| 75 | + padding: [10 + 4, 10, 10, 10], |
| 76 | + backgroundColor: "transparent", |
| 77 | + }); |
| 78 | + // full size, but pushed down by frameTop |
| 79 | + this._add(control, { left: 0, right: 0, bottom: 0, top: 10 }); |
| 80 | + break; |
| 81 | + case "legend": |
| 82 | + control = new qx.ui.basic.Atom().set({ |
| 83 | + font: "text-14", |
| 84 | + padding: [0, 6], |
| 85 | + }); |
| 86 | + this.bind("legend", control, "label"); |
| 87 | + this.bind("legendBackgroundColor", control, "backgroundColor"); |
| 88 | + this._add(control, { left: 12, top: 0 }); |
| 89 | + break; |
| 90 | + } |
| 91 | + return control || this.base(arguments, id); |
| 92 | + }, |
| 93 | + } |
| 94 | +}); |
0 commit comments