Skip to content

Commit

Permalink
Frame onClick.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tourahi committed Dec 3, 2023
1 parent 36c498a commit 9ad65ca
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
12 changes: 7 additions & 5 deletions Controls/Button.moon
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ circleBorder = (box) =>
if @enabled and @stroke > 0
oldLineWidth = Graphics.getLineWidth!
Graphics.setLineWidth @stroke
Graphics.setLineStyle @borderLineStyle
Graphics.setColor @strokeColor
Graphics.circle "line", box.x, box.y, box\getRadius!
Graphics.setLineWidth oldLineWidth
Expand All @@ -33,7 +32,6 @@ polyBorder = (box) =>
if @enabled and @stroke > 0
oldLineWidth = Graphics.getLineWidth!
Graphics.setLineWidth @stroke
Graphics.setLineStyle @borderLineStyle
Graphics.setColor @strokeColor
Graphics.polygon "line", box\getVertices!
Graphics.setLineWidth oldLineWidth
Expand Down Expand Up @@ -64,6 +62,7 @@ drawPoly = =>
r, g, b, a = Graphics.getColor!
color = currentColor self

Graphics.setLineStyle @borderLineStyle
-- Button body
if @bgImage
if not @isPressed
Expand Down Expand Up @@ -95,8 +94,8 @@ drawPoly = =>
if @textDrawable
Graphics.setColor @fontColor
textW, textH = @textDrawable\getWidth!, @textDrawable\getHeight!
x = box.x - textW / 2
y = box.y - textH / 2
x = math.ceil(box.x - textW / 2)
y = math.ceil(box.y - textH / 2)
Graphics.draw @textDrawable, x, y

Graphics.setColor r, g, b, a
Expand All @@ -109,6 +108,8 @@ drawCircle = =>
boxR = box\getRadius!
color = currentColor self

Graphics.setLineStyle @borderLineStyle

-- Button body
if @bgImage
if not @isPressed
Expand Down Expand Up @@ -153,6 +154,8 @@ drawRect = =>
boxW, boxH = box\getWidth!, box\getHeight!
color = currentColor self

Graphics.setLineStyle @borderLineStyle

-- Button body
if @bgImage
imageW, imageH = @bgImage\getWidth!, @bgImage\getHeight!
Expand All @@ -176,7 +179,6 @@ drawRect = =>
if @enabled and @stroke > 0
oldLineWidth = Graphics.getLineWidth!
Graphics.setLineWidth @stroke
Graphics.setLineStyle @borderLineStyle
Graphics.setColor @strokeColor
Graphics.rectangle "line", box.x, box.y, boxW, boxH, @rx, @ry
Graphics.setLineWidth oldLineWidth
Expand Down
15 changes: 8 additions & 7 deletions Controls/Frame.moon
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Frame extends Content
@toolBarColor = t.frame.toolBarColor
@toolBarColorUnfocused = t.frame.toolBarColorUnfocused
@backgroundColor = t.frame.contentBackground
@toolBarTitleColor = t.frame.toolBarTitleColor

@closeBtn = Button "Box"

Expand All @@ -54,25 +53,20 @@ class Frame extends Content
@on "UI_DRAW", @onDraw, @
@on "UI_FOCUS", @onFocus, @
@on "UI_UN_FOCUS", @onUnFocus, @
@on "UI_CLICK", @onClick, @
@on "UI_MOUSE_DOWN", @onMouseDown, @
@on "UI_ON_ADD", @onAdd, @

@addChild @closeBtn
@setDrag true
@setMakeTopWhenClicked true

@setToolBarTitle label, math.ceil(@toolBarHeight/2)

onDraw: =>
drawToolBar @

box = @getBoundingBox!
r, g, b, a = Graphics.getColor!
boxW, boxH = box\getWidth!, box\getHeight!

Graphics.setColor @toolBarTitleColor
Graphics.draw @toolBarTitle, box.x + @titleOffSet, box.y + @titleOffSet


Graphics.setColor @backgroundColor
Graphics.rectangle "fill", box.x, box.y + @toolBarHeight, boxW, boxH - @toolBarHeight, @rx, @ry
Expand Down Expand Up @@ -113,6 +107,11 @@ class Frame extends Content
manager\setFocus @
@onFocus!

<<<<<<< HEAD
onClick: =>
manager\setFocus @
@onFocus!

setToolBarTitle: (text = @text, size, font) =>
if size and font
if type(font) == "number" then @font = Graphics.newFont font
Expand All @@ -124,5 +123,7 @@ class Frame extends Content

@titleOffSet = math.floor ((@toolBarHeight-1) / 2) - (size/2)

=======
>>>>>>> parent of 36c498a (Frame toolbar title.)

Frame
Binary file added Controls/assets/Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion Controls/themes/blues.moon
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Default =
toolBarColor: {0.161, 0.29, 0.478}
toolBarColorUnfocused: {0.62, 0.62, 0.576}
contentBackground: {0.082, 0.086, 0.09}
toolBarTitleColor: {1, 1, 1}

button:
width: 100
Expand Down
2 changes: 1 addition & 1 deletion init.moon
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ keyboard.setKeyRepeat true
export MeowUI = {
debug: true
keyInput: true -- If you are using keyInput functions else disable it. (Some example controls will used it, so if you want to use them keep it as is).
version: "v0.0.0.116"
version: "v0.1"
stage: "alpha"
defTheme: "blues"
author: "Tourahi Amine"
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Control.moon
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class Control

if @childrenEnabled
for i = #@children, 1, -1
hitControl = @children[i]\hitTest x, y
control = @children[i]
hitControl = control\hitTest x, y
if hitControl then return hitControl

if @enabled
Expand Down Expand Up @@ -448,7 +449,6 @@ class Control
@children[i]\setParent nil
Tremove @children, i
child.events\dispatch child.events\getEvent "UI_ON_REMOVE"
child = nil
break

--- drops the control children.
Expand Down

0 comments on commit 9ad65ca

Please sign in to comment.