diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2018-03-25 12:39:22 +0200 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2018-03-25 12:41:41 +0200 |
commit | abd8f73708201f858b049385fb28702dd6c8db8e (patch) | |
tree | c3d1a9fa6d28d385bd5cc07bfa6704ee4a51f99e | |
parent | 486da6fb853bb06c7b3434d1dbe5a66fab45f6ca (diff) | |
download | gnome-contacts-abd8f73708201f858b049385fb28702dd6c8db8e.tar.gz |
MaxWidth: rename Center and extract to its own file.
Since we only use it to set the maximum width, Center is no longer a
good name.
Also added a bit more documentation.
-rw-r--r-- | src/contacts-contact-pane.vala | 10 | ||||
-rw-r--r-- | src/contacts-max-width-bin.vala | 66 | ||||
-rw-r--r-- | src/contacts-utils.vala | 46 | ||||
-rw-r--r-- | src/meson.build | 1 |
4 files changed, 72 insertions, 51 deletions
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala index 54e0b4a..1a21557 100644 --- a/src/contacts-contact-pane.vala +++ b/src/contacts-contact-pane.vala @@ -198,12 +198,12 @@ public class Contacts.ContactPane : Stack { this.sheet.margin = 36; this.sheet.set_margin_bottom (24); - var hcenter = new Center (); - hcenter.max_width = 600; - hcenter.show (); - hcenter.add (this.sheet); + var contact_sheet_container = new MaxWidthBin (); + contact_sheet_container.max_width = 600; + contact_sheet_container.show (); + contact_sheet_container.add (this.sheet); - this.contact_sheet_page.add (hcenter); + this.contact_sheet_page.add (contact_sheet_container); this.sheet.set_focus_vadjustment (this.contact_sheet_page.get_vadjustment ()); this.contact_sheet_page.get_child ().get_style_context ().add_class ("contacts-main-view"); diff --git a/src/contacts-max-width-bin.vala b/src/contacts-max-width-bin.vala new file mode 100644 index 0000000..e22e59a --- /dev/null +++ b/src/contacts-max-width-bin.vala @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2011 Alexander Larsson <alexl@redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * The MaxWidthBin is a very basic helper class to restrict a given widget's + * width to a given maximum. Set the widget as the child of this Bin to + * restrict its width. + */ +public class Contacts.MaxWidthBin : Gtk.Bin { + + public int max_width { get; set; } + + public override void get_preferred_height (out int minimum_height, out int natural_height) { + var child = get_child (); + if (child != null) { + int min, nat; + child.get_preferred_height (out min, out nat); + minimum_height = min; + natural_height = nat; + } else { + minimum_height = -1; + natural_height = -1; + } + } + + public override void get_preferred_width (out int minimum_width, out int natural_width) { + var child = get_child (); + if (child != null) { + int min, nat; + child.get_preferred_width (out min, out nat); + minimum_width = min; + natural_width = nat; + } else { + minimum_width = -1; + natural_width = -1; + } + } + + public override void size_allocate (Gtk.Allocation allocation) { + Gtk.Allocation new_alloc; + + set_allocation (allocation); + new_alloc = allocation; + if (allocation.width > this.max_width) { + new_alloc.width = this.max_width; + new_alloc.x = allocation.x; + } + + var child = get_child (); + child.size_allocate (new_alloc); + } +} diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala index a8042a1..9671ccc 100644 --- a/src/contacts-utils.vala +++ b/src/contacts-utils.vala @@ -69,52 +69,6 @@ namespace Contacts { } } -public class Center : Bin { - public int max_width { get; set; } - - public override void get_preferred_height (out int minimum_height, out int natural_height) { - var child = get_child (); - if (child != null) { - int min; - int nat; - child.get_preferred_height (out min, out nat); - minimum_height = min; - natural_height = nat; - } else { - minimum_height = -1; - natural_height = -1; - } - } - - public override void get_preferred_width (out int minimum_width, out int natural_width) { - var child = get_child (); - if (child != null) { - int min; - int nat; - child.get_preferred_width (out min, out nat); - minimum_width = min; - natural_width = nat; - } else { - minimum_width = -1; - natural_width = -1; - } - } - - public override void size_allocate (Gtk.Allocation allocation) { - Gtk.Allocation new_alloc; - - set_allocation (allocation); - new_alloc = allocation; - if (allocation.width > this.max_width) { - new_alloc.width = this.max_width; - new_alloc.x = allocation.x; - } - - var child = get_child (); - child.size_allocate (new_alloc); - } -} - namespace Contacts.Utils { public void compose_mail (string email) { var mailto_uri = "mailto:" + Uri.escape_string (email, "@" , false); diff --git a/src/meson.build b/src/meson.build index fe3db78..b472ece 100644 --- a/src/meson.build +++ b/src/meson.build @@ -22,6 +22,7 @@ contacts_vala_sources = [ 'contacts-linked-personas-dialog.vala', 'contacts-linking.vala', 'contacts-list-pane.vala', + 'contacts-max-width-bin.vala', 'contacts-settings.vala', 'contacts-setup-window.vala', 'contacts-store.vala', |