mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
Move popover separator into .ui
Allows reusing a custom separator in multiple popovers
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
const { GObject, Gtk } = imports.gi;
|
const { GObject, Gtk } = imports.gi;
|
||||||
|
const Misc = imports.src.misc;
|
||||||
|
|
||||||
/* Negative values from CSS */
|
/* Negative values from CSS */
|
||||||
const PopoverOffset = {
|
const PopoverOffset = {
|
||||||
@@ -220,27 +221,36 @@ class ClapperElapsedPopoverButton extends LabelPopoverButton
|
|||||||
|
|
||||||
addSeparator(text)
|
addSeparator(text)
|
||||||
{
|
{
|
||||||
const box = new Gtk.Box({
|
this.popoverBox.append(new PopoverSeparator({
|
||||||
orientation: Gtk.Orientation.HORIZONTAL,
|
|
||||||
hexpand: true,
|
|
||||||
});
|
|
||||||
const label = new Gtk.Label({
|
|
||||||
label: text,
|
label: text,
|
||||||
halign: Gtk.Align.CENTER,
|
}));
|
||||||
});
|
}
|
||||||
const leftSeparator = new Gtk.Separator({
|
});
|
||||||
orientation: Gtk.Orientation.HORIZONTAL,
|
|
||||||
hexpand: true,
|
var PopoverSeparator = GObject.registerClass({
|
||||||
valign: Gtk.Align.CENTER,
|
GTypeName: 'ClapperPopoverSeparator',
|
||||||
});
|
Template: `file://${Misc.getClapperPath()}/ui/popover-separator.ui`,
|
||||||
const rightSeparator = new Gtk.Separator({
|
InternalChildren: ['middle_label'],
|
||||||
orientation: Gtk.Orientation.HORIZONTAL,
|
Properties: {
|
||||||
hexpand: true,
|
'label': GObject.ParamSpec.string(
|
||||||
valign: Gtk.Align.CENTER,
|
'label',
|
||||||
});
|
'Middle label',
|
||||||
box.append(leftSeparator);
|
'Text to set in the middle',
|
||||||
box.append(label);
|
GObject.ParamFlags.WRITABLE,
|
||||||
box.append(rightSeparator);
|
null
|
||||||
this.popoverBox.append(box);
|
),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
class ClapperPopoverSeparator extends Gtk.Box
|
||||||
|
{
|
||||||
|
_init(opts)
|
||||||
|
{
|
||||||
|
super._init();
|
||||||
|
this.label = opts.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
set label(value)
|
||||||
|
{
|
||||||
|
this._middle_label.label = value || "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
26
ui/popover-separator.ui
Normal file
26
ui/popover-separator.ui
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface>
|
||||||
|
<template class="ClapperPopoverSeparator" parent="GtkBox">
|
||||||
|
<property name="orientation">horizontal</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSeparator">
|
||||||
|
<property name="orientation">horizontal</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="middle_label">
|
||||||
|
<property name="halign">center</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSeparator">
|
||||||
|
<property name="orientation">horizontal</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</template>
|
||||||
|
</interface>
|
Reference in New Issue
Block a user