On 12/27/19, 7:02 AM, "Carlos Rovira" <[email protected]> wrote:
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?
Yes, it is fine to change them 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.
The original discussion included the topic of higher-level abstractions vs
platform-specific APIs. It seems you really want Jewel users to use a
platform-specific API, so you are welcome to allow NaN in Jewel.
If I were to implement something similar in Basic, I would first try to
understand how often it is needed and where it is needed because I would not
want to implement something on UIBase "just-in-case". If it was primarily
needed on, say, a TitleWindow/Panel thing, that TitleWindow might get a
higher-level API like 'displayState" which could have the values "minimized,
maximized, sizedToContent". The underlying code behind displayState would call
the sizeToContent utility function. And then it could be used in ternary
expressions. And I might implement that on a subclass of TitleWindow
(TitleWindowWithDisplayState) so that not all TitleWindows/Panels carry that
API.
One of the things I think you are running into with inheritWidth (which doesn't
actually get set to inherit when you set to null, IMO, so I'm not a fan of the
name), is that in Royale we have elected to make width a Number where in the
browser it is a String. If you want to expose browser APIs to Jewel users, you
may want to come up with a whole new set of base classes that more directly
mimic the browser API. Then setting width to NaN or null wouldn't be a factor.
Folks would be setting the value to a string like "auto" instead. However I
think there are good reasons for most other Royale components to make width a
Number. I think there are way more calculations of width based on Numbers,
although I can imagine a component set where width is always determined by
constraints and not values. I think it is very rare for folks to need to
switch random components from sizeToParent to sizeToContent, and that the
components that need that more frequently can expose that choice in subclasses
for those who need to manage that value via expressions.
My 2 cents,
-Alex
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
https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&data=02%7C01%7Caharui%40adobe.com%7C39715e51de7749703a2b08d78addbb1a%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C637130557240362094&sdata=yeDSDeCKTNK1jeg8unPRrxVTKMvd8mmqBE%2F6FmJxC%2FQ%3D&reserved=0