|
@@ -23,8 +23,10 @@ type
|
|
|
hovered*: bool
|
|
|
pressed*: bool
|
|
|
focused*: bool
|
|
|
+ padding_used*: bool
|
|
|
|
|
|
mousemode*: MouseMode
|
|
|
+ padding*: AnchorObj
|
|
|
background*: DrawableRef
|
|
|
|
|
|
on_mouse_enter*: proc(self: ControlRef, x, y: float): void ## This called when the mouse enters the Control node.
|
|
@@ -32,8 +34,8 @@ type
|
|
|
on_click*: proc(self: ControlRef, x, y: float): void ## This called when the user clicks on the Control node.
|
|
|
on_press*: proc(self: ControlRef, x, y: float): void ## This called when the user holds on the mouse on the Control node.
|
|
|
on_release*: proc(self: ControlRef, x, y: float): void ## This called when the user no more holds on the mouse.
|
|
|
- on_focus*: proc(self: ControlRef): void ## This called when the Control node gets focus.
|
|
|
- on_unfocus*: proc(self: ControlRef): void ## This called when the Control node loses focus.
|
|
|
+ on_focus*: proc(self: ControlRef): void ## This called when the Control node gets focus.
|
|
|
+ on_unfocus*: proc(self: ControlRef): void ## This called when the Control node loses focus.
|
|
|
ControlRef* = ref ControlObj
|
|
|
|
|
|
|
|
@@ -41,15 +43,17 @@ template controlpattern*: untyped =
|
|
|
result.hovered = false
|
|
|
result.focused = false
|
|
|
result.pressed = false
|
|
|
+ result.padding_used = true
|
|
|
|
|
|
result.mousemode = MOUSEMODE_SEE
|
|
|
- result.background = Drawable()
|
|
|
result.rect_size = Vector2()
|
|
|
result.rect_min_size = Vector2()
|
|
|
result.position = Vector2()
|
|
|
result.global_position = Vector2()
|
|
|
- result.anchor = Anchor(0, 0, 0, 0)
|
|
|
result.size_anchor = Vector2()
|
|
|
+ result.anchor = Anchor(0, 0, 0, 0)
|
|
|
+ result.padding = Anchor(0, 0, 0, 0)
|
|
|
+ result.background = Drawable()
|
|
|
|
|
|
result.on_mouse_enter = proc(self: ControlRef, x, y: float) = discard
|
|
|
result.on_mouse_exit = proc(self: ControlRef, x, y: float) = discard
|
|
@@ -79,8 +83,8 @@ method calcPositionAnchor*(self: ControlRef) =
|
|
|
if self.size_anchor.y > 0.0:
|
|
|
self.rect_size.y = self.parent.CanvasRef.rect_size.y * self.size_anchor.y
|
|
|
if not self.anchor.isEmpty():
|
|
|
- self.position.x = self.parent.CanvasRef.rect_size.x*self.anchor.x1 - self.rect_size.x*self.anchor.x2
|
|
|
- self.position.y = self.parent.CanvasRef.rect_size.y*self.anchor.y1 - self.rect_size.y*self.anchor.y2
|
|
|
+ self.position.x = self.parent.CanvasRef.rect_size.x*self.anchor.x1 - (self.rect_size.x+self.padding.x1+self.padding.x2)*self.anchor.x2
|
|
|
+ self.position.y = self.parent.CanvasRef.rect_size.y*self.anchor.y1 - (self.rect_size.y+self.padding.y1+self.padding.y2)*self.anchor.y2
|
|
|
|
|
|
method draw*(self: ControlRef, w, h: GLfloat) =
|
|
|
## this method uses in the `window.nim`.
|
|
@@ -90,7 +94,9 @@ method draw*(self: ControlRef, w, h: GLfloat) =
|
|
|
x = -w/2 + self.global_position.x
|
|
|
y = h/2 - self.global_position.y
|
|
|
|
|
|
- self.background.draw(x, y, self.rect_size.x, self.rect_size.y)
|
|
|
+ self.background.draw(
|
|
|
+ x, y, self.rect_size.x + self.padding.x1 + self.padding.x2,
|
|
|
+ self.rect_size.y + self.padding.y1 + self.padding.y2)
|
|
|
|
|
|
# Press
|
|
|
if self.pressed:
|
|
@@ -145,6 +151,14 @@ method setBackgroundColor*(self: ControlRef, color: ColorRef) {.base.} =
|
|
|
## Changes Control background color.
|
|
|
self.background.setColor(color)
|
|
|
|
|
|
+method setPadding*(self: ControlRef, padding: AnchorObj) {.base.} =
|
|
|
+ ## Changes Control padding.
|
|
|
+ self.padding = padding
|
|
|
+
|
|
|
+method setPadding*(self: ControlRef, x1, y1, x2, y2: float) {.base.} =
|
|
|
+ ## Changes Control padding.
|
|
|
+ self.setPadding(Anchor(x1, y1, x2, y2))
|
|
|
+
|
|
|
method setStyle*(self: ControlRef, style: StyleSheetRef) {.base.} =
|
|
|
self.background.setStyle(style)
|
|
|
for i in style.dict:
|
|
@@ -169,5 +183,17 @@ method setStyle*(self: ControlRef, style: StyleSheetRef) {.base.} =
|
|
|
parseFloat(tmp[0]), parseFloat(tmp[1]),
|
|
|
parseFloat(tmp[2]), parseFloat(tmp[3]))
|
|
|
)
|
|
|
+ # padding: 1
|
|
|
+ # padding: 0.5 1 0.5 1
|
|
|
+ of "padding":
|
|
|
+ let tmp = i.value.split(Whitespace)
|
|
|
+ if tmp.len() == 1:
|
|
|
+ let tmp2 = parseFloat(tmp[0])
|
|
|
+ self.setPadding(Anchor(tmp2, tmp2, tmp2, tmp2))
|
|
|
+ elif tmp.len() == 4:
|
|
|
+ self.setPadding(Anchor(
|
|
|
+ parseFloat(tmp[0]), parseFloat(tmp[1]),
|
|
|
+ parseFloat(tmp[2]), parseFloat(tmp[3]))
|
|
|
+ )
|
|
|
else:
|
|
|
discard
|