Skip to content

Commit

Permalink
feat; use AdwToggleGroup for counterpart switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Sep 22, 2024
1 parent b757e72 commit e65a53d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
25 changes: 10 additions & 15 deletions data/ui/components/player/now-playing/counterpart-switcher.blp
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
using Gtk 4.0;
using Adw 1;

template $MuzikaNPCounterpartSwitcher : Box {
styles ["linked"]
template $MuzikaNPCounterpartSwitcher : Adw.Bin {
Adw.ToggleGroup toggle_group {
Adw.Toggle {
name: "song";
label: _("Song");
}

ToggleButton music_counterpart {
label: _("Song");

action-name: "queue.current-is-video";
action-target: "false";
}

ToggleButton video_counterpart {
label: _("Video");
group: music_counterpart;

action-name: "queue.current-is-video";
action-target: "true";
Adw.Toggle {
name: "video";
label: _("Video");
}
}
}
37 changes: 35 additions & 2 deletions src/components/player/now-playing/counterpart-switcher.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import GObject from "gi://GObject";
import Gtk from "gi://Gtk?version=4.0";
import Adw from "gi://Adw";

export class MuzikaNPCounterpartSwitcher extends Gtk.Box {
import { get_player } from "src/application";

export class MuzikaNPCounterpartSwitcher extends Adw.Bin {
static {
GObject.registerClass(
{
GTypeName: "MuzikaNPCounterpartSwitcher",
Template:
"resource:///com/vixalien/muzika/ui/components/player/now-playing/counterpart-switcher.ui",
InternalChildren: ["toggle_group"],
},
this,
);
}

/// @ts-expect-error outdated types
private _toggle_group: Adw.ToggleGroup;
private _binding: GObject.Binding | null = null;

vfunc_map(): void {
super.vfunc_map();

this._binding?.unbind();

this._binding = get_player().queue.bind_property_full(
"current-is-video",
this._toggle_group,
"active-name",
GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.BIDIRECTIONAL,
(_, current_is_video: boolean) => {
return [true, current_is_video ? "video" : "song"];
},
(_, active_name: "song" | "video") => {
return [true, active_name === "video" ? true : false];
},
);
}

vfunc_unmap(): void {
super.vfunc_unmap();

this._binding?.unbind();
this._binding = null;
}
}

0 comments on commit e65a53d

Please sign in to comment.