-
-
Notifications
You must be signed in to change notification settings - Fork 73
feat(Widgets): FadeBin #1354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(Widgets): FadeBin #1354
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7a9dcc9
feat(Widgets): FadeBin
GeopJr c976e8d
fix: apply review comments
GeopJr a9850a1
fix: apply measure from review
GeopJr 7e12ddb
feat: collapse-long-posts setting
GeopJr 2d0f191
feat(status): exapnd posts on thread view
GeopJr d1bebee
feat(status): string + osd for expand button
GeopJr 4956cfe
feat(fadebin): skip intermediate snapshot
GeopJr abb13b7
fix: null check
GeopJr 4e855c0
feat(fadebin): animation
GeopJr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| public class Tuba.Widgets.FadeBin : Gtk.Widget { | ||
| const int MAX_HEIGHT = 300; | ||
| const float FADE_HEIGHT = 125f; | ||
|
|
||
| private Gtk.Widget? _child = null; | ||
| public Gtk.Widget? child { | ||
| get { return _child; } | ||
| set { | ||
| if (_child != null) _child.unparent (); | ||
| _child = value; | ||
| _child.set_parent (this); | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| ~FadeBin () { | ||
| if (this.child != null) this.child.unparent (); | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public override Gtk.SizeRequestMode get_request_mode () { | ||
| if (this.child != null) return this.child.get_request_mode (); | ||
| return Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH; | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private bool _reveal = false; | ||
| public bool reveal { | ||
| get { return _reveal; } | ||
| set { | ||
| if (_reveal != value) { | ||
| _reveal = value; | ||
| this.queue_draw (); | ||
| this.queue_resize (); | ||
GeopJr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| private bool _should_fade = false; | ||
| private bool should_fade { | ||
| get { return _should_fade; } | ||
| set { | ||
| if (_should_fade != value) { | ||
| _should_fade = value; | ||
| this.notify_property ("faded"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public bool faded { | ||
| get { | ||
| return this.should_fade && !reveal; | ||
| } | ||
| } | ||
|
|
||
| const Gsk.ColorStop[] GRADIENT = { | ||
| { 0f, { 0, 0, 0, 1f } }, | ||
| { 1f, { 0, 0, 0, 0f } }, | ||
| }; | ||
|
|
||
| public override void size_allocate (int width, int height, int baseline) { | ||
| if (this.child == null) { | ||
| base.size_allocate (width, height, baseline); | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.should_fade = false; | ||
| return; | ||
| } | ||
|
|
||
| this.child.allocate (width, height, baseline, null); | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (this.reveal) { | ||
| this.should_fade = false; | ||
| return; | ||
| } | ||
|
|
||
| this.should_fade = this.child.get_height () >= MAX_HEIGHT; | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public override void measure (Gtk.Orientation orientation, int for_size, out int minimum, out int natural, out int minimum_baseline, out int natural_baseline) { | ||
| this.child.measure ( | ||
GeopJr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| orientation, | ||
| for_size, | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| out minimum, | ||
| out natural, | ||
| out minimum_baseline, | ||
| out natural_baseline | ||
| ); | ||
| if (this.reveal) return; | ||
|
|
||
| minimum = int.min (minimum, MAX_HEIGHT); | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| minimum_baseline = -1; | ||
| natural_baseline = -1; | ||
| if (orientation == Gtk.Orientation.VERTICAL) { | ||
| natural = MAX_HEIGHT; | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| public override void snapshot (Gtk.Snapshot snapshot) { | ||
| if (this.child == null || !this.faded) { | ||
| this.child.snapshot (snapshot); | ||
GeopJr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
|
|
||
| var height = this.get_height (); | ||
| if (height <= 0) { | ||
| this.child.snapshot (snapshot); | ||
| return; | ||
| } | ||
|
|
||
| Gtk.Snapshot child_snapshot = new Gtk.Snapshot (); | ||
| this.snapshot_child (this.child, child_snapshot); | ||
| var node = child_snapshot.to_node (); | ||
| if (node == null) { | ||
| this.child.snapshot (snapshot); | ||
| return; | ||
| } | ||
GeopJr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| var bounds = node.get_bounds (); | ||
| bounds.origin.y = 0; | ||
| bounds.origin.x = Math.floorf (bounds.origin.x); | ||
| bounds.size.width = Math.ceilf (bounds.size.width) + 1; | ||
| bounds.size.height = height; | ||
|
|
||
| snapshot.push_mask (Gsk.MaskMode.INVERTED_ALPHA); | ||
|
|
||
| var new_fade = height - FADE_HEIGHT; | ||
| snapshot.append_linear_gradient ( | ||
| Graphene.Rect () { | ||
| origin = Graphene.Point () { | ||
| x = bounds.origin.x, | ||
| y = new_fade | ||
| }, | ||
| size = Graphene.Size () { | ||
| width = bounds.size.width, | ||
| height = FADE_HEIGHT | ||
| } | ||
| }, | ||
| Graphene.Point () { | ||
| x = 0, | ||
| y = height | ||
| }, | ||
| Graphene.Point () { | ||
| x = 0, | ||
| y = new_fade | ||
| }, | ||
| GRADIENT | ||
| ); | ||
|
|
||
| snapshot.pop (); | ||
| snapshot.push_clip (bounds); | ||
| snapshot.append_node (node); | ||
| snapshot.pop (); | ||
| snapshot.pop (); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.