Hi Harbs,

I assume your implementation is part of the StyledUIBase class.
One thing I see is _width and _height are private (as well the rest of
underscored vars in UIBase), should be change it to protected?

if you consider NaN to be error prone, we should consider other option,
since for me the important part here is the flexibility/usability of the
solution through ternary/binding constructions in MXML or AS3 code by users.



El vie., 27 dic. 2019 a las 14:00, Harbs (<[email protected]>) escribió:

> I would implement it differently:
>
> COMPILE::SWF//assuming this works in SWF
> public function
> inheritDimensions(width:Boolean=true,height:Boolean=true):void{
>   if(width){
>     this.width = NaN;
>   }
>   if(height){
>     this.height = NaN;
>   }
> }
> COMPILE::JS
> public function
> inheritDimensions(width:Boolean=true,height:Boolean=true):void{
>         if(width){
>           _width = _explicitWidth = _percentWidth = NaN;
>           this.positioner.style.width = null;
>         }
>         if(height){
>           _height = _explicitHeight = _percentHeight = NaN;
>           this.positioner.style.height = null;
>         }
>     // do we need to dispatch an event?
> }
>
> > 1.- *I loose ternary operato**rs*. I mean expressions like:
> *button.width
> > = **condition ? 200 : NaN;*
>
> Like I already said, I think this kind of code is bug-prone, so I don’t
> share your concern.
>
> > 2.- *Lose opportunity to do binding in MXML*. I mean expressions like:
> > *button.width
> > = "{condition ? 200 : NaN}”*
>
> You can create a subclass of Button in your application with custom
> setters if this is a concern.
>
> > 3.- *Duplicating `style.width` instruction*. In setWidth the
> > positioner.style.width is set to "NaNpx" then we reach the
> > "setInheritWidth" to remove to null. No collateral problems, but just
> seems
> > poor code.
>
> My implementation solves this problem. Ideally I’d like to solve the
> problem of accessing private vars from utility functions, but that’s
> another topic.
>
>
> HTH,
> Harbs
> > On Dec 27, 2019, at 2:03 PM, Carlos Rovira <[email protected]>
> wrote:
> >
> > public function setInheritWidth(noEvent:Boolean = false):void
> > {
> > setWidth(NaN);//we need _width = NaN
> > COMPILE::JS
> > {
> > this.positioner.style.width = null;//remove style.width after setWidth
> sets
> > _width to "NaNpx" for JS
> > }
> > }
>
>

-- 
Carlos Rovira
http://about.me/carlosrovira

Reply via email to