Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library: Ported View switcher to rust #594

Merged
merged 11 commits into from
Sep 17, 2023
43 changes: 43 additions & 0 deletions src/Library/demos/View Switcher/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::workbench;
use adw::prelude::*;

use glib::clone;
use gtk::glib;

pub fn main() {
let notifications_page: adw::ViewStackPage = workbench::builder().object("page3").unwrap();
let notification_list: gtk::ListBox = workbench::builder().object("notification_list").unwrap();

let notification_count = 5;
notifications_page.set_badge_number(notification_count);

for _ in 0..notification_count {
let notification_row = adw::ActionRow::builder()
.title("Notification")
.selectable(false)
.build();

let button = gtk::Button::builder()
.halign(gtk::Align::Center)
.valign(gtk::Align::Center)
.margin_top(10)
.margin_bottom(10)
.icon_name("check-plain-symbolic")
.build();

button.connect_clicked(clone!(
@weak notifications_page, @weak notification_list, @weak notification_row => move |_| {
notifications_page.set_badge_number(notifications_page.badge_number() - 1);
notification_list.remove(&notification_row);

if notifications_page.badge_number() == 0 {
notifications_page.set_needs_attention(false);
}
}
));

notification_row.add_suffix(&button);

notification_list.append(&notification_row);
}
}
7 changes: 3 additions & 4 deletions src/Library/demos/View Switcher/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import Gtk from "gi://Gtk";
const notifications_page = workbench.builder.get_object("page3");
const notification_list = workbench.builder.get_object("notification_list");

let notification_count = 5;
const notification_count = 5;
notifications_page.badge_number = notification_count;

for (let i = 0; i < notification_count; i++) {
const notification_row = new Adw.ActionRow({
title: "Notification",
selectable: false,
});

notification_row.title = "Notification";

const button = new Gtk.Button({
halign: "center",
valign: "center",
Expand All @@ -23,7 +22,7 @@ for (let i = 0; i < notification_count; i++) {
});

button.connect("clicked", () => {
notifications_page.badge_number = --notification_count;
notifications_page.badge_number -= 1;
notification_list.remove(notification_row);

if (notifications_page.badge_number === 0) {
Expand Down
16 changes: 8 additions & 8 deletions src/Library/demos/View Switcher/main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
public void main() {
var notifications_page = workbench.builder.get_object("page3") as Adw.ViewStackPage;
var notification_list = workbench.builder.get_object("notification_list") as Gtk.ListBox;

int notification_count = 5;

notifications_page.badge_number = notification_count;

for (int i = 0; i < notification_count; i++){
var notification_row = new Adw.ActionRow(){
title = "Notification",
selectable = false,
};

var button = new Gtk.Button(){
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER,
margin_top = 10,
margin_bottom = 10,
icon_name = "check-plain-symbolic"
};

button.clicked.connect( () => {
notifications_page.badge_number = --notification_count;
notifications_page.badge_number -= 1;
notification_list.remove(notification_row);

if (notifications_page.badge_number == 0)
if (notifications_page.badge_number == 0) {
notifications_page.needs_attention = false;
}
});

notification_row.add_suffix(button);

notification_list.append(notification_row);
Expand Down