gui: only show the toolbox on enter

This is using opacity of 0% to hide them - this way the space stays allocated
and showing it doesn't rearrange things. Using visiblity here causes
everything to shift around on reveal.
pull/145/head
Peter Hutterer 2019-07-19 18:09:13 +10:00
parent 0b9d4c2602
commit 4e886fca2b
2 changed files with 112 additions and 92 deletions

View File

@ -22,7 +22,13 @@
<property name="can_focus">False</property>
<property name="icon_name">object-rotate-right-symbolic</property>
</object>
<template class="Drawing" parent="GtkBox">
<template class="Drawing" parent="GtkEventBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="enter-notify-event" handler="_on_enter" swapped="no"/>
<signal name="leave-notify-event" handler="_on_leave" swapped="no"/>
<child>
<object class="GtkBox" id="box_drawing">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">20</property>
@ -30,6 +36,7 @@
<property name="orientation">vertical</property>
<child>
<object class="GtkBox" id="box_toolbar">
<property name="height_request">20</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
@ -138,5 +145,7 @@
<style>
<class name="drawing"/>
</style>
</object>
</child>
</template>
</interface>

View File

@ -12,7 +12,7 @@
#
from gettext import gettext as _
from gi.repository import GObject, Gtk, GdkPixbuf
from gi.repository import GObject, Gtk, GdkPixbuf, Gdk
from .config import Config
from .svg import JsonSvg
@ -24,7 +24,7 @@ gi.require_version("Gtk", "3.0")
@Gtk.Template(resource_path='/org/freedesktop/Tuhi/ui/Drawing.ui')
class Drawing(Gtk.Box):
class Drawing(Gtk.EventBox):
__gtype_name__ = "Drawing"
box_toolbar = Gtk.Template.Child()
@ -42,6 +42,7 @@ class Drawing(Gtk.Box):
self.refresh() # sets self.svg
self.timestamp = self.svg.timestamp
self.box_toolbar.set_opacity(0)
def _on_orientation_changed(self, config, pspec):
self.orientation = config.orientation
@ -123,3 +124,13 @@ class Drawing(Gtk.Box):
o = orientations[orientations.index(self.orientation) + advance]
self.orientation = o
self.refresh()
@Gtk.Template.Callback('_on_enter')
def _on_enter(self, *args):
self.box_toolbar.set_opacity(100)
@Gtk.Template.Callback('_on_leave')
def _on_leave(self, drawing, event):
if event.detail == Gdk.NotifyType.INFERIOR:
return
self.box_toolbar.set_opacity(0)