Skip to content

Commit 2d484c0

Browse files
committed
Fix applying style
1 parent 4c472af commit 2d484c0

File tree

1 file changed

+18
-16
lines changed
  • openc3-cosmos-init/plugins/packages/openc3-tool-common/src/components/widgets

1 file changed

+18
-16
lines changed

openc3-cosmos-init/plugins/packages/openc3-tool-common/src/components/widgets/Widget.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ export default {
4848
data() {
4949
return {
5050
screen: null,
51+
// We make style a data attribute so as we recurse through nested
52+
// widgets we can check to see if style attributes have been applied
53+
// at any level of the widget, i.e. if LABELVALUE applies a style
54+
// to the VALUE component then we don't want the VALUE widget to think
55+
// it doesn't have a style when it renders.
56+
style: {},
5157
}
5258
},
5359
computed: {
5460
computedStyle() {
55-
let style = {}
5661
this.settings.forEach((setting) => {
5762
const index = parseInt(setting[0])
5863
if (this.widgetIndex !== null) {
@@ -62,19 +67,25 @@ export default {
6267
return
6368
}
6469
}
65-
this.applySetting(style, setting)
70+
this.applySetting(this.style, setting)
6671
})
67-
// If they haven't defined a width then we add flex to the style
68-
if (style['width'] === undefined) {
72+
// If nothing has yet defined a width then we add flex to the style
73+
if (this.style['width'] === undefined) {
6974
// This flex allows for alignment in our widgets
7075
// The value of '0 10 100%' was achieved through trial and error
7176
// The larger flex-shrink value was critical for success
72-
style['flex'] = '0 10 100%' // flex-grow, flex-shrink, flex-basis
77+
this.style['flex'] = '0 10 100%' // flex-grow, flex-shrink, flex-basis
7378
}
74-
return style
79+
return this.style
7580
},
7681
},
7782
created() {
83+
// Look through the settings and get a reference to the screen
84+
this.settings.forEach((setting) => {
85+
if (setting[0] === '__SCREEN__') {
86+
this.screen = setting[1]
87+
}
88+
})
7889
// Figure out any subsettings that apply
7990
this.settings = this.settings
8091
.map((setting) => {
@@ -89,19 +100,10 @@ export default {
89100
// on the current widget
90101
if (this.widgetIndex === index) {
91102
return setting.slice(1)
92-
} else {
93-
return null
94103
}
95104
})
96105
// Remove any settings that we filtered out with null
97-
.filter((setting) => setting !== null)
98-
99-
// Look through the settings and get a reference to the screen
100-
this.settings.forEach((setting) => {
101-
if (setting[0] === '__SCREEN__') {
102-
this.screen = setting[1]
103-
}
104-
})
106+
.filter((setting) => setting !== undefined)
105107
},
106108
methods: {
107109
applySetting(style, setting) {

0 commit comments

Comments
 (0)