♻️ ags(control-center/notifhistory): more structured function

This commit is contained in:
retrozinndev
2025-04-10 16:44:53 -03:00
parent e0cc539541
commit 739df31113
+58 -54
View File
@@ -4,58 +4,62 @@ import { HistoryNotification, Notifications } from "../../scripts/notifications"
import { NotificationWidget } from "../Notification";
export const NotifHistory = () => new Widget.Box({
orientation: Gtk.Orientation.VERTICAL,
className: "history",
visible: bind(Notifications.getDefault(), "history").as(history => history.length > 0),
children: [
new Widget.Scrollable({
className: "history",
hscroll: Gtk.PolicyType.NEVER,
vscroll: Gtk.PolicyType.AUTOMATIC,
visible: bind(Notifications.getDefault(), "history").as(history => history.length > 0),
propagateNaturalHeight: true,
propagateNaturalWidth: false,
onDraw: (scrollable) => {
scrollable.minContentHeight =
((scrollable.get_child()! as Gtk.Viewport).get_child() as Widget.Box).get_children()?.[0].get_allocation().height || 0;
},
child: new Widget.Box({
className: "notifications",
export const NotifHistory = () => {
return new Widget.Box({
orientation: Gtk.Orientation.VERTICAL,
className: bind(Notifications.getDefault(), "history").as(history => history.length > 0 ? "history" : "history hide"),
children: [
new Widget.Scrollable({
className: "history",
hscroll: Gtk.PolicyType.NEVER,
vscroll: Gtk.PolicyType.AUTOMATIC,
propagateNaturalHeight: true,
propagateNaturalWidth: false,
onDraw: (scrollable) => {
if(!(scrollable.get_child()! as Gtk.Viewport).get_child()) return;
scrollable.minContentHeight =
((scrollable.get_child()! as Gtk.Viewport).get_child() as Widget.Box
).get_children()?.[0].get_allocation().height
|| 0;
},
child: new Widget.Box({
className: "notifications",
hexpand: true,
orientation: Gtk.Orientation.VERTICAL,
homogeneous: false,
spacing: 4,
valign: Gtk.Align.START,
children: bind(Notifications.getDefault(), "history").as((history: Array<HistoryNotification>) =>
history.map((notification: HistoryNotification) => NotificationWidget(notification,
() => Notifications.getDefault().removeHistory(notification.id), true)
))
} as Widget.BoxProps)
} as Widget.ScrollableProps),
new Widget.Box({
vexpand: false,
hexpand: true,
orientation: Gtk.Orientation.VERTICAL,
homogeneous: false,
spacing: 4,
valign: Gtk.Align.START,
children: bind(Notifications.getDefault(), "history").as((history: Array<HistoryNotification>) =>
history.map((notification: HistoryNotification) => NotificationWidget(notification,
() => Notifications.getDefault().removeHistory(notification.id), true)
))
} as Widget.BoxProps)
} as Widget.ScrollableProps),
new Widget.Box({
vexpand: false,
hexpand: true,
halign: Gtk.Align.END,
className: "button-row",
children: [
new Widget.Button({
className: "clear-all",
child: new Widget.Box({
children: [
new Widget.Label({
className: "nf",
css: "margin-right: 6px",
label: "󰎟"
} as Widget.LabelProps),
new Widget.Label({
label: "Clear"
} as Widget.LabelProps)
]
} as Widget.BoxProps),
onClick: () => Notifications.getDefault().clearHistory(),
} as Widget.ButtonProps)
]
})
]
} as Widget.BoxProps);
halign: Gtk.Align.END,
className: "button-row",
children: [
new Widget.Button({
className: "clear-all",
child: new Widget.Box({
children: [
new Widget.Label({
className: "nf",
css: "margin-right: 6px",
label: "󰎟"
} as Widget.LabelProps),
new Widget.Label({
label: "Clear"
} as Widget.LabelProps)
]
} as Widget.BoxProps),
onClick: () => Notifications.getDefault().clearHistory(),
} as Widget.ButtonProps)
]
})
]
} as Widget.BoxProps);
}