Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluid: Reposition and rescale #497

Closed
wants to merge 3 commits into from

Conversation

etorth
Copy link
Contributor

@etorth etorth commented Sep 8, 2022

Continuation of #481

@etorth etorth marked this pull request as ready for review September 8, 2022 22:38
@Albrecht-S Albrecht-S added enhancement New feature or request fluid Fast Light User Interface Designer (fluid) labels Sep 9, 2022
@Albrecht-S Albrecht-S changed the title Reposition and rescale Fluid: Reposition and rescale Sep 9, 2022
@MatthiasWM
Copy link
Contributor

Sorry for the very late reply.

OK, so I see what you are doing here, and I believe that we can do a much easier implementation. If you set relative position, the Widget Class is generate at 0, 0 first and later moved, so the Fl_Group::position() method does all the work. We can do the same for resizing. We just let Fl_Group::resize() do all the work for us. So these would be the code snippets for all three options:

Default:

UserInterface::UserInterface(int X, int Y, int W, int H, const char *L) :
  Fl_Group(X, Y, W, H, L)
{
  { new Fl_Button(20, 20, 63, 20, "button");
  } // Fl_Button* o
  end();
}

Position relative:

UserInterface::UserInterface(int X, int Y, int W, int H, const char *L) :
  Fl_Group(0, 0, W, H, L)
{
  { new Fl_Button(20, 20, 63, 20, "button");
  } // Fl_Button* o
  position(X, Y);
  end();
}

Position and size relative:

UserInterface::UserInterface(int X, int Y, int W, int H, const char *L) :
  Fl_Group(0, 0, 329, 224, L)  // 329 and 224 is the original size from Fluid
{
  { new Fl_Button(20, 20, 63, 20, "button");
  } // Fl_Button* o
  resize(X, Y, W, H);
  end();
}

Please let me know if this solves your issues.

@etorth
Copy link
Contributor Author

etorth commented Nov 1, 2022

It won't work if your embedded widgets has larger size than embedding widget.

Sorry for the very late reply.

OK, so I see what you are doing here, and I believe that we can do a much easier implementation. If you set relative position, the Widget Class is generate at 0, 0 first and later moved, so the Fl_Group::position() method does all the work. We can do the same for resizing. We just let Fl_Group::resize() do all the work for us. So these would be the code snippets for all three options:

Default:

UserInterface::UserInterface(int X, int Y, int W, int H, const char *L) :
  Fl_Group(X, Y, W, H, L)
{
  { new Fl_Button(20, 20, 63, 20, "button");
  } // Fl_Button* o
  end();
}

Position relative:

UserInterface::UserInterface(int X, int Y, int W, int H, const char *L) :
  Fl_Group(0, 0, W, H, L)
{
  { new Fl_Button(20, 20, 63, 20, "button");
  } // Fl_Button* o
  position(X, Y);
  end();
}

Position and size relative:

UserInterface::UserInterface(int X, int Y, int W, int H, const char *L) :
  Fl_Group(0, 0, 329, 224, L)  // 329 and 224 is the original size from Fluid
{
  { new Fl_Button(20, 20, 63, 20, "button");
  } // Fl_Button* o
  resize(X, Y, W, H);
  end();
}

Please let me know if this solves your issues.

@MatthiasWM
Copy link
Contributor

Why not? The resize() will update your embedded window to fit to the requested size, resizing all its children as well. Maybe I am missing something here. The original message had sample code. Could you please post a .fl where original Fluid generates code that does not work for you, so I can try out my approach? Thanks!

It won't work if your embedded widgets has larger size than embedding widget.

Position and size relative:

  ...
  resize(X, Y, W, H);
  ...

@Albrecht-S
Copy link
Member

Could you please post a .fl where original Fluid generates code that does not work for you, so I can try out my approach?

@MatthiasWM On behalf of the OP, it's all there.

  1. The original test.fl file is inlined in this Fluid: enhancement for widget_class for extra option: reposition-and-rescale #481 (comment)
  2. My modified .fl file can be found as a link in this Fluid: enhancement for widget_class for extra option: reposition-and-rescale #481 (comment) together with my notes what was "wrong" in the original file (widget sizes). Direct link: pr-481_resize_rescale_v3.fl.txt

I just tested both .fl files with current fluid and you can easily see the difference. Obviously the OP's proposal is intended to "fix" the code generated by fluid from their original test.fl file so it works like the file modified by me.

The discussion continued in #481 (comment) where @etorth explained why his patch would be useful because you can't always "know" the exact size of a "class definition" if it has been developed in another project or by another team.

@MatthiasWM That said, I'm not sure if it's worth the effort and I wasn't sure whether the proposed code would be correct. That's why I asked for your review. I'm +/- 0 on this change and would like to leave the decision to you.

@MatthiasWM
Copy link
Contributor

@etorth @Albrecht-S Ok, so I implemented the feature in PR #531 . The implementation works as expected with the give .fl file, and I am pretty sure it will work well for other cases too. It's actually a nice feature that makes widget classes more useful.

@MatthiasWM MatthiasWM closed this Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fluid Fast Light User Interface Designer (fluid)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants