add: widget prop setter checks

This commit is contained in:
Aylur
2023-10-07 21:44:34 +02:00
parent 528b51b51e
commit 25f09733ff
12 changed files with 57 additions and 24 deletions
+6 -3
View File
@@ -13,7 +13,7 @@ export default class AgsBox extends Gtk.Box {
}, this);
}
constructor({ children, ...rest }: { children?: Gtk.Widget[] | null }) {
constructor({ children, ...rest }: { children?: Gtk.Widget[] }) {
super(rest);
if (children)
@@ -21,7 +21,7 @@ export default class AgsBox extends Gtk.Box {
}
get children() { return this.get_children(); }
set children(children: Gtk.Widget[] | null) {
set children(children: Gtk.Widget[]) {
const newChildren = children || [];
this.get_children()
@@ -42,7 +42,10 @@ export default class AgsBox extends Gtk.Box {
}
get vertical() { return this.orientation === Gtk.Orientation.VERTICAL; }
set vertical(vertical) {
set vertical(vertical: boolean) {
if (this.vertical === vertical)
return;
this.orientation = vertical
? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL;
+1 -4
View File
@@ -26,15 +26,12 @@ export default class AgsCenterBox extends AgsBox {
}, this);
}
set children(children: Gtk.Widget[] | null) {
set children(children: Gtk.Widget[]) {
const newChildren = children || [];
newChildren.filter(ch => !newChildren?.includes(ch))
.forEach(ch => ch.destroy());
if (!children)
return;
if (children[0])
this.start_widget = children[0];
+14 -2
View File
@@ -29,6 +29,9 @@ export default class AgsCircularProgress extends Gtk.Bin {
// @ts-expect-error
get rounded() { return this._rounded; }
set rounded(r: boolean) {
if (this.rounded === r)
return;
// @ts-expect-error
this._rounded = r;
this.notify('rounded');
@@ -37,9 +40,12 @@ export default class AgsCircularProgress extends Gtk.Bin {
// @ts-expect-error
get inverted() { return this._inverted; }
set inverted(c: boolean) {
set inverted(inverted: boolean) {
if (this.inverted === inverted)
return;
// @ts-expect-error
this._inverted = c;
this._inverted = inverted;
this.notify('inverted');
this.queue_draw();
}
@@ -47,6 +53,9 @@ export default class AgsCircularProgress extends Gtk.Bin {
// @ts-expect-error
get start_at() { return this._startAt; }
set start_at(value: number) {
if (this.start_at === value)
return;
if (value > 1)
value = 1;
@@ -62,6 +71,9 @@ export default class AgsCircularProgress extends Gtk.Bin {
// @ts-expect-error
get value() { return this._value; }
set value(value: number) {
if (this.value === value)
return;
if (value > 1)
value = 1;
+2 -2
View File
@@ -40,7 +40,7 @@ export default class AgsLabel extends Gtk.Label {
get truncate() { return truncates[this.ellipsize]; }
set truncate(truncate: string) {
if (!truncate)
if (this.truncate === truncate)
return;
if (!truncate.includes(truncate)) {
@@ -54,7 +54,7 @@ export default class AgsLabel extends Gtk.Label {
get justification() { return justifications[this.justify]; }
set justification(justify: string) {
if (!justify)
if (this.justification === justify)
return;
if (!justifications.includes(justify)) {
+1 -1
View File
@@ -39,7 +39,7 @@ export class AgsMenu extends Gtk.Menu {
}
get children() { return this.get_children(); }
set children(children: Gtk.Widget[] | null) {
set children(children: Gtk.Widget[]) {
this.get_children().forEach(ch => ch.destroy());
if (!children)
+3
View File
@@ -20,6 +20,9 @@ export default class AgsOverlay extends Gtk.Overlay {
}
set pass_through(passthrough: boolean) {
if (this.pass_through === passthrough)
return;
this.get_children().forEach(ch =>
this.set_overlay_pass_through(ch, passthrough));
+7 -1
View File
@@ -15,12 +15,18 @@ export default class AgsProgressBar extends Gtk.ProgressBar {
get value() { return this.fraction; }
set value(value: number) {
if (this.value === value)
return;
this.fraction = value;
this.notify('value');
}
get vertical() { return this.orientation === Gtk.Orientation.VERTICAL; }
set vertical(vertical) {
set vertical(vertical: boolean) {
if (this.vertical === vertical)
return;
this.orientation = vertical
? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL;
+1 -1
View File
@@ -20,7 +20,7 @@ export default class AgsRevealer extends Gtk.Revealer {
get transition() { return transitions[this.transitionType]; }
set transition(transition: string) {
if (!transition)
if (!transition || this.transition === transition)
return;
if (!transitions.includes(transition)) {
+2 -2
View File
@@ -26,7 +26,7 @@ export default class AgsScrollable extends Gtk.ScrolledWindow {
// @ts-expect-error
get hscroll() { return this._hscroll; }
set hscroll(hscroll: string) {
if (!hscroll)
if (!hscroll || this.hscroll === hscroll)
return;
if (!policy.includes(hscroll)) {
@@ -43,7 +43,7 @@ export default class AgsScrollable extends Gtk.ScrolledWindow {
// @ts-expect-error
get vscroll() { return this._vscroll; }
set vscroll(vscroll: string) {
if (!vscroll)
if (!vscroll || this.vscroll === vscroll)
return;
if (!policy.includes(vscroll)) {
+16 -1
View File
@@ -61,7 +61,7 @@ export default class AgsSlider extends Gtk.Scale {
get value() { return this.adjustment.value; }
set value(value: number) {
if (this.dragging)
if (this.dragging || this.value === value)
return;
this.adjustment.value = value;
@@ -70,18 +70,27 @@ export default class AgsSlider extends Gtk.Scale {
get min() { return this.adjustment.lower; }
set min(min: number) {
if (this.min === min)
return;
this.adjustment.lower = min;
this.notify('min');
}
get max() { return this.adjustment.upper; }
set max(max: number) {
if (this.max === max)
return;
this.adjustment.upper = max;
this.notify('max');
}
get step() { return this.adjustment.stepIncrement; }
set step(step: number) {
if (this.step === step)
return;
this.adjustment.stepIncrement = step;
this.notify('step');
}
@@ -89,6 +98,9 @@ export default class AgsSlider extends Gtk.Scale {
// @ts-expect-error
get dragging() { return this._dragging; }
set dragging(dragging: boolean) {
if (this.dragging === dragging)
return;
// @ts-expect-error
this._dragging = dragging;
this.notify('dragging');
@@ -96,6 +108,9 @@ export default class AgsSlider extends Gtk.Scale {
get vertical() { return this.orientation === Gtk.Orientation.VERTICAL; }
set vertical(vertical) {
if (this.vertical === vertical)
return;
this.orientation = vertical
? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL;
+2 -5
View File
@@ -62,7 +62,7 @@ export default class AgsStack extends Gtk.Stack {
get transition() { return transitions[this.transitionType]; }
set transition(transition: string) {
if (typeof transition !== 'string')
if (this.transition === transition)
return;
if (!transitions.includes(transition)) {
@@ -76,14 +76,11 @@ export default class AgsStack extends Gtk.Stack {
get shown() { return this.visible_child_name; }
set shown(name: string) {
if (name === null || !this.get_child_by_name(name)) {
if (!this.get_child_by_name(name)) {
this.visible = false;
return;
}
if (!name)
return;
this.visible = true;
this.set_visible_child_name(name);
this.notify('shown');
+2 -2
View File
@@ -167,7 +167,7 @@ export default class AgsWindow extends Gtk.Window {
// @ts-expect-error
get popup() { return !!this._popup; }
// this will get removed in gtk4
// this will be removed in gtk4
set popup(popup: boolean) {
if (this.popup === popup)
return;
@@ -187,7 +187,7 @@ export default class AgsWindow extends Gtk.Window {
});
}
this.notify('notify');
this.notify('popup');
}
get focusable() {