From aa77fc8bf3d4d6ef4e84f4a5be795be909b5d83f Mon Sep 17 00:00:00 2001 From: kramo <93832451+kra-mo@users.noreply.github.com> Date: Sat, 11 Mar 2023 22:07:56 +0100 Subject: [PATCH] Show play button on hover - closes #4 --- data/gtk/game.blp | 45 +++++++++++++++++++++++++-------------------- src/game.py | 22 +++++++++++++++++++++- src/window.py | 2 +- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/data/gtk/game.blp b/data/gtk/game.blp index 51f189a..a258c80 100644 --- a/data/gtk/game.blp +++ b/data/gtk/game.blp @@ -28,12 +28,31 @@ template game : Box { maximum-size: 200; Box { - Label title { - label: _("Title"); - ellipsize: end; - hexpand: true; - halign: start; - margin-start: 12; + Overlay overlay { + [overlay] + Revealer button_revealer { + reveal-child: false; + transition-type: crossfade; + Button button_play { + halign: start; + label: _("Play"); + margin-start: 6; + margin-end: 6; + margin-top: 6; + margin-bottom: 6; + } + } + Revealer title_revealer { + transition-type: crossfade; + reveal-child: true; + Label title { + label: _("Title"); + ellipsize: end; + hexpand: true; + halign: start; + margin-start: 12; + } + } } MenuButton menu_button { @@ -57,13 +76,6 @@ template game : Box { } menu game_options { - section { - item { - label: _("Play"); - action: "app.launch_game"; - } - } - section { item { label: _("Edit"); @@ -83,13 +95,6 @@ menu game_options { } menu hidden_game_options { - section { - item { - label: _("Play"); - action: "app.launch_game"; - } - } - section { item { label: _("Edit"); diff --git a/src/game.py b/src/game.py index 839cac3..f465607 100644 --- a/src/game.py +++ b/src/game.py @@ -23,18 +23,38 @@ from gi.repository import Gtk class game(Gtk.Box): __gtype_name__ = 'game' + overlay = Gtk.Template.Child() title = Gtk.Template.Child() + button_play = Gtk.Template.Child() cover = Gtk.Template.Child() cover_button = Gtk.Template.Child() menu_button = Gtk.Template.Child() hidden_game_options = Gtk.Template.Child() + button_revealer = Gtk.Template.Child() + title_revealer = Gtk.Template.Child() - def __init__(self, title, pixbuf, game_id, **kwargs): + def __init__(self, parent_widget, title, pixbuf, game_id, **kwargs): super().__init__(**kwargs) + self.parent_widget = parent_widget self.name = title self.pixbuf = pixbuf self.game_id = game_id self.title.set_label(title) self.cover.set_pixbuf(pixbuf) + + self.event_contoller_motion = Gtk.EventControllerMotion.new() + self.overlay.add_controller(self.event_contoller_motion) + + self.button_play.connect("clicked", self.launch_game) + self.event_contoller_motion.connect("enter", self.toggle_show_play) + self.event_contoller_motion.connect("leave", self.toggle_show_play) + + def toggle_show_play(self, widget, *args): + self.button_revealer.set_reveal_child(not self.button_revealer.get_reveal_child()) + self.title_revealer.set_reveal_child(not self.title_revealer.get_reveal_child()) + + def launch_game(self, widget): + self.parent_widget.set_active_game(None, None, self.game_id) + self.parent_widget.get_application().on_launch_game_action(None) diff --git a/src/window.py b/src/window.py index 0c85672..2b22001 100644 --- a/src/window.py +++ b/src/window.py @@ -121,7 +121,7 @@ class CartridgesWindow(Adw.ApplicationWindow): if "removed" in current_game.keys(): continue - entry = game(current_game["name"], get_cover(current_game, self), game_id) + entry = game(self, current_game["name"], get_cover(current_game, self), game_id) if not self.games[game_id]["hidden"]: self.visible_widgets[game_id] = entry