[gnome-boxes] Add Revealer actor
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Add Revealer actor
- Date: Thu, 7 Jun 2012 07:22:45 +0000 (UTC)
commit 83067811aa85c5d97f6fe1f66162a58eb6387682
Author: Alexander Larsson <alexl redhat com>
Date: Fri Jun 1 15:27:25 2012 +0200
Add Revealer actor
This is an actor that lets you slide in/out a child, clipping the child
to the revealer. This is useful for instance to implement sliding in
sidebars or notifications.
https://bugzilla.gnome.org/show_bug.cgi?id=677274
src/Makefile.am | 1 +
src/revealer.vala | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index af60f51..cdeb9b0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,6 +51,7 @@ gnome_boxes_SOURCES = \
i-properties-provider.vala \
properties.vala \
remote-machine.vala \
+ revealer.vala \
selectionbar.vala \
sidebar.vala \
spice-display.vala \
diff --git a/src/revealer.vala b/src/revealer.vala
new file mode 100644
index 0000000..5065acd
--- /dev/null
+++ b/src/revealer.vala
@@ -0,0 +1,88 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Clutter;
+
+public class Boxes.Revealer: Clutter.Actor {
+ private bool horizontal;
+ private bool revealed;
+ public uint duration;
+
+ public Revealer (bool horizontal) {
+ this.horizontal = horizontal;
+ clip_to_allocation = true;
+ revealed = true;
+ duration = 250;
+
+ if (horizontal) {
+ var layout = new Clutter.BinLayout (Clutter.BinAlignment.FILL,
+ Clutter.BinAlignment.FIXED);
+ this.set_layout_manager (layout);
+ } else {
+ var layout = new Clutter.BinLayout (Clutter.BinAlignment.FIXED,
+ Clutter.BinAlignment.FILL);
+ this.set_layout_manager (layout);
+ }
+
+ this.actor_added.connect ( (child) => {
+ if (revealed)
+ child.show ();
+ else
+ child.hide ();
+ });
+ }
+
+ public void reveal () {
+ foreach (var child in get_children ()) {
+ if (!revealed)
+ child.show ();
+ if (horizontal) {
+ if (!revealed) {
+ float height;
+ child.get_preferred_height (-1, null, out height);
+ child.y = -height;
+ }
+ child.animate (Clutter.AnimationMode.EASE_IN_QUAD, duration, "y", 0f);
+ } else {
+ if (!revealed) {
+ float width;
+ child.get_preferred_width (-1, null, out width);
+ child.x = -width;
+ }
+ child.animate (Clutter.AnimationMode.EASE_IN_QUAD, duration, "x", 0f);
+ }
+ }
+ revealed = true;
+ }
+
+ private void unreveal_child (Clutter.Actor child) {
+ if (horizontal) {
+ float height;
+ child.get_preferred_height (-1, null, out height);
+ var anim = child.animate (Clutter.AnimationMode.EASE_OUT_QUAD, duration, "y", -height);
+ anim.completed.connect (() => {
+ child.hide ();
+ revealed = false;
+ });
+ } else {
+ float width;
+ child.get_preferred_width (-1, null, out width);
+ var anim = child.animate (Clutter.AnimationMode.EASE_OUT_QUAD, duration, "x", -width);
+ anim.completed.connect (() => {
+ child.hide ();
+ revealed = false;
+ });
+ }
+ }
+
+ public void unreveal () {
+ if (!revealed)
+ return;
+
+ bool found_child = false;
+ foreach (var child in get_children ()) {
+ found_child = true;
+ unreveal_child (child);
+ }
+ if (!found_child)
+ revealed = false;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]