Make overlay wrap

This commit is contained in:
Jan Hamal Dvořák 2025-03-08 21:56:41 +01:00
parent 8508b13382
commit 81d9ddf606
2 changed files with 14 additions and 4 deletions

View file

@ -10,7 +10,8 @@ import gi
gi.require_version("Gdk", "4.0")
gi.require_version("Gtk", "4.0")
gi.require_version("Gst", "1.0")
from gi.repository import Gdk, Gst, Gtk # NOQA: E402
gi.require_version("Pango", "1.0")
from gi.repository import Gdk, Gst, Gtk, Pango # NOQA: E402
class MainWindow(Gtk.ApplicationWindow):
@ -34,6 +35,8 @@ class MainWindow(Gtk.ApplicationWindow):
self.overlay_label.set_valign(Gtk.Align.CENTER)
self.overlay_label.set_halign(Gtk.Align.CENTER)
self.overlay_label.set_visible(False)
self.overlay_label.set_wrap(True)
self.overlay_label.set_wrap_mode(Pango.WrapMode.WORD_CHAR)
def update_overlay(widget: Gtk.Widget, frame_clock: Gdk.FrameClock, data: Any) -> bool:
current_time = frame_clock.get_frame_time() / 1_000_000
@ -65,12 +68,17 @@ class MainWindow(Gtk.ApplicationWindow):
self.video_widget.set_vexpand(True)
self.video_widget.set_hexpand(True)
overlay_box = Gtk.Box()
overlay_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
overlay_box.set_name("black-overlay")
overlay_box.set_vexpand(True)
overlay_box.set_hexpand(True)
overlay_box.append(self.video_widget)
overlay_box.append(self.overlay_label)
# Create an overlay container
overlay = Gtk.Overlay()
overlay.set_child(self.video_widget)
overlay.add_overlay(self.overlay_label)
overlay_box.append(overlay)
# Setup GStreamer pipeline
self.pipeline = Gst.Pipeline.new("video-player")

View file

@ -15,4 +15,6 @@ listview > row {
background-color: rgba(64, 64, 64, 0.25);
padding: 20px;
border-radius: 10px;
margin: 48px;
width: 80%;
}