Skip to content

Commit

Permalink
feat(ScaleRevealer): multiple widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr committed Oct 29, 2023
1 parent cbf10b3 commit ea70d6e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Dialogs/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
) {
if (as_is && preview == null) return;

media_viewer.add_media (url, media_type, preview, pos, as_is, alt_text, user_friendly_url, stream);
media_viewer.add_media (url, media_type, preview, pos, as_is, alt_text, user_friendly_url, stream, source_widget);

if (!is_media_viewer_visible) {
media_viewer.reveal (source_widget);
Expand Down
17 changes: 16 additions & 1 deletion src/Views/MediaViewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,15 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
enabled = true,
allow_mouse_drag = true
};
swipe_tracker.prepare.connect (on_swipe_tracker_prepare);
swipe_tracker.update_swipe.connect (on_update_swipe);
swipe_tracker.end_swipe.connect (on_end_swipe);
}

private void on_swipe_tracker_prepare (Adw.NavigationDirection direction) {
update_revealer_widget ();
}

private void on_update_swipe (double progress) {
this.swipe_children_opacity = 0.0;
this.swipe_progress = progress;
Expand Down Expand Up @@ -673,6 +678,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
}

private void reset_media_viewer () {
revealer_widgets.clear ();
this.fullscreen = false;
todo_items.clear ();

Expand All @@ -686,6 +692,11 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
revealed = false;
}

private void update_revealer_widget () {
if (revealed && revealer_widgets.has_key ((int) carousel.position))
scale_revealer.source_widget = revealer_widgets.get ((int) carousel.position);
}

private async string download_video (string url) throws Error {
return yield Host.download (url);
}
Expand All @@ -702,6 +713,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
do_todo_items ();
}

public Gee.HashMap<int, Gtk.Widget> revealer_widgets = new Gee.HashMap<int, Gtk.Widget> ();
public void add_media (
string url,
Tuba.Attachment.MediaType media_type,
Expand All @@ -710,11 +722,14 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
bool as_is = false,
string? alt_text = null,
string? user_friendly_url = null,
bool stream = false
bool stream = false,
Gtk.Widget? revealer_widget = null
) {
Item item;
string final_friendly_url = user_friendly_url == null ? url : user_friendly_url;
Gdk.Paintable? final_preview = as_is ? null : preview;
if (revealer_widget != null)
revealer_widgets.set (pos == null ? items.size : pos, revealer_widget);

if (media_type.is_video ()) {
var video = new Gtk.Video ();
Expand Down
32 changes: 23 additions & 9 deletions src/Widgets/ScaleRevealer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ public class Tuba.Widgets.ScaleRevealer : Adw.Bin {

public signal void transition_done ();
public Adw.TimedAnimation animation { get; construct set; }
public Gtk.Widget? source_widget { get; set; }
private Gtk.Widget? _source_widget = null;
public Gtk.Widget? source_widget {
get {
return _source_widget;
}
set {
if (_source_widget != null)
_source_widget.opacity = 1.0;
_source_widget = value;
update_source_widget ();
}
}
public Gdk.Texture? source_widget_texture { get; set; }

private void update_source_widget () {
if (this.source_widget == null) {
source_widget_texture = null;
} else {
source_widget_texture = render_widget_to_texture (this.source_widget);
this.source_widget.opacity = 0.0;
}
}

private bool _reveal_child = false;
public bool reveal_child {
get {
Expand All @@ -22,13 +42,7 @@ public class Tuba.Widgets.ScaleRevealer : Adw.Bin {
if (value) {
animation.value_to = 1.0;
this.visible = true;

if (source_widget == null) {
source_widget_texture = null;
} else {
source_widget_texture = render_widget_to_texture (this.source_widget);
source_widget.opacity = 0.0;
}
update_source_widget ();
} else {
animation.value_to = 0.0;
}
Expand Down Expand Up @@ -119,7 +133,7 @@ public class Tuba.Widgets.ScaleRevealer : Adw.Bin {

if (source_widget == null) return;
if (source_widget_texture == null) {
warning ("The source widget texture is None, using child snapshot as fallback");
// The source widget texture is None, using child snapshot as fallback
this.snapshot_child (this.child, snapshot);
} else {
if (progress > 0.0) {
Expand Down

0 comments on commit ea70d6e

Please sign in to comment.