This commit is contained in:
end-4
2023-12-29 22:00:16 +07:00
parent eb3191d409
commit 97dd57c80c
13 changed files with 644 additions and 440 deletions
+12 -6
View File
@@ -1,23 +1,25 @@
const { Gdk, Gtk } = imports.gi;
import { App, Service, Utils, Variable, Widget } from '../imports.js';
import { App, SCREEN_WIDTH, SCREEN_HEIGHT, Service, Utils, Variable, Widget } from '../imports.js';
const { Box, Button, Entry, EventBox, Icon, Label, Revealer, Scrollable, Stack } = Widget;
export const MarginRevealer = ({
transition = 'slide_down',
child,
revealChild,
showClass = 'element-show', // These are for animation curve
showClass = 'element-show', // These are for animation curve, they don't really hide
hideClass = 'element-hide', // Don't put margins in these classes!
extraProperties = [],
...rest
}) => {
child.toggleClassName(`${revealChild ? showClass : hideClass}`, true);
const widget = Scrollable({
...rest,
css: `min-height: 0px;`,
properties: [
['revealChild', true], // It'll be set to false after init if it's supposed to hide
['transition', transition],
['show', (self) => {
if (self._revealChild) return;
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER);
child.toggleClassName(hideClass, false);
child.toggleClassName(showClass, true);
self._revealChild = true;
@@ -38,17 +40,21 @@ export const MarginRevealer = ({
child.css = `margin-top: -${child.get_allocated_height()}px;`;
}],
['toggle', (self) => {
console.log('toggle');
if (self._revealChild) self._hide(self);
else self._show(self);
}],
...extraProperties,
],
child: child,
setup: (self) => {
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER);
if (!revealChild)
self.set_policy(Gtk.PolicyType.ALWAYS, Gtk.PolicyType.ALWAYS);
else
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER);
self.child = child;
},
...rest,
});
child.toggleClassName(`${revealChild ? showClass : hideClass}`, true);
return widget;
}
+35 -10
View File
@@ -144,15 +144,37 @@ export default ({
transition: 'slide_up',
transitionDuration: 120,
revealChild: false,
child: Label({
xalign: 0,
className: `txt-smallie notif-body-${notifObject.urgency}`,
useMarkup: true,
xalign: 0,
justify: Gtk.Justification.LEFT,
maxWidthChars: 24,
wrap: true,
label: notifObject.body,
child: Box({
vertical: true,
className: 'spacing-v-10',
children: [
Label({
xalign: 0,
className: `txt-smallie notif-body-${notifObject.urgency}`,
useMarkup: true,
xalign: 0,
justify: Gtk.Justification.LEFT,
maxWidthChars: 24,
wrap: true,
label: notifObject.body,
}),
Box({
homogeneous: true,
className: 'notif-actions',
children: [
Button({
className: `notif-action notif-action-${notifObject.urgency}`,
label: 'Close',
onClicked: () => destroyWithAnims(),
}),
...notifObject.actions.map(action => Widget.Button({
className: `notif-action notif-action-${notifObject.urgency}`,
onClicked: () => notifObject.invoke(action.id),
label: action.label,
}))
],
})
]
}),
});
const notifIcon = Box({
@@ -217,11 +239,13 @@ export default ({
notifTextPreview.revealChild = false;
notifTextExpanded.revealChild = true;
self.child.label = 'expand_less';
expanded = true;
}
else {
notifTextPreview.revealChild = true;
notifTextExpanded.revealChild = false;
self.child.label = 'expand_more';
expanded = true;
}
},
child: MaterialIcon('expand_more', 'norm', {
@@ -240,7 +264,6 @@ export default ({
})
// Gesture stuff
const gesture = Gtk.GestureDrag.new(widget);
var initDirX = 0;
var initDirVertical = -1; // -1: unset, 0: horizontal, 1: vertical
@@ -320,11 +343,13 @@ export default ({
notifTextPreview.revealChild = false;
notifTextExpanded.revealChild = true;
expanded = true;
notifExpandButton.child.label = 'expand_less';
}
else if (initDirVertical == 1 && offset_y < -MOVE_THRESHOLD && expanded) {
notifTextPreview.revealChild = true;
notifTextExpanded.revealChild = false;
expanded = false;
notifExpandButton.child.label = 'expand_more';
}
}, 'drag-update')