From 49cca32ca56667fcfe81679b145f4df43aa82c83 Mon Sep 17 00:00:00 2001 From: Zander Brown Date: Tue, 7 Nov 2023 10:47:14 +0000 Subject: [PATCH] js: Cleanup usage of StScrollView Whilst you *can* use add_actor() with ScrollView, it's more idiomatic to work on :child Cleanup a few extras along the way Part-of: --- js/gdm/authList.js | 17 ++++++++--------- js/gdm/loginDialog.js | 17 +++++++---------- js/ui/appDisplay.js | 6 +++--- js/ui/calendar.js | 4 ++-- js/ui/components/telepathyClient.js | 10 +++++----- js/ui/dateMenu.js | 19 ++++++++++--------- js/ui/dialog.js | 12 ++++++------ js/ui/lookingGlass.js | 9 ++++----- js/ui/popupMenu.js | 2 +- js/ui/search.js | 4 ++-- js/ui/switcherPopup.js | 5 +++-- js/ui/unlockDialog.js | 6 ++++-- 12 files changed, 55 insertions(+), 56 deletions(-) diff --git a/js/gdm/authList.js b/js/gdm/authList.js index d46fb11bb..e0351a271 100644 --- a/js/gdm/authList.js +++ b/js/gdm/authList.js @@ -84,20 +84,19 @@ export const AuthList = GObject.registerClass({ this.label = new St.Label({style_class: 'login-dialog-auth-list-title'}); this.add_child(this.label); - this._scrollView = new St.ScrollView({ - style_class: 'login-dialog-auth-list-view', - }); - this._scrollView.set_policy( - St.PolicyType.NEVER, St.PolicyType.AUTOMATIC); - this.add_child(this._scrollView); - this._box = new St.BoxLayout({ vertical: true, style_class: 'login-dialog-auth-list', pseudo_class: 'expanded', }); - this._scrollView.add_child(this._box); + this._scrollView = new St.ScrollView({ + style_class: 'login-dialog-auth-list-view', + hscrollbar_policy: St.PolicyType.NEVER, + child: this._box, + }); + this.add_child(this._scrollView); + this._items = new Map(); this.connect('key-focus-in', this._moveFocusToItems.bind(this)); @@ -129,7 +128,7 @@ export const AuthList = GObject.registerClass({ scrollToItem(item) { let box = item.get_allocation_box(); - let adjustment = this._scrollView.get_vscroll_bar().get_adjustment(); + const {adjustment} = this._scrollView.vscroll; let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0); adjustment.ease(value, { diff --git a/js/gdm/loginDialog.js b/js/gdm/loginDialog.js index 0121a2fdc..f3afdbb5e 100644 --- a/js/gdm/loginDialog.js +++ b/js/gdm/loginDialog.js @@ -168,10 +168,8 @@ const UserList = GObject.registerClass({ style_class: 'login-dialog-user-list-view', x_expand: true, y_expand: true, + hscrollbar_policy: St.PolicyType.NEVER, }); - this.set_policy( - St.PolicyType.NEVER, - St.PolicyType.AUTOMATIC); this._box = new St.BoxLayout({ vertical: true, @@ -179,7 +177,7 @@ const UserList = GObject.registerClass({ pseudo_class: 'expanded', }); - this.add_child(this._box); + this.child = this._box; this._items = {}; } @@ -226,7 +224,7 @@ const UserList = GObject.registerClass({ scrollToItem(item) { let box = item.get_allocation_box(); - let adjustment = this.get_vscroll_bar().get_adjustment(); + const {adjustment} = this.vscroll; let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0); adjustment.ease(value, { @@ -238,7 +236,7 @@ const UserList = GObject.registerClass({ jumpToItem(item) { let box = item.get_allocation_box(); - let adjustment = this.get_vscroll_bar().get_adjustment(); + const {adjustment} = this.vscroll; let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0); @@ -487,17 +485,16 @@ export const LoginDialog = GObject.registerClass({ this._userSelectionBox.add_child(this._notListedButton); + const bannerBox = new St.BoxLayout({vertical: true}); + this._bannerView = new St.ScrollView({ style_class: 'login-dialog-banner-view', opacity: 0, - vscrollbar_policy: St.PolicyType.AUTOMATIC, hscrollbar_policy: St.PolicyType.NEVER, + child: bannerBox, }); this.add_child(this._bannerView); - let bannerBox = new St.BoxLayout({vertical: true}); - - this._bannerView.add_child(bannerBox); this._bannerLabel = new St.Label({ style_class: 'login-dialog-banner', text: '', diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 901bb5516..44bcd3dbf 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -520,15 +520,15 @@ var BaseAppView = GObject.registerClass({ y_expand: true, reactive: true, enable_mouse_scrolling: false, + hscrollbar_policy: St.PolicyType.EXTERNAL, + vscrollbar_policy: St.PolicyType.NEVER, + child: this._grid, }); - this._scrollView.set_policy(St.PolicyType.EXTERNAL, St.PolicyType.NEVER); this._canScroll = true; // limiting scrolling speed this._scrollTimeoutId = 0; this._scrollView.connect('scroll-event', this._onScroll.bind(this)); - this._scrollView.add_child(this._grid); - const scroll = this._scrollView.hscroll; this._adjustment = scroll.adjustment; this._adjustment.connect('notify::value', adj => { diff --git a/js/ui/calendar.js b/js/ui/calendar.js index 913203e04..11945a788 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -954,8 +954,8 @@ class CalendarMessageList extends St.Widget { style_class: 'vfade', overlay_scrollbars: true, x_expand: true, y_expand: true, + hscrollbar_policy: St.PolicyType.NEVER, }); - this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC); box.add_child(this._scrollView); let hbox = new St.BoxLayout({style_class: 'message-list-controls'}); @@ -1008,7 +1008,7 @@ class CalendarMessageList extends St.Widget { 'actor-added', this._sync.bind(this), 'actor-removed', this._sync.bind(this), this); - this._scrollView.add_child(this._sectionList); + this._scrollView.child = this._sectionList; this._mediaSection = new Mpris.MediaSection(); this._addSection(this._mediaSection); diff --git a/js/ui/components/telepathyClient.js b/js/ui/components/telepathyClient.js index 001c5d274..41f1be704 100644 --- a/js/ui/components/telepathyClient.js +++ b/js/ui/components/telepathyClient.js @@ -870,17 +870,17 @@ class ChatNotificationBanner extends MessageTray.NotificationBanner { this.emit('unfocused'); }); + this._contentArea = new St.BoxLayout({ + style_class: 'chat-body', + vertical: true, + }); this._scrollArea = new St.ScrollView({ style_class: 'chat-scrollview vfade', vscrollbar_policy: St.PolicyType.AUTOMATIC, hscrollbar_policy: St.PolicyType.NEVER, visible: this.expanded, + child: this._contentArea, }); - this._contentArea = new St.BoxLayout({ - style_class: 'chat-body', - vertical: true, - }); - this._scrollArea.add_child(this._contentArea); this.setExpandedBody(this._scrollArea); this.setExpandedLines(CHAT_EXPAND_LINES); diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js index d9219fda2..53134deb6 100644 --- a/js/ui/dateMenu.js +++ b/js/ui/dateMenu.js @@ -919,20 +919,21 @@ class DateMenuButton extends PanelMenu.Button { vbox.add_child(this._date); vbox.add_child(this._calendar); - this._displaysSection = new St.ScrollView({ - style_class: 'datemenu-displays-section vfade', - x_expand: true, - overlay_scrollbars: true, - }); - this._displaysSection.set_policy(St.PolicyType.NEVER, St.PolicyType.EXTERNAL); - vbox.add_child(this._displaysSection); - const displaysBox = new St.BoxLayout({ vertical: true, x_expand: true, style_class: 'datemenu-displays-box', }); - this._displaysSection.add_child(displaysBox); + + this._displaysSection = new St.ScrollView({ + style_class: 'datemenu-displays-section vfade', + x_expand: true, + overlay_scrollbars: true, + hscrollbar_policy: St.PolicyType.NEVER, + vscrollbar_policy: St.PolicyType.EXTERNAL, + child: displaysBox, + }); + vbox.add_child(this._displaysSection); this._eventsItem = new EventsSection(); displaysBox.add_child(this._eventsItem); diff --git a/js/ui/dialog.js b/js/ui/dialog.js index 62602870f..f0dc021ce 100644 --- a/js/ui/dialog.js +++ b/js/ui/dialog.js @@ -259,16 +259,16 @@ export const ListSection = GObject.registerClass({ _init(params) { this._title = new St.Label({style_class: 'dialog-list-title'}); - this._listScrollView = new St.ScrollView({ - style_class: 'dialog-list-scrollview', - hscrollbar_policy: St.PolicyType.NEVER, - }); - this.list = new St.BoxLayout({ style_class: 'dialog-list-box', vertical: true, }); - this._listScrollView.add_child(this.list); + + this._listScrollView = new St.ScrollView({ + style_class: 'dialog-list-scrollview', + hscrollbar_policy: St.PolicyType.NEVER, + child: this.list, + }); let defaultParams = { style_class: 'dialog-list', diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js index 83f563c7a..3a8c0be73 100644 --- a/js/ui/lookingGlass.js +++ b/js/ui/lookingGlass.js @@ -162,9 +162,8 @@ const Notebook = GObject.registerClass({ labelBox.add_child(label); this.tabControls.add_child(labelBox); - let scrollview = new St.ScrollView({y_expand: true}); - scrollview.get_hscroll_bar().hide(); - scrollview.add_child(child); + const scrollview = new St.ScrollView({y_expand: true, child}); + scrollview.hscroll.hide(); const tabData = { child, @@ -395,7 +394,7 @@ class ObjInspector extends St.ScrollView { this._parentList = []; - this.get_hscroll_bar().hide(); + this.hscroll.hide(); this._container = new St.BoxLayout({ name: 'LookingGlassPropertyInspector', style_class: 'lg-dialog', @@ -403,7 +402,7 @@ class ObjInspector extends St.ScrollView { x_expand: true, y_expand: true, }); - this.add_child(this._container); + this.child = this._container; this._lookingGlass = lookingGlass; } diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js index 131f9ba6c..737188c13 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -1016,9 +1016,9 @@ export class PopupSubMenu extends PopupMenuBase { style_class: 'popup-sub-menu', hscrollbar_policy: St.PolicyType.NEVER, vscrollbar_policy: St.PolicyType.NEVER, + child: this.box, }); - this.actor.add_child(this.box); this.actor._delegate = this; this.actor.clip_to_allocation = true; this.actor.connect('key-press-event', this._onKeyPressEvent.bind(this)); diff --git a/js/ui/search.js b/js/ui/search.js index d31265be3..76918290c 100644 --- a/js/ui/search.js +++ b/js/ui/search.js @@ -573,9 +573,9 @@ export const SearchResultsView = GObject.registerClass({ style_class: 'search-display vfade', x_expand: true, y_expand: true, + hscrollbar_policy: St.PolicyType.NEVER, + child: this._content, }); - this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC); - this._scrollView.add_child(this._content); let action = new Clutter.PanAction({interpolate: true}); action.connect('pan', this._onPan.bind(this)); diff --git a/js/ui/switcherPopup.js b/js/ui/switcherPopup.js index cc44c401a..9017d2c9e 100644 --- a/js/ui/switcherPopup.js +++ b/js/ui/switcherPopup.js @@ -409,10 +409,11 @@ export const SwitcherList = GObject.registerClass({ this._scrollView = new St.ScrollView({ style_class: 'hfade', enable_mouse_scrolling: false, + hscrollbar_policy: St.PolicyType.NEVER, + vscrollbar_policy: St.PolicyType.NEVER, + child: this._list, }); - this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.NEVER); - this._scrollView.add_child(this._list); this.add_child(this._scrollView); // Those arrows indicate whether scrolling in one direction is possible diff --git a/js/ui/unlockDialog.js b/js/ui/unlockDialog.js index 26092320f..94da3270d 100644 --- a/js/ui/unlockDialog.js +++ b/js/ui/unlockDialog.js @@ -43,13 +43,15 @@ const NotificationsBox = GObject.registerClass({ name: 'unlockDialogNotifications', }); - this._scrollView = new St.ScrollView({hscrollbar_policy: St.PolicyType.NEVER}); this._notificationBox = new St.BoxLayout({ vertical: true, style_class: 'unlock-dialog-notifications-container', }); - this._scrollView.add_child(this._notificationBox); + this._scrollView = new St.ScrollView({ + hscrollbar_policy: St.PolicyType.NEVER, + child: this._notificationBox, + }); this.add_child(this._scrollView); this._settings = new Gio.Settings({