Skip to content

Commit ddbe8f7

Browse files
Fix BarBackgrounds when switching from one layout to the other
1 parent cbe5800 commit ddbe8f7

3 files changed

Lines changed: 98 additions & 11 deletions

File tree

resources/js/components/molecules/MAlignment.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@
5757
watch: {
5858
alignment(newVal, oldVal) {
5959
this.applyCorrectStyleSet(newVal);
60-
},
61-
62-
getStyleSet(newVal, oldVal) {
63-
if((newVal === 'green' || newVal === 'greenCentered') && this.alignment === Alignments.center) {
64-
this.$store.commit('canvas/setAlignment', Alignments.left);
65-
}
6660
}
6761
},
6862
methods: {

resources/js/components/molecules/MBarBlock.vue

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import {
4949
BarSchemes,
5050
BarTypes,
51+
BackgroundTypes,
5152
ColorSchemes,
5253
StyleSetTypes
5354
} from "../../service/canvas/Constants";
@@ -70,6 +71,7 @@
7071
colorSchema: 'canvas/getColorSchema',
7172
bars: 'canvas/getBars',
7273
textFitsImage: 'canvas/getTextFitsImage',
74+
backgroundType: 'canvas/getBackgroundType',
7375
}),
7476
7577
fontSizePercent: {
@@ -131,6 +133,72 @@
131133
)
132134
},
133135
136+
updateBarSchemas() {
137+
// Handle bars based on layout and color scheme
138+
if (this.bars.length > 0 && this.bars[0].type === BarTypes.headline) {
139+
const schema = this.getSchemaForBar(0);
140+
this.$store.dispatch('canvas/setBar', {
141+
index: 0,
142+
bar: { ...this.bars[0], schema }
143+
});
144+
}
145+
146+
// Force the second headline to use the scheme for current layout
147+
if (this.bars.length > 1 && this.bars[1].type === BarTypes.headline) {
148+
const schema = this.getSchemaForBar(1);
149+
this.$store.dispatch('canvas/setBar', {
150+
index: 1,
151+
bar: { ...this.bars[1], schema }
152+
});
153+
}
154+
155+
// Handle third headline bar if present (for green layout with 3 headline bars)
156+
if (this.bars.length > 2 && this.bars[2].type === BarTypes.headline &&
157+
!(this.styleSet === StyleSetTypes.green2025 || this.styleSet === StyleSetTypes.green2025Centered)) {
158+
this.$store.dispatch('canvas/setBar', {
159+
index: 2,
160+
bar: { ...this.bars[2], schema: BarSchemes.magenta }
161+
});
162+
}
163+
164+
// For subline, use the computed sublineSchema which is based on current style set
165+
if (this.bars.length > 2 && this.bars[2].type === BarTypes.subline) {
166+
this.$store.dispatch('canvas/setBar', {
167+
index: 2,
168+
bar: { ...this.bars[2], schema: this.sublineSchema }
169+
});
170+
}
171+
},
172+
173+
getSchemaForBar(index) {
174+
// Green2025 layout
175+
if (this.styleSet === StyleSetTypes.green2025 || this.styleSet === StyleSetTypes.green2025Centered) {
176+
return BarSchemes.green2025;
177+
}
178+
179+
// Young layout
180+
if (this.styleSet === StyleSetTypes.young) {
181+
if(index === 0) {
182+
return (this.colorSchema === ColorSchemes.white)
183+
? BarSchemes.white
184+
: BarSchemes.green;
185+
} else {
186+
return BarSchemes.magenta;
187+
}
188+
}
189+
190+
// Green layout
191+
const backgroundRequiresGreen =
192+
this.backgroundType === BackgroundTypes.transparent ||
193+
this.backgroundType === BackgroundTypes.image;
194+
195+
if (index === 0 || (index === 1 && this.bars.length >2 && this.bars[2].type === BarTypes.headline)) {
196+
return backgroundRequiresGreen ? BarSchemes.green : BarSchemes.white;
197+
}
198+
199+
return BarSchemes.magenta;
200+
},
201+
134202
maybeRemoveSubline() {
135203
// remove sublines for style set young
136204
if (this.styleSet === StyleSetTypes.young) {
@@ -148,7 +216,9 @@
148216
// remove first primary headline if there are two
149217
const primaryHeadlines = this.bars.filter(
150218
bar => bar.type === BarTypes.headline
151-
&& (bar.schema === BarSchemes.white || bar.schema === BarSchemes.green)
219+
&& (bar.schema === BarSchemes.white ||
220+
bar.schema === BarSchemes.green ||
221+
bar.schema === BarSchemes.green2025)
152222
);
153223
if (primaryHeadlines.length > 1) {
154224
this.$store.commit('canvas/removeBar', {index: 0})
@@ -157,7 +227,8 @@
157227
// remove first secondary headline if there are two
158228
const secondaryHeadlines = this.bars.filter(
159229
bar => bar.type === BarTypes.headline
160-
&& (bar.schema === BarSchemes.magenta)
230+
&& (bar.schema === BarSchemes.magenta ||
231+
bar.schema === BarSchemes.transparent2025)
161232
);
162233
if (secondaryHeadlines.length > 1) {
163234
this.$store.commit('canvas/removeBar', {index: 1})
@@ -168,8 +239,17 @@
168239
169240
watch: {
170241
styleSet() {
171-
this.maybeRemoveSubline()
172-
this.maybeRemoveHeadline()
242+
this.maybeRemoveSubline();
243+
this.maybeRemoveHeadline();
244+
245+
this.$nextTick(() => {
246+
this.updateBarSchemas();
247+
});
248+
},
249+
colorSchema() {
250+
this.$nextTick(() => {
251+
this.updateBarSchemas();
252+
});
173253
},
174254
textFitsImage(val) {
175255
if (!val) {

resources/js/components/organisms/OImagery.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
</template>
7373

7474
<script>
75-
import {BackgroundTypes, HugeImageSurfaceLimit, StyleSetTypes} from "../../service/canvas/Constants";
75+
import {BackgroundTypes, HugeImageSurfaceLimit, StyleSetTypes, Alignments} from "../../service/canvas/Constants";
7676
import MBarBlock from "../molecules/MBarBlock";
7777
import MBackgroundBlock from "../molecules/MBackgroundBlock";
7878
import MBorderBlock from "../molecules/MBorderBlock";
@@ -122,6 +122,7 @@ let requestedAnimationFrame;
122122
context: null,
123123
backgroundTypes: BackgroundTypes,
124124
styleSetTypes: StyleSetTypes,
125+
alignments: Alignments,
125126
126127
viewHeight: document.documentElement.clientHeight,
127128
viewWidth: document.documentElement.clientWidth,
@@ -538,6 +539,18 @@ let requestedAnimationFrame;
538539
},
539540
styleSet(value) {
540541
this.engine.styleSet = value;
542+
543+
const currentAlignment = this.$store.getters['canvas/getAlignment'];
544+
545+
if ((value === StyleSetTypes.green || value === StyleSetTypes.green2025) &&
546+
currentAlignment !== Alignments.right) {
547+
this.$store.dispatch('canvas/setAlignment', Alignments.left);
548+
} else if (value === StyleSetTypes.greenCentered ||
549+
value === StyleSetTypes.green2025Centered ||
550+
value === StyleSetTypes.young) {
551+
this.$store.dispatch('canvas/setAlignment', Alignments.center);
552+
}
553+
541554
this.draw().catch(console.debug);
542555
},
543556
format(value) {

0 commit comments

Comments
 (0)