2023-10-31 08:32:40 -04:00
|
|
|
import { Widget } from 'resource:///com/github/Aylur/ags/widget.js';
|
|
|
|
import Gtk from 'gi://Gtk';
|
2023-10-16 13:55:31 -04:00
|
|
|
const Lang = imports.lang;
|
|
|
|
|
2023-10-22 01:37:07 -04:00
|
|
|
export const RoundedCorner = (place, props) => Widget.Box({
|
2023-10-16 13:55:31 -04:00
|
|
|
halign: place.includes('left') ? 'start' : 'end',
|
2023-10-22 01:37:07 -04:00
|
|
|
valign: place.includes('top') ? 'start' : 'end',
|
|
|
|
style: `padding: 1px; margin:
|
|
|
|
${place.includes('top') ? '-1px' : '0'}
|
|
|
|
${place.includes('right') ? '-1px' : '0'}
|
|
|
|
${place.includes('bottom') ? '-1px' : '0'}
|
|
|
|
${place.includes('left') ? '-1px' : '0'};`,
|
|
|
|
child: Widget({
|
|
|
|
...props,
|
|
|
|
type: Gtk.DrawingArea,
|
|
|
|
setup: widget => {
|
2023-10-17 13:47:02 -04:00
|
|
|
const r = widget.get_style_context()
|
2023-10-20 23:11:21 -04:00
|
|
|
.get_property('border-radius', Gtk.StateFlags.NORMAL);
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-10-16 13:55:31 -04:00
|
|
|
widget.set_size_request(r, r);
|
2023-10-22 01:37:07 -04:00
|
|
|
widget.connect('draw', Lang.bind(widget, (widget, cr) => {
|
|
|
|
const c = widget.get_style_context()
|
|
|
|
.get_property('background-color', Gtk.StateFlags.NORMAL);
|
|
|
|
|
|
|
|
const r = widget.get_style_context()
|
|
|
|
.get_property('border-radius', Gtk.StateFlags.NORMAL);
|
|
|
|
|
|
|
|
const borderColor = widget.get_style_context()
|
|
|
|
.get_property('color', Gtk.StateFlags.NORMAL);
|
|
|
|
|
|
|
|
// ur going to write border-width: something anyway
|
|
|
|
const borderWidth = widget.get_style_context()
|
|
|
|
.get_border(Gtk.StateFlags.NORMAL).left;
|
|
|
|
widget.set_size_request(r, r);
|
2023-10-16 13:55:31 -04:00
|
|
|
|
2023-10-22 01:37:07 -04:00
|
|
|
switch (place) {
|
|
|
|
case 'topleft':
|
|
|
|
cr.arc(r, r, r, Math.PI, 3 * Math.PI / 2);
|
|
|
|
cr.lineTo(0, 0);
|
|
|
|
break;
|
2023-10-16 13:55:31 -04:00
|
|
|
|
2023-10-22 01:37:07 -04:00
|
|
|
case 'topright':
|
|
|
|
cr.arc(0, r, r, 3 * Math.PI / 2, 2 * Math.PI);
|
|
|
|
cr.lineTo(r, 0);
|
|
|
|
break;
|
2023-10-16 13:55:31 -04:00
|
|
|
|
2023-10-22 01:37:07 -04:00
|
|
|
case 'bottomleft':
|
|
|
|
cr.arc(r, 0, r, Math.PI / 2, Math.PI);
|
|
|
|
cr.lineTo(0, r);
|
|
|
|
break;
|
2023-10-16 13:55:31 -04:00
|
|
|
|
2023-10-22 01:37:07 -04:00
|
|
|
case 'bottomright':
|
|
|
|
cr.arc(0, 0, r, 0, Math.PI / 2);
|
|
|
|
cr.lineTo(r, r);
|
|
|
|
break;
|
|
|
|
}
|
2023-10-16 13:55:31 -04:00
|
|
|
|
2023-10-22 01:37:07 -04:00
|
|
|
cr.closePath();
|
|
|
|
cr.setSourceRGBA(c.red, c.green, c.blue, c.alpha);
|
|
|
|
cr.fill();
|
|
|
|
cr.setLineWidth(borderWidth);
|
|
|
|
cr.setSourceRGBA(borderColor.red,
|
|
|
|
borderColor.green,
|
|
|
|
borderColor.blue,
|
|
|
|
borderColor.alpha);
|
|
|
|
cr.stroke();
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
}),
|
2023-10-16 13:55:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export const Topleft = () => Widget.Window({
|
|
|
|
name: 'cornertl',
|
|
|
|
layer: 'overlay',
|
|
|
|
anchor: ['top', 'left'],
|
|
|
|
exclusive: false,
|
|
|
|
visible: true,
|
2023-10-20 23:11:21 -04:00
|
|
|
child: RoundedCorner('topleft', { className: 'corner' }),
|
2023-10-16 13:55:31 -04:00
|
|
|
});
|
|
|
|
export const Topright = () => Widget.Window({
|
|
|
|
name: 'cornertr',
|
|
|
|
layer: 'overlay',
|
|
|
|
anchor: ['top', 'right'],
|
|
|
|
exclusive: false,
|
|
|
|
visible: true,
|
2023-10-20 23:11:21 -04:00
|
|
|
child: RoundedCorner('topright', { className: 'corner' }),
|
2023-10-16 13:55:31 -04:00
|
|
|
});
|
|
|
|
export const Bottomleft = () => Widget.Window({
|
|
|
|
name: 'cornerbl',
|
|
|
|
layer: 'overlay',
|
|
|
|
anchor: ['bottom', 'left'],
|
|
|
|
exclusive: false,
|
|
|
|
visible: true,
|
2023-10-20 23:11:21 -04:00
|
|
|
child: RoundedCorner('bottomleft', { className: 'corner' }),
|
2023-10-16 13:55:31 -04:00
|
|
|
});
|
|
|
|
export const Bottomright = () => Widget.Window({
|
|
|
|
name: 'cornerbr',
|
|
|
|
layer: 'overlay',
|
|
|
|
anchor: ['bottom', 'right'],
|
|
|
|
exclusive: false,
|
|
|
|
visible: true,
|
2023-10-20 23:11:21 -04:00
|
|
|
child: RoundedCorner('bottomright', { className: 'corner' }),
|
2023-10-16 13:55:31 -04:00
|
|
|
});
|