Skip to content

Commit 9f744c4

Browse files
committed
Ability for a control to notify the parent (see changeLog: November 19 - 2023).
1 parent 59027e8 commit 9f744c4

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

Controls/Content.moon

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ drawRect = =>
1010
r, g, b, a = Graphics.getColor!
1111
boxW, boxH = box\getWidth!, box\getHeight!
1212
x, y = box\getX!, box\getY!
13-
color = @backgroundColor
13+
local color
14+
15+
if @focuseResponsive and @isFocused! == false
16+
color = @backgroundColorUnFocus
17+
else
18+
color = @backgroundColor
19+
1420
color[4] = color[4] or @alpha
1521

1622
Graphics.setColor color
@@ -42,14 +48,18 @@ class Slide extends Control
4248
@on "UI_MOUSE_DOWN", parent.onMouseDown, parent
4349
@on "UI_MOUSE_UP", parent.onMouseUp, parent
4450
@on "UI_UPDATE", parent.onUpdate, parent
51+
@on "UI_UN_FOCUS", @onUnFocus, @
52+
4553
else
4654
@on "UI_MOUSE_DOWN", @.onMouseDown, @
4755
@on "UI_MOUSE_UP", @.onMouseUp, @
4856
@on "UI_UPDATE", @.onUpdate, @
57+
@on "UI_UN_FOCUS", @onUnFocus, @
58+
@on "UI_FOCUS", @onFocus, @
4959

5060
getExtend: =>
5161
@extend
52-
62+
5363
class Content extends Control
5464

5565
@include Mixins.ThemeMixins
@@ -70,7 +80,7 @@ class Content extends Control
7080
-- @local
7181
h_barSide = "bottom"
7282

73-
new: (label, vbar, hbar) =>
83+
new: (label, vbar, hbar, attachSlides) =>
7484
-- Bounding box type
7585
super "Box", "Content"
7686

@@ -81,7 +91,10 @@ class Content extends Control
8191
colors = t.colors
8292
common = t.common
8393
@stroke = common.stroke
84-
@backgroundColor = colors.contentBackgroundColor
94+
@backgroundColor = t.content.backgroundColorFocuse
95+
@backgroundColorUnFocus = t.content.backgroundColorUnFocuse
96+
@focuseResponsive = false
97+
8598
@strokeColor = colors.strokeColor
8699

87100
@setClip true
@@ -93,7 +106,6 @@ class Content extends Control
93106

94107
@alpha = 1
95108

96-
@onDraw = drawRect
97109
style = t.content
98110
@width = style.width
99111
@height = style.height
@@ -110,9 +122,12 @@ class Content extends Control
110122

111123
@on "UI_DRAW", @onDraw, @
112124
@on "UI_MOUSE_DOWN", @onMouseDown, @
125+
@on "UI_UN_FOCUS", @onUnFocus, @
126+
@on "UI_FOCUS", @onFocus, @
113127
@on "UI_UPDATE", @onUpdate, @
114-
115-
@addSlide true, true
128+
if attachSlides
129+
@addSlide true, true
130+
@onDraw = drawRect -- FIX
116131
@on "UI_WHELL_MOVE", @onWheelMove, @
117132

118133
if vbar then @attachScrollBarV "Box"
@@ -122,6 +137,7 @@ class Content extends Control
122137
slideIdx = @slidesIdx
123138
@slides[@slidesIdx] = Slide "Box", @slidesIdx, @, extend
124139
@slides[@slidesIdx].autoSize = true
140+
125141
if @getLabel!
126142
@slides[@slidesIdx]\setLabel @getLabel!
127143

@@ -358,4 +374,4 @@ class Content extends Control
358374

359375
@slides = nil
360376

361-
root\removeChild @getId!
377+
root\removeChild @getId!

Controls/TextInput.moon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class TextInput extends Control
2020
new: (placeHolder) =>
2121
super "Box", "TextInput"
2222

23-
-- TODO: should be a mixin
2423
t = @getTheme!
2524
common = t.common
2625
style = t.textField

Controls/mx/init.moon

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ EventMixins = class
129129

130130
while parent.getDragParent and parent\getDragParent!
131131
parent = parent\getParent!
132-
132+
133133
if parent.getExtend
134134
if parent\getExtend!
135135
@offsetX = x - parent\getParent!\getBoundingBox!\getX!
@@ -146,6 +146,20 @@ EventMixins = class
146146

147147
onUpdate: (dt) =>
148148

149+
whenFocused: (cb) =>
150+
@Focused = cb
151+
152+
whenUnFocused: (cb) =>
153+
@UnFocused = cb
154+
155+
onFocus: =>
156+
if @Focused
157+
@Focused!
158+
159+
onUnFocus: =>
160+
if @UnFocused
161+
@UnFocused!
162+
149163
KeyboardMixins = class
150164
isCtrlDown: =>
151165
if love._os == "OS X"

Controls/themes/blues.moon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Default =
1414
disabledColor: { 0.0980392156863, 0.101960784314, 0.0980392156863 }
1515
strokeColor: { 0.471, 0.471, 0.439}
1616
fontColor: { 1, 1, 1 }
17-
contentBackgroundColor: {0.082, 0.086, 0.09}
1817
scrollBar: { 0.14, 0.14, 0.14 }
1918

2019
common:
@@ -60,6 +59,8 @@ Default =
6059
radius: ww/4
6160
rx: 1
6261
ry: 1
62+
backgroundColorFocuse: {0.082, 0.086, 0.09}
63+
backgroundColorUnFocuse: {0.808, 0.804, 0.859}
6364

6465
circleButton:
6566
radius: 30

0 commit comments

Comments
 (0)