nice control center
This commit is contained in:
@@ -5,16 +5,99 @@ ControlCenter::ControlCenter(std::string icon, std::string name)
|
||||
: Popover(icon, name) {
|
||||
this->popover->add_css_class("control-center-popover");
|
||||
this->container.set_orientation(Gtk::Orientation::VERTICAL);
|
||||
this->container.set_spacing(0);
|
||||
this->container.set_margin_top(0);
|
||||
this->container.set_margin_bottom(0);
|
||||
this->container.set_margin_start(0);
|
||||
this->container.set_margin_end(0);
|
||||
this->container.set_spacing(10);
|
||||
this->popover->set_hexpand(false);
|
||||
this->popover->set_size_request(240, -1);
|
||||
|
||||
set_popover_child(this->container);
|
||||
|
||||
this->tabRow.set_orientation(Gtk::Orientation::HORIZONTAL);
|
||||
this->tabRow.set_spacing(4);
|
||||
this->tabRow.set_margin_bottom(4);
|
||||
this->tabRow.add_css_class("control-center-tab-row");
|
||||
|
||||
this->container.append(this->mediaControlWidget);
|
||||
this->mediaControl.set_label("\uf5d3"); // control icon
|
||||
this->mediaControl.add_css_class("tab-icon");
|
||||
this->testTabButton.set_label("\uE5CA"); // test icon
|
||||
this->testTabButton.add_css_class("tab-icon");
|
||||
|
||||
this->tabRow.append(this->mediaControl);
|
||||
this->tabRow.append(this->testTabButton);
|
||||
|
||||
this->container.append(this->tabRow);
|
||||
|
||||
this->contentStack.set_hhomogeneous(false);
|
||||
this->contentStack.set_vhomogeneous(false);
|
||||
this->contentStack.set_transition_type(Gtk::StackTransitionType::CROSSFADE);
|
||||
this->contentStack.set_transition_duration(150);
|
||||
|
||||
this->controlCenterContainer.set_orientation(Gtk::Orientation::VERTICAL);
|
||||
this->controlCenterContainer.set_spacing(4);
|
||||
|
||||
this->testLabel.set_text("Test tab");
|
||||
|
||||
this->contentStack.add(this->controlCenterContainer, "controls", "Controls");
|
||||
this->contentStack.add(this->testLabel, "test", "Test");
|
||||
this->contentStack.set_visible_child("controls");
|
||||
this->setActiveTab("controls");
|
||||
|
||||
this->container.append(this->contentStack);
|
||||
|
||||
this->mediaControl.signal_clicked().connect([this]() {
|
||||
this->setActiveTab("controls");
|
||||
});
|
||||
|
||||
this->testTabButton.signal_clicked().connect([this]() {
|
||||
this->setActiveTab("test");
|
||||
});
|
||||
|
||||
this->mprisController->signal_player_registered().connect(
|
||||
[this](const std::string &bus_name) {
|
||||
this->addPlayerWidget(bus_name);
|
||||
});
|
||||
|
||||
this->mprisController->signal_player_deregistered().connect(
|
||||
[this](const std::string &bus_name) {
|
||||
this->removePlayerWidget(bus_name);
|
||||
});
|
||||
|
||||
for (const auto &bus_name : this->mprisController->get_registered_players()) {
|
||||
this->addPlayerWidget(bus_name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ControlCenter::setActiveTab(const std::string &tab_name) {
|
||||
this->contentStack.set_visible_child(tab_name);
|
||||
|
||||
this->mediaControl.remove_css_class("active-button");
|
||||
this->testTabButton.remove_css_class("active-button");
|
||||
|
||||
if (tab_name == "controls") {
|
||||
this->mediaControl.add_css_class("active-button");
|
||||
} else if (tab_name == "test") {
|
||||
this->testTabButton.add_css_class("active-button");
|
||||
}
|
||||
}
|
||||
|
||||
void ControlCenter::addPlayerWidget(const std::string &bus_name) {
|
||||
if (this->mediaWidgets.find(bus_name) != this->mediaWidgets.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto controller = MprisController::createForPlayer(bus_name);
|
||||
auto widget = Gtk::make_managed<MediaControlWidget>(controller);
|
||||
this->mediaWidgets.emplace(bus_name, widget);
|
||||
this->controlCenterContainer.append(*widget);
|
||||
}
|
||||
|
||||
void ControlCenter::removePlayerWidget(const std::string &bus_name) {
|
||||
auto it = this->mediaWidgets.find(bus_name);
|
||||
if (it == this->mediaWidgets.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->controlCenterContainer.remove(*it->second);
|
||||
this->mediaWidgets.erase(it);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user