Skip to content

Geyser H/VBox: Do not resize if policy is not dynamic#3941

Closed
demonnic wants to merge 8 commits intoMudlet:developmentfrom
demonnic:donot_resize_if_not_dynamic
Closed

Geyser H/VBox: Do not resize if policy is not dynamic#3941
demonnic wants to merge 8 commits intoMudlet:developmentfrom
demonnic:donot_resize_if_not_dynamic

Conversation

@demonnic
Copy link
Copy Markdown
Member

@demonnic demonnic commented Jun 28, 2020

Brief overview of PR changes/additions

Right now, if you create an item with a fixed pixel height and v_policy of fixed, and add it to a VBox, then it will not visibly change size but it does get resized from that static pixel height to a % of the vbox's height which represents the same number of pixels.

This is ok, unless your vbox changes size, as now the item inside of it will change sizes to be the same percentage of the new size. With this change, the height or width is only resized if the policy actually calls for it.

Motivation for adding to Mudlet

I was working on an elastic version of VBox which grows or shrinks to fit its contents, but it quickly ran away as the items inside changed size, which told the vbox to get bigger, which made the items inside bigger...

Other info (issues closed, discussion etc)

This does involve a small performance hit the first time an item is added to an H/VBox if both h_policy and v_policy are Geyser.Dynamic, but because I guard against calling resize if the height or width is already where it should be, every change after that should result in the same or better performance as it currently has.

Given the VBox makes it the full width if h_policy is dynamic, you can also reduce this by setting the width to 100% and it won't need to resize it. Same with HBox and the v_policy/height

@demonnic demonnic requested a review from a team June 28, 2020 16:26
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Jun 28, 2020

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Jun 29, 2020

@Edru2 could you review?

@Edru2
Copy link
Copy Markdown
Member

Edru2 commented Jun 29, 2020

I agree with you that Geyser.fixed shouldn't convert pixel values to percentages but this creates another (new) issue.
I created a Hbox (copied and modified from the Geyser Wiki)

TestHBox = Geyser.HBox:new({
  name="HBox",
  x=0, y=0,
  width="30%", height="10%",
  })
  
  local label1 = Geyser.Label:new({
  name="Label1",
  width="250px",
  h_policy=Geyser.Fixed,
  },
  TestHBox)
label1:echo("Label 1", "black", "c")
label1:setColor(255, 0, 0)

 local label2 = Geyser.Label:new({
  name="Label2",
  },
  TestHBox)
label2:echo("Label 2", "black", "c")
label2:setColor(0, 255, 0)

 local label3 = Geyser.Label:new({
  name="Label3",
  h_stretch_factor=2.0,
  },
  TestHBox)
label3:echo("Label 3", nil, "c")
label3:setColor(0, 0, 255)

 local label4 = Geyser.Label:new({
  name="Label4",
  width="200px",
  h_policy=Geyser.Fixed,
  },
  TestHBox)
label4:echo("Label 4", "black", "c")
label4:setColor(0, 255, 255)

And then use

lua TestHBox:resize("100%",nil)

in the command line.
This creates a big gap between the first Label and the second one.

As seen in this gif.
gap

@Edru2
Copy link
Copy Markdown
Member

Edru2 commented Jun 29, 2020

@demonnic check out demonnic#5

@demonnic
Copy link
Copy Markdown
Member Author

That does indeed fix that. Good catch, and thanks for the fix

@demonnic
Copy link
Copy Markdown
Member Author

should we set self.contains_fixed to false at the start of the organize loop, so that if it later does not contain fixed items it will report properly?

@Edru2
Copy link
Copy Markdown
Member

Edru2 commented Jun 29, 2020

should we set self.contains_fixed to false at the start of the organize loop, so that if it later does not contain fixed items it will report properly?

Yes, I missed that one :)

@demonnic
Copy link
Copy Markdown
Member Author

added

@demonnic
Copy link
Copy Markdown
Member Author

ok, I think this is good now. @Edru2 ?

Copy link
Copy Markdown
Member

@vadi2 vadi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested it myself, approving based on demonnics and Edru's work.

@demonnic
Copy link
Copy Markdown
Member Author

demonnic commented Jul 1, 2020

Closing this PR so I can open a new one without the bogus unfinished checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants