Snarling / bitburner-scripts

Various scripts for the game Bitburner, available on steam or at https://danielyxie.github.io/bitburner/
GNU General Public License v3.0
38 stars 5 forks source link

Set height of new sidebar item? #8

Closed RobLeachman closed 2 years ago

RobLeachman commented 2 years ago

(will go ahead and open an issue since the provided overview.js has this problem... mostly just a question)

I don't see a way to set the height of a new sidebar item. When my new item is added the height of the content is zero. Am I missing something? Thanks!

JefStat commented 2 years ago
box = createSidebarItem(title, "<div/>", icon);
box.style.height = '100px';
RobLeachman commented 2 years ago

That's pretty sweet @JefStat! Now how to calculate the right size? I mean I'll hardcode for now and thank you very much! but...

Snarling commented 2 years ago

@RobLeachman Yeah the overview height doesn't fit the extra content when you start working/etc since it only takes into account the content added directly in createItem. I might use something like the below to give it a height of 50px more than the starting content or something like that, so that it has room to add extra lines from work / etc.

If you remove the px height, the height becomes whatever is needed for the content. But if you leave the px height off, height transitions don't work anymore, and you'll get a new px height added anyway as soon as you start resizing. So this seems to be the best way to fit height to content:

let fitHeightToContent=box=>{
  box.style.height=""; //Height becomes normal height of content
  box.style.height=box.offsetHeight+"px" //Explicitly sets new height equal to current height
}
Snarling commented 2 years ago

Added builtin solution in commit 348f221.

RobLeachman commented 2 years ago

This is awesome :) thanks for the quick work! A++ would whine again