Skip to content

Commit

Permalink
feat(Home): prominent compose button
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr committed Aug 31, 2023
1 parent d30bfc0 commit 15a445a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 24 deletions.
4 changes: 4 additions & 0 deletions data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,7 @@ video > overlay > revealer > controls {
.ttl-view .small .preview_card.explore .preview_card_image {
border-radius: 0px;
}

.compose-button {
padding: 8px;
}
23 changes: 14 additions & 9 deletions data/ui/views/base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@
<object class="AdwToolbarView" id="toolbar_view">

<child type="top">
<object class="AdwHeaderBar" id="header"/>
<object class="AdwHeaderBar" id="header" />
</child>

<property name="content">
<object class="GtkOverlay" id="scrolled_overlay">
<child type="overlay">
<object class="GtkButton" id="scroll_to_top">
<property name="icon-name">go-top-symbolic</property>
<object class="GtkRevealer" id="scroll_to_top_rev">
<property name="transition_type">crossfade</property>
<property name="reveal-child">0</property>
<property name="valign">end</property>
<property name="halign">end</property>
<property name="margin_end">16</property>
<property name="margin_bottom">16</property>
<property name="visible">0</property>
<style>
<class name="circular" />
<class name="osd" />
</style>
<property name="child">
<object class="GtkButton" id="scroll_to_top">
<property name="icon-name">go-top-symbolic</property>
<style>
<class name="circular" />
<class name="osd" />
</style>
</object>
</property>
</object>
</child>

Expand Down Expand Up @@ -172,4 +177,4 @@
</child>

</template>
</interface>
</interface>
1 change: 1 addition & 0 deletions src/Views/Base.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 17 additions & 15 deletions src/Views/ContentBase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
33 changes: 33 additions & 0 deletions src/Views/Home.vala
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down

0 comments on commit 15a445a

Please sign in to comment.