feat: better layout
This commit is contained in:
@@ -19,7 +19,8 @@ export default class BeatGroupSettingsView extends UINode implements ISubscriber
|
|||||||
private timeSigUpInput!: NumberInputView;
|
private timeSigUpInput!: NumberInputView;
|
||||||
private loopSettingsView!: BeatLikeLoopSettingsView;
|
private loopSettingsView!: BeatLikeLoopSettingsView;
|
||||||
private autoBeatLengthCheckbox!: BoolBoxView;
|
private autoBeatLengthCheckbox!: BoolBoxView;
|
||||||
private forceFullBarsCheckbox!: BoolBoxView;
|
private beatSettingsViews: BeatSettingsView[] = [];
|
||||||
|
private beatSettingsContainer!: HTMLDivElement;
|
||||||
private autoBeatOptions!: HTMLElement;
|
private autoBeatOptions!: HTMLElement;
|
||||||
|
|
||||||
constructor(options: BeatGroupSettingsUINodeOptions) {
|
constructor(options: BeatGroupSettingsUINodeOptions) {
|
||||||
@@ -29,6 +30,7 @@ export default class BeatGroupSettingsView extends UINode implements ISubscriber
|
|||||||
BeatGroupEvents.BarCountChanged,
|
BeatGroupEvents.BarCountChanged,
|
||||||
BeatGroupEvents.TimeSigUpChanged,
|
BeatGroupEvents.TimeSigUpChanged,
|
||||||
BeatEvents.DisplayTypeChanged,
|
BeatEvents.DisplayTypeChanged,
|
||||||
|
BeatGroupEvents.BeatListChanged,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +45,27 @@ export default class BeatGroupSettingsView extends UINode implements ISubscriber
|
|||||||
} else {
|
} else {
|
||||||
this.autoBeatOptions.classList.remove("visible");
|
this.autoBeatOptions.classList.remove("visible");
|
||||||
}
|
}
|
||||||
|
} else if (event === BeatGroupEvents.BeatListChanged) {
|
||||||
|
this.remakeBeatSettingsViews();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private remakeBeatSettingsViews() {
|
||||||
|
const beatCount = this.beatGroup.getBeatCount();
|
||||||
|
this.beatSettingsViews.splice(beatCount, this.beatSettingsViews.length - beatCount);
|
||||||
|
for (let i = 0; i < beatCount; i++) {
|
||||||
|
if (this.beatSettingsViews[i]) {
|
||||||
|
this.beatSettingsViews[i].setBeat(this.beatGroup.getBeatByIndex(i));
|
||||||
|
} else {
|
||||||
|
this.beatSettingsViews.push(new BeatSettingsView({ beat: this.beatGroup.getBeatByIndex(i) }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.beatSettingsContainer) {
|
||||||
|
this.beatSettingsContainer = UINode.make("div", {
|
||||||
|
subs: this.beatSettingsViews.map(view => view.render())
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.beatSettingsContainer.replaceChildren(...this.beatSettingsViews.map(view => view.render()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +99,7 @@ export default class BeatGroupSettingsView extends UINode implements ISubscriber
|
|||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
const beatSettingsViews = [];
|
this.remakeBeatSettingsViews();
|
||||||
for (let i = 0; i < this.beatGroup.getBeatCount(); i++) {
|
|
||||||
beatSettingsViews.push(new BeatSettingsView({ beat: this.beatGroup.getBeatByIndex(i) }));
|
|
||||||
}
|
|
||||||
this.node = UINode.make("div", {
|
this.node = UINode.make("div", {
|
||||||
classes: ["beat-group-settings"],
|
classes: ["beat-group-settings"],
|
||||||
subs: [
|
subs: [
|
||||||
@@ -104,7 +124,7 @@ export default class BeatGroupSettingsView extends UINode implements ISubscriber
|
|||||||
innerText: "New Track",
|
innerText: "New Track",
|
||||||
onclick: () => this.beatGroup.addBeat(),
|
onclick: () => this.beatGroup.addBeat(),
|
||||||
}),
|
}),
|
||||||
...beatSettingsViews.map(view => view.render()),
|
this.beatSettingsContainer
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
.loop-settings {
|
.loop-settings {
|
||||||
margin-top: 1em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.loop-settings-option-group {
|
.loop-settings-option-group {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import BoolBoxView from "../Widgets/BoolBox/BoolBoxView";
|
|||||||
|
|
||||||
export type BeatLikeLoopSettingsViewUINodeOptions = UINodeOptions & {
|
export type BeatLikeLoopSettingsViewUINodeOptions = UINodeOptions & {
|
||||||
beatLike: BeatLike,
|
beatLike: BeatLike,
|
||||||
|
title?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class BeatLikeLoopSettingsView extends UINode implements ISubscriber {
|
export default class BeatLikeLoopSettingsView extends UINode implements ISubscriber {
|
||||||
@@ -16,10 +17,12 @@ export default class BeatLikeLoopSettingsView extends UINode implements ISubscri
|
|||||||
private loopLengthInput!: NumberInputView;
|
private loopLengthInput!: NumberInputView;
|
||||||
private loopCheckbox!: BoolBoxView;
|
private loopCheckbox!: BoolBoxView;
|
||||||
private loopLengthSection!: HTMLDivElement;
|
private loopLengthSection!: HTMLDivElement;
|
||||||
|
private title: string;
|
||||||
|
|
||||||
constructor(options: BeatLikeLoopSettingsViewUINodeOptions) {
|
constructor(options: BeatLikeLoopSettingsViewUINodeOptions) {
|
||||||
super(options);
|
super(options);
|
||||||
this.beatLike = options.beatLike;
|
this.beatLike = options.beatLike;
|
||||||
|
this.title = options.title ?? "Looping settings:";
|
||||||
this.setupBindings();
|
this.setupBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +33,7 @@ export default class BeatLikeLoopSettingsView extends UINode implements ISubscri
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
notify<T extends string | number>(publisher: IPublisher<T>, event: "all" | T[] | T): void {
|
notify<T extends string | number>(publisher: IPublisher<T> | null, event: "all" | T[] | T): void {
|
||||||
if (event === BeatEvents.LoopLengthChanged) {
|
if (event === BeatEvents.LoopLengthChanged) {
|
||||||
this.loopLengthInput.setValue(this.beatLike.getLoopLength());
|
this.loopLengthInput.setValue(this.beatLike.getLoopLength());
|
||||||
} else if (event === BeatEvents.DisplayTypeChanged) {
|
} else if (event === BeatEvents.DisplayTypeChanged) {
|
||||||
@@ -43,6 +46,12 @@ export default class BeatLikeLoopSettingsView extends UINode implements ISubscri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setBeatLike(beatLike: BeatLike): void {
|
||||||
|
this.beatLike = beatLike;
|
||||||
|
this.notify(null, BeatEvents.LoopLengthChanged);
|
||||||
|
this.notify(null, BeatEvents.DisplayTypeChanged);
|
||||||
|
}
|
||||||
|
|
||||||
rebuild(): HTMLElement {
|
rebuild(): HTMLElement {
|
||||||
this.loopLengthInput = new NumberInputView({
|
this.loopLengthInput = new NumberInputView({
|
||||||
initialValue: this.beatLike.getLoopLength(),
|
initialValue: this.beatLike.getLoopLength(),
|
||||||
@@ -70,7 +79,7 @@ export default class BeatLikeLoopSettingsView extends UINode implements ISubscri
|
|||||||
this.node = UINode.make("div", {
|
this.node = UINode.make("div", {
|
||||||
classes: ["loop-settings"],
|
classes: ["loop-settings"],
|
||||||
subs: [
|
subs: [
|
||||||
UINode.make("p", {innerText: "Global looping settings:"}),
|
UINode.make("p", {innerText: this.title}),
|
||||||
UINode.make("div", {
|
UINode.make("div", {
|
||||||
classes: ["loop-settings-option-group"],
|
classes: ["loop-settings-option-group"],
|
||||||
subs: [
|
subs: [
|
||||||
|
|||||||
@@ -24,3 +24,8 @@
|
|||||||
.beat-settings-time-sig input {
|
.beat-settings-time-sig input {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.beat-settings-name-field {
|
||||||
|
margin: auto auto auto auto;
|
||||||
|
width: 5em;
|
||||||
|
}
|
||||||
@@ -11,7 +11,6 @@ export type BeatSettingsViewUINodeOptions = UINodeOptions & {
|
|||||||
|
|
||||||
export default class BeatSettingsView extends UINode implements ISubscriber {
|
export default class BeatSettingsView extends UINode implements ISubscriber {
|
||||||
private beat: Beat;
|
private beat: Beat;
|
||||||
private visible = false;
|
|
||||||
private nameInput!: HTMLInputElement;
|
private nameInput!: HTMLInputElement;
|
||||||
private loopSettingsView!: BeatLikeLoopSettingsView;
|
private loopSettingsView!: BeatLikeLoopSettingsView;
|
||||||
|
|
||||||
@@ -25,7 +24,13 @@ export default class BeatSettingsView extends UINode implements ISubscriber {
|
|||||||
this.beat.addSubscriber(this, "all");
|
this.beat.addSubscriber(this, "all");
|
||||||
}
|
}
|
||||||
|
|
||||||
notify<T extends string | number>(publisher: IPublisher<T>, event: "all" | T[] | T): void {
|
setBeat(beat: Beat): void {
|
||||||
|
this.beat = beat;
|
||||||
|
this.loopSettingsView.setBeatLike(beat);
|
||||||
|
this.notify(null, BeatEvents.NewName);
|
||||||
|
}
|
||||||
|
|
||||||
|
notify<T extends string | number>(publisher: IPublisher<T> | null, event: "all" | T[] | T): void {
|
||||||
if (event === BeatEvents.NewName) {
|
if (event === BeatEvents.NewName) {
|
||||||
this.nameInput.value = this.beat.getName();
|
this.nameInput.value = this.beat.getName();
|
||||||
}
|
}
|
||||||
@@ -35,6 +40,7 @@ export default class BeatSettingsView extends UINode implements ISubscriber {
|
|||||||
this.loopSettingsView = new BeatLikeLoopSettingsView({beatLike: this.beat});
|
this.loopSettingsView = new BeatLikeLoopSettingsView({beatLike: this.beat});
|
||||||
this.nameInput = UINode.make("input", {
|
this.nameInput = UINode.make("input", {
|
||||||
value: this.beat.getName(),
|
value: this.beat.getName(),
|
||||||
|
classes: ["beat-settings-name-field"],
|
||||||
type: "text",
|
type: "text",
|
||||||
oninput: (event: Event) => this.beat.setName((event.target as HTMLInputElement).value),
|
oninput: (event: Event) => this.beat.setName((event.target as HTMLInputElement).value),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
background-color: var(--color-bg-light);
|
background-color: var(--color-bg-light);
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 30em;
|
width: 30em;
|
||||||
padding: 3em;
|
padding: 0 3em 0 3em;
|
||||||
|
overflow: scroll;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user