I am making a new class in C4 and I am wondering what they should inherit from?
The class is a helper classes and not visual, so should it inherit from C4Object instead of C4Control or NSObject (or some other default class)?
Best option for non-visual objects is to inherit from C4Object.
The C4Object class has all the same functionality of C4Control, except those options for changing any visual state (e.g. origin, borderWidth, animationDuration, etc.). C4Control subclasses should be strictly reserved for visual objects.
Related
I am working with Qt and came across class hierarchies where a base class (sometimes an abstract class) contains Q_PROPERTY macros; will a derived class inherit each Q_PROPERTY from its base class?
Yes, it will. You can easily check this in your debugger: just set a breakpoint after the view / scene is there and inspeckt one of your QObject-instances. You can access the meta-data and the private data for your object and from your base class.
In gwt how to get a widget's default style(CSS Selector).For example, gwt button has style name "gwt-button" which is referenced in gwt theme css file.
How to got that programmatically.
Is there any,
DOM.getStyleAttribute();
to accomplish this. GWT experts please help.
In your example of button (or any object that is a child of UIObject) can call getStyleName()
UIObject documentation
String com.google.gwt.user.client.ui.UIObject.getStyleName()
Gets all of the object's style names, as a space-separated list. If you wish to retrieve only the primary style name, call getStylePrimaryName().
Now as to why you need this information is the real question. It is my guess that you want to change the styling of an object (add or remove). This would best be done by either of the following methods.
1) Supplying a custom resources file to the object that has your styling
2) creating a class that extends Composite and create a custom UIBinder class with all of your styles within it.
I am having trouble wrapping my head around the spark skin class in relation to it's host component. Basically, from what I've seen with most every skin that comes in the Flex 4 framework they don't directly expose the properties that are dynamically being set in the host component. Instead, they define states that get exposed to the skin class to define when a component should look different. This is all fine and dandy when you have a very simple component with a standard set of states, but when you have twenty different properties (hypothetically) to set in your host component that should change how the skin looks it could get very complicated very fast.
The way that I've seen that they have used to get around this is by overriding the commitproperties and invalidate functions in the skin class, grabbing the values for the properties they want from there, and then setting them to a locally instantiated variable inside the skin class. This is fine, but I feel like that is just a patch workaround to it which makes things a lot more complicated than it needs to be.
HERE'S MY QUESTION:
Is there any way to directly expose a bindable property from the host component class so when you define your skin class it is directly ready to be read from? Let's say you have custom button with a boolean property of 'selected'. In the skin class, you want to add in a get and set function for the property 'selected' so you can perform some action upon your skin whenever it's set. How do you tell the skin class that this is an available property for you to work with from the host component?
This question exists at a very theoretical level. I'm not clear what you're trying to accomplish, nor what sort of properties you're setting on your component class. I suspect, there is an architecture problem if you have 20 properties and each one needs to correlate to a different skin states somehow.
However, I can try to answer your specific questions.
Is there any way to directly expose a bindable property from the
host component class so when you define your skin class it is directly
ready to be read from?
When building Flex MobileSkins, they recommend creating a property named hostComponent which gives the skin class a reference to the component class. MXML skins already have a similar property. If you're using a custom skin, this property is created automatically using the HostComponent metadata. Therefore from the skin class you can access properties on the component class using the hostComponent property.
Let's say you have custom button with a boolean property of
'selected'. In the skin class, you want to add in a get and set
function for the property 'selected' so you can perform some action
upon your skin whenever it's set.
I'm not envisioning the situation where you would want to do this. Generally you would not define any properties on the skin class which you intend to explicitly change on the instance of the skin class.
You could dispatch an event from the component class when the property changes. [This is very common]. Then listen for that event in the skin class using the hostComponent property and change things there.
There is also a way to access the skin class instance from within the component class. So you could change properties directly on the skin class using the skin property.
I wouldn't follow either approach without thinking it through. Ideally the component class and skin class should be encapsulated from each other; and each approach would provide dependencies.
When you affect a skin to a component, you can use metatags to store a reference to the skin part you actually use :
[SkinPart(required="false")]
public var resizeHandle:UIComponent;
Then, when overriding the partAdded and partRemoved methods, you will be able to set or unset whatever you want in these skin parts, from the basic properties to event listeners.
override protected function partAdded( partName:String, instance:Object):void
{
super.partAdded(partName, instance);
if (instance == resizeHandle) {
resizeHandle.addEventListener(MouseEvent.MOUSE_DOWN, resizeHandle_mouseDownHandler);
}
}
override protected function partRemoved(partName:String, instance:Object):void
{
if (instance == resizeHandle) {
resizeHandle.removeEventListener(MouseEvent.MOUSE_DOWN, esizeHandle_mouseDownHandler);
}
super.partRemoved(partName, instance);
}
Furthermore, since you have stored a reference to your skin parts, you can still access it whenever you want in your host component and update it. Am I clear ? :-)
When debugging some container sizes (namely, HBox) in Flex (v. 3.5), I noticed a variable "$height" in the Variables list.
Does anyone know what this variable is? It's marked as protected, but I don't believe I can access it in a child class.
I've noticed it sometimes gets a different value than "height" and "_height". Does anyone know why this is and what it means for how a component is drawn?
The full mx framework source is available in your sdk directory here:
\..\sdks\3.3.0\frameworks\projects\framework\src
The private documentation says.
/*
* This property allows access to the Player's native implementation
* of the 'height' property, which can be useful since components
* can override 'height' and thereby hide the native implementation.
* Note that this "base property" is final and cannot be overridden,
* so you can count on it to reflect what is happening at the player level.
*/
It's marked with mx_internal so you need to declare use namespace mx_internal; to get access to it in your own class.
Flex overrides a lot of methods in it's custom objects, such as FlexSprite.
In their internal code base, they often declare new methods that are marked 'final' and super() to the default method implementation. These final methods start with '$' so that they are easily identifiable.
Another example you would see is '$addChild', flex has custom addChild functionality, but uses the original implementation internally through the '$addChild' method.
Does anyone know if it is possible to inject into a regular as3 (non mxml) class? I've tried with limited success.
Thanks
Could you be more specific? There's no difference between an "MXML" class and a class defined in ActionScript, it's just different ways of writing the same thing.
All that is needed for injection to work is a source property that is bindable and a destination property that is public (either a public setter or a public instance variable). If those two requirements are met and the code compiles it should work.
Look at the code for the example application you can find here: http://code.google.com/p/mate-examples/wiki/DocumentBasedExampleIntro and you will find a ton of injectors that target classes not defined using MXML (look for injectors targeting classes whose names end in "Model" especially). You can also find countless examples in the Mate forums.