refactor(ags cursorbox): make hovering more consistent and fix clear button
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2023-12-27 23:13:49 -05:00
parent ecc3d84f8b
commit 0e60d1d098
6 changed files with 82 additions and 71 deletions

View file

@ -86,7 +86,7 @@ export default () => {
/** @type Array<Revealer> */ /** @type Array<Revealer> */
// @ts-expect-error // @ts-expect-error
const indicators = self?.get_parent()?.child.child.child.children; const indicators = self?.get_parent()?.child.child.children;
const currentIndex = indicators const currentIndex = indicators
.findIndex((w) => w.attribute.id === currentId); .findIndex((w) => w.attribute.id === currentId);

View file

@ -2,7 +2,8 @@ import Variable from 'resource:///com/github/Aylur/ags/variable.js';
import { EventBox } from 'resource:///com/github/Aylur/ags/widget.js'; import { EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
const { Gtk } = imports.gi; const { Gtk, Gdk } = imports.gi;
const display = Gdk.Display.get_default();
/** /**
* @typedef {import('types/widgets/eventbox').EventBoxProps} EventBoxProps * @typedef {import('types/widgets/eventbox').EventBoxProps} EventBoxProps
@ -12,11 +13,15 @@ const { Gtk } = imports.gi;
/** @param {EventBoxProps & { /** @param {EventBoxProps & {
* on_primary_click_release?: function(EventBox):void * on_primary_click_release?: function(EventBox):void
* on_hover?: function(EventBox):void
* on_hover_lost?: function(EventBox):void
* }} o * }} o
*/ */
export default ({ export default ({
attribute,
on_primary_click_release = () => {/**/}, on_primary_click_release = () => {/**/},
on_hover = () => {/**/},
on_hover_lost = () => {/**/},
attribute,
...props ...props
}) => { }) => {
// Make this variable to know if the function should // Make this variable to know if the function should
@ -24,52 +29,53 @@ export default ({
const CanRun = Variable(true); const CanRun = Variable(true);
const Disabled = Variable(false); const Disabled = Variable(false);
let widget = EventBox(); const cursorBox = EventBox({
...props,
const wrapper = EventBox({
cursor: 'pointer',
attribute: { attribute: {
...attribute, ...attribute,
disabled: Disabled, disabled: Disabled,
get_child: () => widget.child,
/** @param {import('types/widgets/box').default} new_child */
set_child: (new_child) => {
widget.child = new_child;
},
}, },
}).hook(Disabled, (self) => { on_primary_click_release: (self) => {
self.cursor = Disabled.value ?
'not-allowed' :
'pointer';
});
widget = EventBox({
...props,
sensitive: Disabled.bind().transform((v) => !v),
on_primary_click_release: () => {
// Every click, do a one shot connect to // Every click, do a one shot connect to
// CanRun to wait for location of click // CanRun to wait for location of click
const id = CanRun.connect('changed', () => { const id = CanRun.connect('changed', () => {
if (CanRun.value) { if (CanRun.value && !Disabled.value) {
on_primary_click_release(wrapper); on_primary_click_release(self);
} }
CanRun.disconnect(id); CanRun.disconnect(id);
}); });
}, },
// OnHover
}).on('enter-notify-event', (self) => {
on_hover(self);
self.window.set_cursor(Gdk.Cursor.new_from_name(
display,
Disabled.value ?
'not-allowed' :
'pointer',
));
self.toggleClassName('hover', true);
// OnHoverLost
}).on('leave-notify-event', (self) => {
on_hover_lost(self);
self.window.set_cursor(null);
self.toggleClassName('hover', false);
// Disabled class
}).hook(Disabled, (self) => {
self.toggleClassName('disabled', Disabled.value);
}); });
wrapper.child = widget; const gesture = Gtk.GestureLongPress.new(cursorBox);
const gesture = Gtk.GestureLongPress.new(widget); cursorBox.hook(gesture, () => {
widget.hook(gesture, () => {
const pointer = gesture.get_point(null); const pointer = gesture.get_point(null);
const x = pointer[1]; const x = pointer[1];
const y = pointer[2]; const y = pointer[2];
@ -79,10 +85,10 @@ export default ({
} }
CanRun.value = !( CanRun.value = !(
x > widget.get_allocated_width() || x > cursorBox.get_allocated_width() ||
y > widget.get_allocated_height() y > cursorBox.get_allocated_height()
); );
}, 'end'); }, 'end');
return wrapper; return cursorBox;
}; };

View file

@ -1,7 +1,7 @@
import App from 'resource:///com/github/Aylur/ags/app.js'; import App from 'resource:///com/github/Aylur/ags/app.js';
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js'; import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
import { Button, Label, Box, Icon, Scrollable, Revealer } from 'resource:///com/github/Aylur/ags/widget.js'; import { Label, Box, Icon, Scrollable, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js'; import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import { Notification, HasNotifs } from './base.js'; import { Notification, HasNotifs } from './base.js';
@ -69,33 +69,35 @@ const NotificationList = () => Box({
}, },
}); });
// TODO: use cursorbox feature for this
// Needs to be wrapped to still have onHover when disabled
const ClearButton = () => CursorBox({ const ClearButton = () => CursorBox({
child: Button({ class_name: 'clear',
sensitive: HasNotifs.bind(),
on_primary_click_release: () => { on_primary_click_release: () => {
Notifications.clear(); Notifications.clear();
timeout(1000, () => App.closeWindow('notification-center')); timeout(1000, () => App.closeWindow('notification-center'));
}, },
child: Box({ setup: (self) => {
self.hook(HasNotifs, () => {
self.attribute.disabled?.setValue(!HasNotifs.value);
});
},
children: [ child: Box({
Label('Clear '),
Icon({ children: [
setup: (self) => { Label('Clear '),
self.hook(Notifications, () => {
self.icon = Notifications.notifications.length > 0 ? Icon({
'user-trash-full-symbolic' : setup: (self) => {
'user-trash-symbolic'; self.hook(Notifications, () => {
}); self.icon = Notifications.notifications.length > 0 ?
}, 'user-trash-full-symbolic' :
}), 'user-trash-symbolic';
], });
}), },
}),
],
}), }),
}); });

View file

@ -140,8 +140,9 @@ const GridButton = ({
if (menu) { if (menu) {
const rowMenu = const rowMenu =
self.get_parent() self.get_parent()
?.get_parent()?.get_parent() ?.get_parent()
?.get_parent()?.get_parent() ?.get_parent()
?.get_parent()
// @ts-expect-error // @ts-expect-error
?.children[1]; ?.children[1];

View file

@ -20,22 +20,24 @@
font-size: 22px; font-size: 22px;
} }
button { .clear {
all: unset; box {
transition: 200ms; all: unset;
border-radius: 9px; transition: 200ms;
color: #eee; border-radius: 9px;
background-color: #664C90; color: #eee;
box-shadow: inset 0 0 0 1px rgba(238, 238, 238, 0.03); background-color: #664C90;
padding: 4.5px 9px; box-shadow: inset 0 0 0 1px rgba(238, 238, 238, 0.03);
padding: 4.5px 9px;
}
&:hover { &.hover box {
box-shadow: inset 0 0 0 1px rgba(238, 238, 238, 0.03); box-shadow: inset 0 0 0 1px rgba(238, 238, 238, 0.03);
background-color: rgba(238, 238, 238, 0.154); background-color: rgba(238, 238, 238, 0.154);
color: #f1f1f1; color: #f1f1f1;
} }
&:disabled { &.disabled box {
box-shadow: none; box-shadow: none;
background-color: rgba(#664C90, 0.3); background-color: rgba(#664C90, 0.3);
color: rgba(238, 238, 238, 0.3); color: rgba(238, 238, 238, 0.3);

View file

@ -48,7 +48,7 @@
border 0.5s ease-in-out; border 0.5s ease-in-out;
} }
.toggle-on:hover, .toggle-off:hover { .toggle-on.hover, .toggle-off.hover {
background-color: rgba(127, 132, 156, 0.4); background-color: rgba(127, 132, 156, 0.4);
transition: background-color 0.5s ease-in-out, transition: background-color 0.5s ease-in-out,
border 0.5s ease-in-out; border 0.5s ease-in-out;