Show play button on hover - closes #4

This commit is contained in:
kramo
2023-03-11 22:07:56 +01:00
parent 2e1acc4a2e
commit aa77fc8bf3
3 changed files with 47 additions and 22 deletions

View File

@@ -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");

View File

@@ -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)

View File

@@ -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