I have the following code: in a St.ScrollView I have added a St.BoxLayout . The St.Scrollview is added in a menu.box.Now I want to create a St.Button, to remove the St.BoxLayout from St.ScrollView and add another St.BoxLayout there.I have tried to make a function "clicked" connected with the button, and do this:
this.buttonnotifications.connect('clicked', this.displayNotifications);
displayNotifications: function() {
this.scrollbox.remove(this.vbox);
this.menu.box.remove(this.scrollbox);
this.scrollbox.add_actor(this.vbox1);
this.menu.box.add(this.scrollbox);
},
but it does not work.A snippet of the code is below:
this.buttonbox = new St.BoxLayout();
this.buttontoday = new St.Button({ label: 'Today', width: 140, x_align: 1, style_class: 'selectbutton'});
this.buttonnotifications = new St.Button({ label: 'Notifications', width: 140, x_align: 1, style_class: 'selectbutton'});
this.buttonbox.add_actor(this.buttontoday);
this.buttonbox.add_actor(this.buttonnotifications);
this.menu.box.add(this.buttonbox);
this.scrollbox = new St.ScrollView({
height: 700,
width: 330,
hscrollbar_policy: 2,
vscrollbar_policy: 2,
enable_mouse_scrolling: true
});
this.vbox = new St.BoxLayout({
//height: 1400,
//width: 330,
vertical: true,
//y_expand: true,
style_class: "datemenu-displays-box",
style: "border:10px;"
});
this.vbox1 = new St.BoxLayout({
//height: 1400,
//width: 330,
vertical: true,
//y_expand: true,
style_class: "datemenu-displays-box",
style: "border:10px;"
});
this.vbox.add_actor(this._date.actor);
this.vbox.add_actor(this._calendar.actor);
this.vbox1.add_actor(this._eventsSection.actor, {
//x_fill: true
});
this.vbox.add_actor(this._mediaSection.actor);
this.vbox.add_actor(this._clocksSection.actor);
this.vbox.add_actor(this._weatherSection.actor, {
//x_fill: true
});
this.vbox1.add_actor(this._messageList.actor);
this.scrollbox.add_actor(this.vbox);
this.menu.box.add(this.scrollbox);
In other words I want to remove the vbox and add vbox1 pressing the buttonnotifications. Any help will be appreciated. Thanks in advance.
I have managed to solve this by adding this code:
this.buttonnotifications.connect('clicked', this.displayNotifications.bind(this));
The difference to the previous code is
.bind(this)
method.