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

Add 'Load From SVG Resource' for bitmap property #817

Merged
merged 4 commits into from May 16, 2024

Conversation

vadimgrn
Copy link

@vadimgrn vadimgrn commented May 9, 2024

Adds ability to create a bitmap property from SVG resource on Windows or Mac. wxBitmapBundle::FromSVGResource is used for that. The code generation is implemented for C++ only, I am not familiar with wxWidgets library for Python, Lua, etc.

Signed-off-by: Vadym Hrynchyshyn <vadym.hrynchyshyn@qsc.com>
Copy link
Member

@sodevel sodevel left a comment

Choose a reason for hiding this comment

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

Thanks for this addition. I am also only using C++ and know only very little about the other languages, but doing nothing for the other languages leads to the generation of invalid code, this is not acceptable. Currently, the code generators output a Null-Bitmap for unsupported or not implemented options to at least generate valid output. It would be great if you could do that for the other generators, otherwise i will do it myself later.

Besides this point, the PR is looking good to me, i have just some remarks regarding code style, maybe you can address these, please see the following review.

@@ -96,6 +96,7 @@ class wxFBBitmapProperty : public wxPGProperty
wxPGProperty* CreatePropertyFilePath();
wxPGProperty* CreatePropertyResourceName();
wxPGProperty* CreatePropertyIconSize();
wxPGProperty* CreatePropertyDefSize();
Copy link
Member

Choose a reason for hiding this comment

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

All other methods use the full name of the property instead of an abbrevation, so CreatePropertyDefaultSize() would fit the current naming scheme better.

Copy link
Author

Choose a reason for hiding this comment

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

done

wxPGProperty* wxFBBitmapProperty::CreatePropertyDefSize()
{
// Create 'def_size' property ('Load From SVG Resource' only)
wxPGProperty* propDefSize = new wxFBSizeProperty(wxT("def_size"), wxPG_LABEL, {16, 16});
Copy link
Member

Choose a reason for hiding this comment

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

Why is 16 used as default value? Pretty much in every other place of wxFB a defined default value like wxDefaultSize (-1, -1) is used, can't this be used here as well?

Copy link
Author

@vadimgrn vadimgrn May 15, 2024

Choose a reason for hiding this comment

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

wxDefaultSize(-1, -1) crashes the app. wxBitmapBundle::FromSVGResource expects real WxH because SVG doesn't have size, it will be rasterized to BMP with passed size. 16x16 is used for menu items, 24x24 for toolbars, etc.

@@ -502,7 +518,7 @@ wxVariant wxFBBitmapProperty::ChildChanged(wxVariant& thisValue, const int child
const auto count = GetChildCount();

// childValue.GetInteger() returns the chosen item index
switch (childValue.GetInteger()) {
switch (auto child_val = childValue.GetInteger()) {
Copy link
Member

Choose a reason for hiding this comment

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

Current code usually uses CamelCase, childVal would be more fitting.

Copy link
Author

Choose a reason for hiding this comment

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

done

Comment on lines 572 to 573
auto prop = child_val == 3 ? bp->CreatePropertyIconSize() : bp->CreatePropertyDefSize();
bp->AppendChild(prop);
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to store the result of the ternary operator in a local variable, the result could be passed in-place to AppendChild()

Copy link
Author

Choose a reason for hiding this comment

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

done

@sodevel
Copy link
Member

sodevel commented May 15, 2024

Not part of this PR, but related:

bp->SetPrevSource(childValue.GetInteger());

This is the source of assertions that occur when changing certain child values like ico_size or def_size and probably causes that strange error behaviour when switching between specific source types. Most probably this line belongs in the case 0 of the previous switch.

Signed-off-by: Vadym Hrynchyshyn <vadym.hrynchyshyn@qsc.com>
@vadimgrn
Copy link
Author

Added wxNullBitmap generation for other languages, can't check that, but generated source files look OK.

Copy link
Member

@sodevel sodevel left a comment

Choose a reason for hiding this comment

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

Thank you for the updates, this looks good to me.

In this order all resource based options are grouped together.
Although both types have a common child, they have a different child
for their size property, so a child update is necessary on type change.
@sodevel sodevel merged commit f825645 into wxFormBuilder:master May 16, 2024
8 checks passed
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.

None yet

2 participants