From 15a445aed337b5d3c12cd2f39097269aff17b7b0 Mon Sep 17 00:00:00 2001 From: Evangelos Paterakis Date: Thu, 31 Aug 2023 04:35:55 +0300 Subject: [PATCH] feat(Home): prominent compose button --- data/style.css | 4 ++++ data/ui/views/base.ui | 23 ++++++++++++++--------- src/Views/Base.vala | 1 + src/Views/ContentBase.vala | 32 +++++++++++++++++--------------- src/Views/Home.vala | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 24 deletions(-) diff --git a/data/style.css b/data/style.css index 0b4787817..10dac91dc 100644 --- a/data/style.css +++ b/data/style.css @@ -473,3 +473,7 @@ video > overlay > revealer > controls { .ttl-view .small .preview_card.explore .preview_card_image { border-radius: 0px; } + +.compose-button { + padding: 8px; +} diff --git a/data/ui/views/base.ui b/data/ui/views/base.ui index 882e99d4a..28f2b6d76 100644 --- a/data/ui/views/base.ui +++ b/data/ui/views/base.ui @@ -13,23 +13,28 @@ - + - - go-top-symbolic + + crossfade + 0 end end 16 16 - 0 - + + + go-top-symbolic + + + @@ -172,4 +177,4 @@ - + \ No newline at end of file diff --git a/src/Views/Base.vala b/src/Views/Base.vala index 3658919e7..c6cb69a67 100644 --- a/src/Views/Base.vala +++ b/src/Views/Base.vala @@ -33,6 +33,7 @@ public class Tuba.Views.Base : Adw.BreakpointBin { [GtkChild] protected unowned Gtk.ScrolledWindow scrolled; [GtkChild] protected unowned Gtk.Overlay scrolled_overlay; + [GtkChild] protected unowned Gtk.Revealer scroll_to_top_rev; [GtkChild] protected unowned Gtk.Button scroll_to_top; // [GtkChild] protected unowned Gtk.Box view; // [GtkChild] protected unowned Adw.Clamp clamp; diff --git a/src/Views/ContentBase.vala b/src/Views/ContentBase.vala index af46d9b94..8dd333c88 100644 --- a/src/Views/ContentBase.vala +++ b/src/Views/ContentBase.vala @@ -21,26 +21,28 @@ public class Tuba.Views.ContentBase : Views.Base { content_box.child = content; content.activate.connect (on_content_item_activated); - scrolled.vadjustment.value_changed.connect (() => { - if ( - !bottom_reached_locked - && scrolled.vadjustment.value > scrolled.vadjustment.upper - scrolled.vadjustment.page_size * 2 - ) { - bottom_reached_locked = true; - on_bottom_reached (); - } - - var is_close_to_top = scrolled.vadjustment.value <= 1000; - scroll_to_top.visible = !is_close_to_top - && scrolled.vadjustment.value + scrolled.vadjustment.page_size + 100 < scrolled.vadjustment.upper; - - if (is_close_to_top) reached_close_to_top (); - }); + scrolled.vadjustment.value_changed.connect (on_scrolled_vadjustment_value_change); } ~ContentBase () { debug ("Destroying ContentBase"); } + protected virtual void on_scrolled_vadjustment_value_change () { + if ( + !bottom_reached_locked + && scrolled.vadjustment.value > scrolled.vadjustment.upper - scrolled.vadjustment.page_size * 2 + ) { + bottom_reached_locked = true; + on_bottom_reached (); + } + + var is_close_to_top = scrolled.vadjustment.value <= 1000; + scroll_to_top_rev.reveal_child = !is_close_to_top + && scrolled.vadjustment.value + scrolled.vadjustment.page_size + 100 < scrolled.vadjustment.upper; + + if (is_close_to_top) reached_close_to_top (); + } + private void bind_listitem_cb (GLib.Object item) { ((Gtk.ListItem) item).child = on_create_model_widget (((Gtk.ListItem) item).item); } diff --git a/src/Views/Home.vala b/src/Views/Home.vala index 0406fc715..64f8224d8 100644 --- a/src/Views/Home.vala +++ b/src/Views/Home.vala @@ -1,8 +1,41 @@ public class Tuba.Views.Home : Views.Timeline { + Gtk.Revealer compose_button_rev; construct { url = "/api/v1/timelines/home"; label = _("Home"); icon = "tuba-home-symbolic"; + + scroll_to_top_rev.margin_end = 32; + scroll_to_top_rev.margin_bottom = 80; + + compose_button_rev = new Gtk.Revealer () { + transition_type = Gtk.RevealerTransitionType.SLIDE_UP, + valign = halign = Gtk.Align.END, + margin_end = margin_bottom = 24, + reveal_child = true, + child = new Gtk.Button.from_icon_name ("document-edit-symbolic") { + action_name = "app.compose", + tooltip_text = _("Compose"), + css_classes = { "circular", "compose-button", "suggested-action" } + } + }; + + compose_button_rev.bind_property ("reveal-child", scroll_to_top_rev, "margin-bottom", GLib.BindingFlags.SYNC_CREATE, (b, src, ref target) => { + target.set_int (src.get_boolean () ? 80 : 24); + + return true; + }); + + scrolled_overlay.add_overlay (compose_button_rev); + } + + double last_adjustment = 0.0; + protected override void on_scrolled_vadjustment_value_change () { + base.on_scrolled_vadjustment_value_change (); + + if (scrolled.vadjustment.value > 1000) + compose_button_rev.reveal_child = scrolled.vadjustment.value + scrolled.vadjustment.page_size + 100 < scrolled.vadjustment.upper; + last_adjustment = scrolled.vadjustment.value; } public override string? get_stream_url () {