Skip to content

Commit

Permalink
add SpinButton.range, SpinButton.increments
Browse files Browse the repository at this point in the history
  • Loading branch information
Aylur committed Mar 7, 2024
1 parent dfff165 commit 5da9b96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Features

- Calendar.detail
- SpinButton.range
- SpinButton.increments

## Fixes

Expand Down
16 changes: 16 additions & 0 deletions src/widgets/spinbutton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export type SpinButtonProps<
Self = SpinButton<Attr>,
> = BaseProps<Self, Gtk.SpinButton.ConstructorProperties & {
on_value_changed?: Event<Self>
range?: [min: number, max: number],
increments?: [step: number, page: number],
}, Attr>;

export function newSpinButton<
Expand All @@ -23,6 +25,8 @@ export class SpinButton<Attr> extends Gtk.SpinButton {
register(this, {
properties: {
'on-value-changed': ['jsobject', 'rw'],
'range': ['jsobject', 'rw'],
'increments': ['jsobject', 'rw'],
},
});
}
Expand All @@ -34,6 +38,18 @@ export class SpinButton<Attr> extends Gtk.SpinButton {

get on_value_changed() { return this._get('on-value-changed') || (() => false); }
set on_value_changed(callback: Event<this>) { this._set('on-value-changed', callback); }

get range() { return this.get_range(); }
set range([min, max]: [number, number]) {
if (typeof min === 'number' && typeof max === 'number')
this.set_range(min, max);
}

get increments() { return this.get_increments(); }
set increments([step, page]: [number, number]) {
if (typeof step === 'number' && typeof page === 'number')
this.set_increments(step, page);
}
}

export default SpinButton;

0 comments on commit 5da9b96

Please sign in to comment.