searchDisplay: set a max width on the search results scrolled child

On large displays, we don't want the search results list to expand
across the whole screen; set a maximum width of 1000px.
Unfortunately, since in St max-width only affects size requisition, we
need a little custom layout manager to have it applied to the allocation
too.

https://bugzilla.gnome.org/show_bug.cgi?id=692453
This commit is contained in:
Cosimo Cecchi 2013-01-23 14:35:28 -05:00
parent 4bd071bf3c
commit 30aaa6e26c
2 changed files with 32 additions and 1 deletions

View File

@ -779,6 +779,10 @@ StScrollBar StButton#vhandle:active {
spacing: 18px; spacing: 18px;
} }
#searchResultsBin {
max-width: 1000px;
}
#searchResultsContent { #searchResultsContent {
padding-right: 20px; padding-right: 20px;
spacing: 16px; spacing: 16px;

View File

@ -17,6 +17,26 @@ const Search = imports.ui.search;
const MAX_LIST_SEARCH_RESULTS_ROWS = 3; const MAX_LIST_SEARCH_RESULTS_ROWS = 3;
const MAX_GRID_SEARCH_RESULTS_ROWS = 1; const MAX_GRID_SEARCH_RESULTS_ROWS = 1;
const MaxWidthBin = new Lang.Class({
Name: 'MaxWidthBin',
Extends: St.Bin,
vfunc_allocate: function(box, flags) {
let themeNode = this.get_theme_node();
let maxWidth = themeNode.get_max_width();
let availWidth = box.x2 - box.x1;
let adjustedBox = box;
if (availWidth > maxWidth) {
let excessWidth = availWidth - maxWidth;
adjustedBox.x1 += Math.floor(excessWidth / 2);
adjustedBox.x2 -= Math.floor(excessWidth / 2);
}
this.parent(adjustedBox, flags);
}
});
const SearchResult = new Lang.Class({ const SearchResult = new Lang.Class({
Name: 'SearchResult', Name: 'SearchResult',
@ -301,12 +321,19 @@ const SearchResults = new Lang.Class({
this._content = new St.BoxLayout({ name: 'searchResultsContent', this._content = new St.BoxLayout({ name: 'searchResultsContent',
vertical: true }); vertical: true });
this._contentBin = new MaxWidthBin({ name: 'searchResultsBin',
x_fill: true,
y_fill: true,
child: this._content });
let scrollChild = new St.BoxLayout();
scrollChild.add(this._contentBin, { expand: true });
this._scrollView = new St.ScrollView({ x_fill: true, this._scrollView = new St.ScrollView({ x_fill: true,
y_fill: false, y_fill: false,
style_class: 'vfade' }); style_class: 'vfade' });
this._scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC); this._scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
this._scrollView.add_actor(this._content); this._scrollView.add_actor(scrollChild);
let action = new Clutter.PanAction({ interpolate: true }); let action = new Clutter.PanAction({ interpolate: true });
action.connect('pan', Lang.bind(this, this._onPan)); action.connect('pan', Lang.bind(this, this._onPan));
this._scrollView.add_action(action); this._scrollView.add_action(action);