Skip to content

Instantly share code, notes, and snippets.

@kirillp
Created January 10, 2017 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirillp/4cc967c813194d087ff0ec237a64c43f to your computer and use it in GitHub Desktop.
Save kirillp/4cc967c813194d087ff0ec237a64c43f to your computer and use it in GitHub Desktop.
package delightex.moe.nativecontrols;
import apple.coregraphics.struct.CGRect;
import apple.uikit.UITextField;
import apple.uikit.struct.UIEdgeInsets;
import delightex.graphics.moe.util.MoeUtils;
import delightex.tools.Logger;
import org.moe.natj.general.Pointer;
import org.moe.natj.general.ann.ByValue;
import org.moe.natj.general.ann.Runtime;
import org.moe.natj.objc.ObjCRuntime;
import org.moe.natj.objc.ann.ObjCClassName;
import org.moe.natj.objc.ann.Selector;
@Runtime(ObjCRuntime.class)
@ObjCClassName("CustomTextField")
class CustomTextField extends UITextField {
private UIEdgeInsets myPaddingInsets;
protected CustomTextField(Pointer peer) {
super(peer);
Logger.log("CustomTextField.ctor");
}
@Selector("alloc")
public static native CustomTextField alloc();
@Selector("init")
public native CustomTextField init();
@Override
public CGRect editingRectForBounds(@ByValue CGRect cgRect) {
return textRectForBounds(cgRect);
}
@Override
public CGRect textRectForBounds(@ByValue CGRect cgRect) {
return myPaddingInsets != null ? MoeUtils.inset(cgRect, myPaddingInsets) : cgRect;
}
void setPadding(double top, double right, double bottom, double left) {
myPaddingInsets = new UIEdgeInsets(top, left, bottom, right);
setNeedsLayout();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment