nicer button interactivities
This commit is contained in:
@@ -13,55 +13,59 @@ BluetoothWidget::BluetoothWidget(std::string icon, std::string title) : Popover(
|
||||
this->statusArea.set_halign(Gtk::Align::FILL);
|
||||
this->container.append(this->statusArea);
|
||||
|
||||
this->toggleButton = Gtk::make_managed<Gtk::Button>("\ue1a8");
|
||||
this->toggleButton->add_css_class("bluetooth-toggle-button");
|
||||
this->toggleButton->set_tooltip_text("Turn Bluetooth Off");
|
||||
this->toggleButton->signal_clicked().connect([this]() {
|
||||
const bool newState = !isPowered;
|
||||
setPowerState(newState);
|
||||
powerStateChangedSignal.emit(newState);
|
||||
});
|
||||
this->toggleButton->add_css_class("toggle-button");
|
||||
this->powerButton = Gtk::make_managed<Gtk::Button>("\ue1a8");
|
||||
this->powerButton->set_tooltip_text("Turn Bluetooth Off");
|
||||
this->powerButton->signal_clicked().connect(sigc::mem_fun(*this, &BluetoothWidget::onPowerButtonClicked));
|
||||
this->powerButton->add_css_class("toggle-button");
|
||||
|
||||
this->scanButton = Gtk::make_managed<Gtk::Button>("\ue1aa");
|
||||
this->scanButton->set_tooltip_text("Scan for Devices");
|
||||
this->scanButton->add_css_class("bluetooth-scan-button");
|
||||
this->scanButton->signal_clicked().connect([this]() {
|
||||
const bool newState = !isDiscovering;
|
||||
setIsDiscovering(newState);
|
||||
isDiscoveringChangedSignal.emit(newState);
|
||||
});
|
||||
this->scanButton->add_css_class("toggle-button");
|
||||
this->scanButton->signal_clicked().connect(sigc::mem_fun(*this, &BluetoothWidget::onScanButtonClicked));
|
||||
|
||||
this->statusArea.append(*this->toggleButton);
|
||||
this->statusArea.append(*this->powerButton);
|
||||
this->statusArea.append(*this->scanButton);
|
||||
}
|
||||
|
||||
void BluetoothWidget::onPowerButtonClicked() {
|
||||
onPowerStateButtonClickedSignal.emit();
|
||||
}
|
||||
|
||||
void BluetoothWidget::onScanButtonClicked() {
|
||||
onIsDiscoveringButtonClickedSignal.emit();
|
||||
}
|
||||
|
||||
void BluetoothWidget::toggleButton(Gtk::Button *button, bool state) {
|
||||
if (state) {
|
||||
button->add_css_class("toggle-button-on");
|
||||
button->remove_css_class("toggle-button-off");
|
||||
} else {
|
||||
button->add_css_class("toggle-button-off");
|
||||
button->remove_css_class("toggle-button-on");
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothWidget::setPowerState(bool state) {
|
||||
this->isPowered = state;
|
||||
|
||||
if (state) {
|
||||
this->toggleButton->set_label("\ue1a8");
|
||||
this->toggleButton->add_css_class("toggle-button-on");
|
||||
this->toggleButton->remove_css_class("toggle-button-off");
|
||||
this->scanButton->set_sensitive(state);
|
||||
|
||||
if (!state) {
|
||||
this->scanButton->add_css_class("toggle-button-disabled");
|
||||
this->add_css_class("disabled-popover-icon");
|
||||
this->setIsDiscovering(false);
|
||||
} else {
|
||||
this->toggleButton->set_label("\ue1a9");
|
||||
this->toggleButton->add_css_class("toggle-button-off");
|
||||
this->toggleButton->remove_css_class("toggle-button-on");
|
||||
this->scanButton->remove_css_class("toggle-button-disabled");
|
||||
this->remove_css_class("disabled-popover-icon");
|
||||
}
|
||||
|
||||
this->setIsDiscovering(false);
|
||||
this->toggleButton(this->powerButton, state);
|
||||
}
|
||||
|
||||
void BluetoothWidget::setIsDiscovering(bool state) {
|
||||
this->isDiscovering = state;
|
||||
|
||||
if (state) {
|
||||
this->scanButton->add_css_class("toggle-button-on");
|
||||
this->scanButton->remove_css_class("toggle-button-off");
|
||||
} else {
|
||||
this->scanButton->add_css_class("toggle-button-off");
|
||||
this->scanButton->remove_css_class("toggle-button-on");
|
||||
}
|
||||
this->toggleButton(this->scanButton, state);
|
||||
}
|
||||
|
||||
void BluetoothWidget::update() {
|
||||
|
||||
Reference in New Issue
Block a user