fltk-rs / fl2rust

A fluid (fltk ui designer) file to Rust transpiler
MIT License
52 stars 3 forks source link

Size issue of embedded widget_class's sub widgets #21

Closed fbradasc closed 1 year ago

fbradasc commented 1 year ago

If I create a widget_class with sub widgets (in an its own .fl file) and then I use its instance in another .fl file, the widget_class's sub widgets are drawn with the wrong size.

I made a little project which shows the issue (and propose a fix): ewc.tar.gz

Here is a picture of what I observe:

observed

And this is what I expect:

expected

I think the problem is in how the xywh fields of the widget_class are converted in the .rs output file:

$diff expected_my_class_ui.rs observed_my_class_ui.rs
28c28
< let mut base_group = Group::new(0, 0, 150, 150, label);
---
> let mut base_group = Group::new(x, y, w, h, label);
30c30
< let mut fl2rust_widget_2 = Frame::new(0, 0, 150, 25, None);
---
> let mut fl2rust_widget_2 = Frame::new(0 + x, 0 + y, 150 + w, 25 + h, None);
35c35
< let mut fl2rust_widget_3 = Group::new(0, 25, 150, 125, None);
---
> let mut fl2rust_widget_3 = Group::new(0 + x, 25 + y, 150 + w, 125 + h, None);
42c42
< let mut fl2rust_widget_4 = Frame::new(5, 30, 65, 115, None);
---
> let mut fl2rust_widget_4 = Frame::new(5 + x, 30 + y, 65 + w, 115 + h, None);
47c47
< let mut fl2rust_widget_5 = Frame::new(80, 30, 65, 115, None);
---
> let mut fl2rust_widget_5 = Frame::new(80 + x, 30 + y, 65 + w, 115 + h, None);
52d51
< base_group.resize(x,y,w,h);

I made a patch which makes fl2rust produces the .rs output I expect (see the file 0001-Fix-size-of-embedded-widget_class-sub-widgets.patch that I put it in the attached ewc.tar.gz).

Indeed the expected output for Rust shall be in par with the C++ output produced by fluid

MoAlyousef commented 1 year ago

Hi

The proposed fix looks good. Would you like to create a pull request with the suggested changes?

fbradasc commented 1 year ago

Done.

Thank you!