TextView paddings
This commit is contained in:
9
haxework/gui/HasPaddings.hx
Normal file
9
haxework/gui/HasPaddings.hx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package haxework.gui;
|
||||||
|
|
||||||
|
interface HasPaddings {
|
||||||
|
public var leftPadding(default, set):Float;
|
||||||
|
public var rightPadding(default, set):Float;
|
||||||
|
public var topPadding(default, set):Float;
|
||||||
|
public var bottomPadding(default, set):Float;
|
||||||
|
public var paddings(null, set):Float;
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import haxework.gui.core.HAlign;
|
|||||||
import haxework.gui.core.VAlign;
|
import haxework.gui.core.VAlign;
|
||||||
import haxework.gui.layout.ILayout;
|
import haxework.gui.layout.ILayout;
|
||||||
|
|
||||||
interface IGroupView<C:Content> extends IView<C> {
|
interface IGroupView<C:Content> extends IView<C> extends HasPaddings {
|
||||||
|
|
||||||
public var views(default, null):Array<IView<Dynamic>>;
|
public var views(default, null):Array<IView<Dynamic>>;
|
||||||
public var layout(default, default):ILayout;
|
public var layout(default, default):ILayout;
|
||||||
@@ -14,12 +14,6 @@ interface IGroupView<C:Content> extends IView<C> {
|
|||||||
public var layoutHAlign(default, set):HAlign;
|
public var layoutHAlign(default, set):HAlign;
|
||||||
public var layoutMargin(default, set):Float;
|
public var layoutMargin(default, set):Float;
|
||||||
|
|
||||||
public var leftPadding(default, set):Float;
|
|
||||||
public var rightPadding(default, set):Float;
|
|
||||||
public var topPadding(default, set):Float;
|
|
||||||
public var bottomPadding(default, set):Float;
|
|
||||||
public var paddings(null, set):Float;
|
|
||||||
|
|
||||||
public function addView(view:IView<Dynamic>):IView<Dynamic>;
|
public function addView(view:IView<Dynamic>):IView<Dynamic>;
|
||||||
public function addViewFirst(view:IView<Dynamic>):IView<Dynamic>;
|
public function addViewFirst(view:IView<Dynamic>):IView<Dynamic>;
|
||||||
public function insertView(view:IView<Dynamic>, index:Int):IView<Dynamic>;
|
public function insertView(view:IView<Dynamic>, index:Int):IView<Dynamic>;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package haxework.gui;
|
|||||||
import haxework.gui.IView.Content;
|
import haxework.gui.IView.Content;
|
||||||
import flash.text.TextFormatAlign;
|
import flash.text.TextFormatAlign;
|
||||||
|
|
||||||
interface ITextView<C:Content, T> extends IView<C> {
|
interface ITextView<C:Content, T> extends IView<C> extends HasPaddings {
|
||||||
public var textField(default, null):T;
|
public var textField(default, null):T;
|
||||||
public var text(get, set):String;
|
public var text(get, set):String;
|
||||||
public var align(default, set):TextFormatAlign;
|
public var align(default, set):TextFormatAlign;
|
||||||
|
|||||||
@@ -27,7 +27,12 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
|||||||
public var layoutHAlign(default, set):HAlign;
|
public var layoutHAlign(default, set):HAlign;
|
||||||
public var layoutVAlign(default, set):VAlign;
|
public var layoutVAlign(default, set):VAlign;
|
||||||
public var fill(default, set):Bool = true;
|
public var fill(default, set):Bool = true;
|
||||||
public var paddings(default, set):Float = 0.0;
|
|
||||||
|
public var leftPadding(default, set):Float = 0.0;
|
||||||
|
public var rightPadding(default, set):Float = 0.0;
|
||||||
|
public var topPadding(default, set):Float = 0.0;
|
||||||
|
public var bottomPadding(default, set):Float = 0.0;
|
||||||
|
public var paddings(null, set):Float = 0.0;
|
||||||
|
|
||||||
private var textFormat:TextFormat;
|
private var textFormat:TextFormat;
|
||||||
|
|
||||||
@@ -59,14 +64,6 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
|||||||
return new TextField();
|
return new TextField();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_paddings(value:Float):Float {
|
|
||||||
if (paddings != value) {
|
|
||||||
paddings = value;
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
return paddings;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_fill(value:Bool):Bool {
|
private function set_fill(value:Bool):Bool {
|
||||||
if (fill != value) {
|
if (fill != value) {
|
||||||
fill = value;
|
fill = value;
|
||||||
@@ -192,10 +189,10 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
|||||||
textField.height = h;
|
textField.height = h;
|
||||||
//textField.width = w;
|
//textField.width = w;
|
||||||
#end
|
#end
|
||||||
width = textField.width + paddings * 2;
|
width = textField.width + leftPadding + rightPadding;
|
||||||
height = textField.height + paddings * 2;
|
height = textField.height + topPadding + bottomPadding;
|
||||||
textField.x = paddings;
|
textField.x = leftPadding;
|
||||||
textField.y = paddings;
|
textField.y = topPadding;
|
||||||
} else {
|
} else {
|
||||||
placeTextField(textField);
|
placeTextField(textField);
|
||||||
}
|
}
|
||||||
@@ -223,16 +220,16 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
|||||||
//#if html5 textField.height = _textHeight; #end
|
//#if html5 textField.height = _textHeight; #end
|
||||||
textField.x = switch (layoutHAlign) {
|
textField.x = switch (layoutHAlign) {
|
||||||
case HAlign.NONE: 0;
|
case HAlign.NONE: 0;
|
||||||
case HAlign.LEFT: paddings;
|
case HAlign.LEFT: leftPadding;
|
||||||
case HAlign.CENTER: (width - textField.width) / 2;
|
case HAlign.CENTER: (width - textField.width) / 2 + leftPadding - rightPadding;
|
||||||
case HAlign.RIGHT: width - textField.width - paddings;
|
case HAlign.RIGHT: width - textField.width - rightPadding;
|
||||||
default: 0;
|
default: 0;
|
||||||
}
|
}
|
||||||
textField.y = switch (layoutVAlign) {
|
textField.y = switch (layoutVAlign) {
|
||||||
case VAlign.NONE: 0;
|
case VAlign.NONE: 0;
|
||||||
case VAlign.TOP: paddings;
|
case VAlign.TOP: topPadding;
|
||||||
case VAlign.MIDDLE: (height - _textHeight) / 2;
|
case VAlign.MIDDLE: (height - _textHeight) / 2 + topPadding - bottomPadding;
|
||||||
case VAlign.BOTTOM: height - _textHeight - paddings;
|
case VAlign.BOTTOM: height - _textHeight - bottomPadding;
|
||||||
default: 0;
|
default: 0;
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
@@ -242,4 +239,43 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
|||||||
textField.mouseEnabled = value;
|
textField.mouseEnabled = value;
|
||||||
return super.set_mouseEnabled(value);
|
return super.set_mouseEnabled(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function set_leftPadding(value:Float):Float {
|
||||||
|
if (leftPadding != value) {
|
||||||
|
leftPadding = value;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return leftPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_rightPadding(value:Float):Float {
|
||||||
|
if (rightPadding != value) {
|
||||||
|
rightPadding = value;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return rightPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_topPadding(value:Float):Float {
|
||||||
|
if (topPadding != value) {
|
||||||
|
topPadding = value;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return topPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_bottomPadding(value:Float):Float {
|
||||||
|
if (bottomPadding != value) {
|
||||||
|
bottomPadding = value;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return bottomPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_paddings(value:Float):Float {
|
||||||
|
leftPadding = rightPadding = topPadding = bottomPadding = value;
|
||||||
|
invalidate();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user