Bug #13872
openWCompositeWidget does not Apply Style classes from Implementation class
0%
Description
Only Tested with WPanel implementation so far.
Making a WCompositeWidget
implement a WPanel
, the Panel Specific style classes are not added.
Making it collapsible: it works, but there is no indicator: the Collapse Button is not visible.
It does not even look like a WPanel
or "card"
at all.
Unless this is desired behaviour, but I do not think so
Sample Code WPanel in Contrast
Files
Updated by Matthias Van Ceulebroeck 5 days ago
- Assignee set to Matthias Van Ceulebroeck
- Target version set to 4.12.3
Hello Christian,
this is a VERY good catch. No theming is ever applied to the WPanel
.
This could be the case for any widget that is set as the WCompositeWidget
's implementation. I am however sure I have seen this work for certain other widgets, and am curious as to what the discrepancy is.
Updated by Christian Meyer 5 days ago
Hi Matthias
The Wt- Internal Composite Widgets (like WPanel) work as expected. Because they are a Special Type that is handled in the Theme.
It is different for User Generated Composites.
From what I could figure out, I wrote a Patch, but it really is not a longterm, global solution.
It just targets WBootstrap5Theme
, making its apply()
function a friend of WCompositeWidget
, and in the apply()
function, change the widget to the implementation()
of the composite Widget.
Updated by Christian Meyer about 21 hours ago
I made a way better patch...
I added a function to WCompositeWidget
to check if the impl_
widget can be cast
to a Type:
template <typename T>
bool canCastTo() const {
if (!impl_) {
return false; // Cannot cast if no implementation widget exists
}
// Perform the dynamic_cast and check if it succeeds
return dynamic_cast<T>(impl_.get()) != nullptr;
}
There are concepts for the future, and also static_asserts to make sure the type fits. (left out here)
Within the ::apply()
functions of the Bootstrap and Css Theme Classes, I added a check to see if it is a composite:
WCompositeWidget *composite = dynamic_cast<WCompositeWidget*>(widget);
auto panel = dynami_cast<WPanel*>(widget);
if(panel || (composite && composite->canCastTo<WPanel*>()))
{
... // Apply Style
}
Updated the ::apply()
Function for WCSSTheme as well as Bootstrap 2, 3 & 5