[gnome-boxes] Make it possible to scroll the media box
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Make it possible to scroll the media box
- Date: Wed, 23 May 2012 16:27:41 +0000 (UTC)
commit e608841af9b33153509026dd3a90c55630f51f83
Author: Alexander Larsson <alexl redhat com>
Date: Wed May 23 18:24:43 2012 +0200
Make it possible to scroll the media box
https://bugzilla.gnome.org/show_bug.cgi?id=672601
data/gtk-style.css | 12 +++++++++++
src/wizard-source.vala | 52 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletions(-)
---
diff --git a/data/gtk-style.css b/data/gtk-style.css
index 40a7ba1..d250298 100644
--- a/data/gtk-style.css
+++ b/data/gtk-style.css
@@ -165,6 +165,14 @@ BoxesMenuBox .menuitem:prelight {
background-color: shade (@boxes_bg2_color, 1.1);
}
+/* Ensure the viewport is transparent so the background don't
+ show through the rounded corners */
+.boxes-menu GtkViewport {
+ background-image: none;
+ background-color: transparent;
+ border-style: none;
+}
+
.boxes-menu-row {
-GtkWidget-focus-line-width: 0;
border-style: ridge none none none;
@@ -182,6 +190,10 @@ BoxesMenuBox .menuitem:prelight {
border-style: none;
}
+.boxes-menu-scrolled .boxes-menu-row:nth-child(first) {
+ border-radius: 0;
+}
+
.boxes-menu > .boxes-menu-row:nth-child(last) {
border-radius: 0 0 15px 15px;
}
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index 28dd0e4..c146316 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -9,6 +9,46 @@ private enum Boxes.SourcePage {
public delegate void ClickedFunc ();
+/* Subclass of ScrolledWindow that shows at allocates enough
+ space to not scroll for at most N children. */
+private class Boxes.WizardScrolled : Gtk.ScrolledWindow {
+ private int num_visible;
+ public WizardScrolled (int num_visible) {
+ this.num_visible = num_visible;
+ this.get_style_context ().add_class ("boxes-menu-scrolled");
+ this.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
+ get_vscrollbar ().show.connect (() => {
+ this.get_style_context ().add_class ("boxes-menu-scrolled");
+ this.reset_style ();
+ });
+ get_vscrollbar ().hide.connect ( () => {
+ this.get_style_context ().remove_class ("boxes-menu-scrolled");
+ this.reset_style ();
+ });
+ }
+
+ public override void get_preferred_height (out int minimum_height, out int natural_height) {
+ base.get_preferred_height (out minimum_height, out natural_height);
+ var viewport = get_child () as Gtk.Viewport;
+ var box = viewport.get_child () as Gtk.Box;
+
+ int height = 0;
+ int i = 0;
+ foreach (var w in box.get_children ()) {
+ if (!w.get_visible ())
+ continue;
+ int child_height;
+ w.get_preferred_height (null, out child_height);
+ height += child_height;
+ i++;
+ if (i == num_visible)
+ break;
+ }
+ minimum_height = int.max (minimum_height, height);
+ natural_height = int.max (natural_height, height);
+ }
+}
+
private class Boxes.WizardSource: GLib.Object {
public Gtk.Widget widget { get { return notebook; } }
private SourcePage _page;
@@ -38,6 +78,7 @@ private class Boxes.WizardSource: GLib.Object {
private Gtk.Box main_vbox;
private Gtk.Box media_vbox;
+ private Gtk.ScrolledWindow media_scrolled;
private Gtk.Notebook notebook;
private Gtk.Label url_label;
private Gtk.Image url_image;
@@ -62,8 +103,12 @@ private class Boxes.WizardSource: GLib.Object {
main_vbox.grab_focus ();
notebook.append_page (main_vbox, null);
+ media_scrolled = new WizardScrolled (6);
+
media_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
- main_vbox.add (media_vbox);
+ media_scrolled.set_no_show_all (true);
+ media_scrolled.add_with_viewport (media_vbox);
+ main_vbox.add (media_scrolled);
var hbox = add_entry (main_vbox, () => { page = SourcePage.URL; });
var label = new Gtk.Label (_("Enter URL"));
@@ -155,6 +200,10 @@ private class Boxes.WizardSource: GLib.Object {
if (nouveau)
add_media_entry (media);
}
+
+ // In case we removed everything
+ if (media_vbox.get_children ().length () == 0)
+ media_scrolled.hide ();
}
private void add_media_entry (InstallerMedia media) {
@@ -193,6 +242,7 @@ private class Boxes.WizardSource: GLib.Object {
}
media_vbox.show_all ();
+ media_scrolled.show ();
}
private Gtk.Box add_entry (Gtk.Box box,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]