nodesnim/nodescontrol/control

The base of other Control nodes.

Types

ControlXYHandler = proc (self: ControlRef; x, y: float)
ControlHandler = proc (self: ControlRef)
ControlObj = object of CanvasObj
  hovered*: bool
  pressed*: bool
  focused*: bool
  mousemode*: MouseMode
  padding*: AnchorObj        ## Only for Box, VBox, HBox, GridBox and Label objects!
  margin*: AnchorObj         ## Only for HBox and VBox objects!
  background*: DrawableRef
  on_mouse_enter*: ControlXYHandler ## This called when the mouse enters the Control node.
  on_mouse_exit*: ControlXYHandler ## This called when the mouse exit from the Control node.
  on_click*: ControlXYHandler ## This called when the user clicks on the Control node.
  on_press*: ControlXYHandler ## This called when the user holds on the mouse on the Control node.
  on_release*: ControlXYHandler ## This called when the user no more holds on the mouse.
  on_focus*: ControlHandler  ## This called when the Control node gets focus.
  on_unfocus*: ControlHandler ## This called when the Control node loses focus.
  
ControlRef = ref ControlObj

Lets

control_handler = proc (self: ControlRef) = discard
control_xy_handler = proc (self: ControlRef; x, y: float) = discard

Procs

proc Control(name: string = "Control"): ControlRef {...}{.raises: [], tags: [].}

Creates a new Control.

Arguments:

  • name is a node name.

Example:

var ctrl = Control("Control")

Methods

method calcPositionAnchor(self: ControlRef) {...}{.raises: [], tags: [].}
Calculates node position. This uses in the scene.nim.
method draw(self: ControlRef; w, h: GLfloat) {...}{.raises: [GLerror, Exception],
    tags: [RootEffect].}
this method uses in the window.nim.
method duplicate(self: ControlRef): ControlRef {...}{.base, raises: [], tags: [].}
Duplicates Control object and create a new Control.
method getGlobalMousePosition(self: ControlRef): Vector2Obj {...}{.base, inline,
    raises: [], tags: [].}
Returns mouse position.
method handle(self: ControlRef; event: InputEvent; mouse_on: var NodeRef) {...}{.
    raises: [Exception], tags: [RootEffect].}
Handles user input. This uses in the window.nim.
method setBackground(self: ControlRef; drawable: DrawableRef) {...}{.base, inline,
    raises: [], tags: [].}

Changes background drawable.

Arguments:

  • drawable - can be DrawableRef or GradientDrawableRef.
method setBackgroundColor(self: ControlRef; color: ColorRef) {...}{.base, inline,
    raises: [], tags: [].}
Changes Control background color.
method setMargin(self: ControlRef; margin: AnchorObj) {...}{.base, inline,
    raises: [], tags: [].}

Changes Control margin.

See also:

method setMargin(self: ControlRef; x1, y1, x2, y2: float) {...}{.base, inline,
    raises: [], tags: [].}

Changes Control margin.

Arguments:

  • x1 - left margin.
  • y1 - top margin.
  • x2 - right margin.
  • y2 - bottom margin.

See also:

method setPadding(self: ControlRef; padding: AnchorObj) {...}{.base, inline,
    raises: [], tags: [].}

Changes Control padding.

See also:

method setPadding(self: ControlRef; x1, y1, x2, y2: float) {...}{.base, inline,
    raises: [], tags: [].}

Changes Control padding.

Arguments:

  • x1 - left padding.
  • y1 - top padding.
  • x2 - right padding.
  • y2 - bottom padding.

See also:

method setStyle(self: ControlRef; style: StyleSheetRef) {...}{.base,
    raises: [ValueError, RegexError, ResourceError, GLerror], tags: [].}

Changes control node style.

Styles:

  • size-anchor - 1, 1.0, 0.5 1
  • position-anchor - 1, 0.5 1 0.5 1
  • margin - 8, 2 4 6 8
  • padding - 8, 2 4 6 8