mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 16:02:00 +02:00
Extend Gtk.ToggleButton for Popover buttons
Instead of trying to force active state for a normal button that is not designed to be toggle-able, use GTK toggle buttons.
This commit is contained in:
@@ -46,10 +46,6 @@ class ClapperCustomButton extends Gtk.Button
|
|||||||
|
|
||||||
const clapperWidget = this.get_ancestor(Gtk.Grid);
|
const clapperWidget = this.get_ancestor(Gtk.Grid);
|
||||||
clapperWidget.revealControls();
|
clapperWidget.revealControls();
|
||||||
|
|
||||||
/* Button opens a popover */
|
|
||||||
if(this.popoverBox)
|
|
||||||
clapperWidget.isPopoverOpen = true;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -78,11 +74,20 @@ class ClapperIconToggleButton extends CustomButton
|
|||||||
});
|
});
|
||||||
|
|
||||||
var PopoverButtonBase = GObject.registerClass(
|
var PopoverButtonBase = GObject.registerClass(
|
||||||
class ClapperPopoverButtonBase extends CustomButton
|
class ClapperPopoverButtonBase extends Gtk.ToggleButton
|
||||||
{
|
{
|
||||||
_init()
|
_init()
|
||||||
{
|
{
|
||||||
super._init();
|
super._init({
|
||||||
|
margin_top: 4,
|
||||||
|
margin_bottom: 4,
|
||||||
|
margin_start: 2,
|
||||||
|
margin_end: 2,
|
||||||
|
can_focus: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.isFullscreen = false;
|
||||||
|
this.add_css_class('flat');
|
||||||
|
|
||||||
this.popover = new Gtk.Popover({
|
this.popover = new Gtk.Popover({
|
||||||
position: Gtk.PositionType.TOP,
|
position: Gtk.PositionType.TOP,
|
||||||
@@ -106,7 +111,16 @@ class ClapperPopoverButtonBase extends CustomButton
|
|||||||
if(this.isFullscreen === isFullscreen)
|
if(this.isFullscreen === isFullscreen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
super.setFullscreenMode(isFullscreen);
|
this.margin_top = (isFullscreen) ? 5 : 4;
|
||||||
|
this.margin_start = (isFullscreen) ? 3 : 2;
|
||||||
|
this.margin_end = (isFullscreen) ? 3 : 2;
|
||||||
|
this.can_focus = isFullscreen;
|
||||||
|
|
||||||
|
/* Redraw icon after style class change */
|
||||||
|
if(this.icon_name)
|
||||||
|
this.set_icon_name(this.icon_name);
|
||||||
|
|
||||||
|
this.isFullscreen = isFullscreen;
|
||||||
|
|
||||||
this.popover.set_offset(0, -this.margin_top);
|
this.popover.set_offset(0, -this.margin_top);
|
||||||
|
|
||||||
@@ -118,11 +132,18 @@ class ClapperPopoverButtonBase extends CustomButton
|
|||||||
this.popover[action + '_css_class'](cssClass);
|
this.popover[action + '_css_class'](cssClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
vfunc_clicked()
|
vfunc_toggled()
|
||||||
{
|
{
|
||||||
super.vfunc_clicked();
|
if(!this.active)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const clapperWidget = this.get_ancestor(Gtk.Grid);
|
||||||
|
|
||||||
|
if(this.isFullscreen)
|
||||||
|
clapperWidget.revealControls();
|
||||||
|
|
||||||
|
clapperWidget.isPopoverOpen = true;
|
||||||
|
|
||||||
this.set_state_flags(Gtk.StateFlags.CHECKED, false);
|
|
||||||
this.popover.popup();
|
this.popover.popup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,8 +158,7 @@ class ClapperPopoverButtonBase extends CustomButton
|
|||||||
clapperWidget.revealControls();
|
clapperWidget.revealControls();
|
||||||
|
|
||||||
clapperWidget.isPopoverOpen = false;
|
clapperWidget.isPopoverOpen = false;
|
||||||
|
this.active = false;
|
||||||
this.unset_state_flags(Gtk.StateFlags.CHECKED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCloseRequest()
|
_onCloseRequest()
|
||||||
|
Reference in New Issue
Block a user