Skip to content

Commit

Permalink
set ScrollablePopupMenu height dynamcially
Browse files Browse the repository at this point in the history
  • Loading branch information
rjocoleman committed Nov 29, 2023
1 parent 95c2dd6 commit 9b9eb6a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,16 @@ const ScrollablePopupMenu = GObject.registerClass(

this.scrollView.connect('scroll-event', this._onScrollEvent.bind(this));

this.scrollView.set_height(300);
this.MAX_HEIGHT = 300;

this.addSection = (section) => {
this.box.add_actor(section.actor);
this.updateHeight();
};

this.removeAll = () => {
this.box.destroy_all_children();
this.updateHeight();
};

this.addSectionWithLabel = (section, labelText) => {
Expand All @@ -357,6 +359,15 @@ const ScrollablePopupMenu = GObject.registerClass(
this.box.add_actor(label);
}
this.box.add_actor(section.actor);
this.updateHeight();
};

this.updateHeight = () => {
let totalHeight = 0;
this.box.get_children().forEach(child => {
totalHeight += child.get_preferred_height(-1)[1];
});
this.scrollView.set_height(Math.min(totalHeight, this.MAX_HEIGHT));
};
}

Expand Down

0 comments on commit 9b9eb6a

Please sign in to comment.