Skip to content

Commit

Permalink
Traktor: Some cleanup in UiKit.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 27, 2024
1 parent 31d03de commit 430678c
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 89 deletions.
7 changes: 4 additions & 3 deletions data/Source/System/UiKit/Scripts/Border.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Border:setStyle("resource", "MC_Border")
Border:setStyle("background", Color4f(0.8, 0.8, 0.8, 1.0))
function Border:new(parent)
local mc = Widget._createResource(parent, self:getStyle().resource)
local mc < const > = Widget._createResource(parent, self:getStyle().resource)
self:_initialize(parent, mc)
end
Expand All @@ -21,7 +21,7 @@ end
function Border:place(x, y, width, height)
Widget.place(self, x, y, width, height)
local p = self:getPlacement()
local p < const > = self:getPlacement()
self._mc.size = Vector2(p.width, p.height)
end
Expand All @@ -45,9 +45,10 @@ function Border:_initialize(parent, mc)
end
function Border:_loadStyle()
local style = self:getStyle()
local style < const > = self:getStyle()
self:setColor(style.background)
end
]]>
</text>
</object>
9 changes: 5 additions & 4 deletions data/Source/System/UiKit/Scripts/Button.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Button = Button or class("Button", Widget)
function Button:new(parent, imageUp, imageDown, imageHover)
local mc = Widget._createEmptyResource(parent)
local mc < const > = Widget._createEmptyResource(parent)
self:_initialize(parent, mc, imageUp, imageDown, imageHover)
end
Expand Down Expand Up @@ -38,7 +38,7 @@ function Button:_initialize(parent, mc, imageUp, imageDown, imageHover)
Widget._initialize(self, parent, mc)
if isa(imageUp, traktor.drawing.Image) then
local bm = self._mc.context:createBitmap(imageUp)
local bm < const > = self._mc.context:createBitmap(imageUp)
if bm == nil then return false end
self._imageUp_mc = Widget._createEmptyResource(self)
self._imageUp_mc:attachBitmap(bm, 0)
Expand All @@ -59,7 +59,7 @@ function Button:_initialize(parent, mc, imageUp, imageDown, imageHover)
if imageDown ~= nil then
if isa(imageDown, traktor.drawing.Image) then
local bm = self._mc.context:createBitmap(imageDown)
local bm < const > = self._mc.context:createBitmap(imageDown)
if bm == nil then return false end
self._imageDown_mc = Widget._createEmptyResource(self)
self._imageDown_mc:attachBitmap(bm, 0)
Expand All @@ -83,7 +83,7 @@ function Button:_initialize(parent, mc, imageUp, imageDown, imageHover)
if imageHover ~= nil then
if isa(imageHover, traktor.drawing.Image) then
local bm = self._mc.context:createBitmap(imageHover)
local bm < const > = self._mc.context:createBitmap(imageHover)
if bm == nil then return false end
self._imageHover_mc = Widget._createEmptyResource(self)
self._imageHover_mc:attachBitmap(bm, 0)
Expand Down Expand Up @@ -173,6 +173,7 @@ function Button:_onMouseLeave()
self._isRolledOver = false
return true
end
]]>
</text>
</object>
5 changes: 3 additions & 2 deletions data/Source/System/UiKit/Scripts/Carousel.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ end
function Carousel:_layout()
local p < const > = self:getPlacement()
local children < const > = self:getChildren(function (c) return c.__layout ~= ILayout.FLOAT end)
local x = 0
local children = self:getChildren(function (c) return c.__layout ~= ILayout.FLOAT end)
for _, child in ipairs(children) do
child:place(x, 0, p.width, p.height)
x = x + p.width + self._pad
Expand All @@ -83,12 +83,13 @@ function Carousel:_show(index)
local sx < const > = -self._current * (p.width + self._pad)
local ex < const > = -index * (p.width + self._pad)
Tween(0, 1, 1, function(value, last)
local f = Ease.outElastic(value)
local f < const > = Ease.outElastic(value)
local x < const > = sx * (1 - f) + ex * f
self._inner_mc.X = x
end)
self._current = index
end
]]>
</text>
</object>
4 changes: 2 additions & 2 deletions data/Source/System/UiKit/Scripts/CheckBox.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CheckBox:setStyle("resource", "MC_CheckBox")
CheckBox:setStyle("background", traktor.Color4f(0.8, 0.8, 0.8, 1.0))
function CheckBox:new(parent)
local mc = Widget._createResource(parent, self:getStyle().resource)
local mc < const > = Widget._createResource(parent, self:getStyle().resource)
self:_initialize(parent, mc)
end
Expand Down Expand Up @@ -71,7 +71,7 @@ function CheckBox:_initialize(parent, mc)
end
function CheckBox:_loadStyle()
local style = self:getStyle()
local style < const > = self:getStyle()
self:setColor(style.background)
end
Expand Down
17 changes: 9 additions & 8 deletions data/Source/System/UiKit/Scripts/Container.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Container = Container or class("Container", Widget)
function Container:new(parent, layout)
local mc = Widget._createEmptyResource(parent)
local mc < const > = Widget._createEmptyResource(parent)
self:_initialize(parent, mc, layout)
end
Expand All @@ -19,25 +19,25 @@ function Container:getPreferredSize()
end
if self._layout ~= nil then
local w, h = self._layout:estimate(self)
local e = { width = w, height = h }
local w, h < const > = self._layout:estimate(self)
local e < const > = { width = w, height = h }
self._cachedEstimate = e
return e
else
local w, h = 0, 0
for _, child in ipairs(self._children) do
local ps = child:getPreferredSize()
local ps < const > = child:getPreferredSize()
w = math.max(w, ps.width)
h = math.max(h, ps.height)
end
local e = { width = w, height = h }
local e < const > = { width = w, height = h }
self._cachedEstimate = e
return e
end
end
function Container:place(x, y, width, height)
local last = self:getPlacement()
local last < const > = self:getPlacement()
Widget.place(self, x, y, width, height)
Expand All @@ -46,14 +46,14 @@ function Container:place(x, y, width, height)
end
if self:isVisible(false) and self._layout ~= nil then
local p = self:getPlacement()
local p < const > = self:getPlacement()
self._layout:update(self, p.width, p.height)
end
end
function Container:layout()
if self:isVisible(false) and self._layout ~= nil then
local p = self:getPlacement()
local p < const > = self:getPlacement()
self._layout:update(self, p.width, p.height)
end
end
Expand Down Expand Up @@ -83,6 +83,7 @@ function Container:_removeChild(child)
Widget._removeChild(self, child)
self._cachedEstimate = nil
end
]]>
</text>
</object>
15 changes: 8 additions & 7 deletions data/Source/System/UiKit/Scripts/Dialog.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ Dialog:setStyle("background", traktor.Color4f(0.6, 0.6, 0.6, 1.0))
Dialog:setStyle("border", traktor.Color4f(1.0, 1.0, 1.0, 1.0))
function Dialog:new(parent, layout)
local mc = Widget._createResource(parent, self:getStyle().resource, true)
local mc < const > = Widget._createResource(parent, self:getStyle().resource, true)
self:_initialize(parent, mc, layout)
end
function Dialog:place(x, y, width, height)
Container.place(self, x, y, width, height)
local p = self:getPlacement()
local p < const > = self:getPlacement()
self._background_mc.width = p.width
self._background_mc.height = p.height
self._border_mc.width = p.width
self._border_mc.height = p.height
local p = self:getAncestor():getPlacement()
local tl = self:globalToLocal({ x = 0, y = 0 })
local p < const > = self:getAncestor():getPlacement()
local tl < const > = self:globalToLocal({ x = 0, y = 0 })
self._shadow_mc.X = tl.x
self._shadow_mc.Y = tl.y
Expand Down Expand Up @@ -84,20 +84,21 @@ function Dialog:_initialize(parent, mc, layout)
end
function Dialog:_updatePlacement()
local ps = self:getPreferredSize()
local p = self:getAncestor():getPlacement()
local ps < const > = self:getPreferredSize()
local p < const > = self:getAncestor():getPlacement()
self:place((p.width - ps.width) / 2, (p.height - ps.height) / 2, ps.width, ps.height)
end
function Dialog:_loadStyle()
local style = self:getStyle()
local style < const > = self:getStyle()
self:setColor(style.background)
self:setBorderColor(style.border)
end
function Dialog:_getInnerClip()
return self._inner_mc
end
]]>
</text>
</object>
41 changes: 21 additions & 20 deletions data/Source/System/UiKit/Scripts/DropDown.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DropDown:setStyle("textListSize", 17)
DropDown:setStyle("fadeDuration", 0.1)
function DropDown:new(parent, items)
local mc = Widget._createResource(parent, self:getStyle().resource)
local mc < const > = Widget._createResource(parent, self:getStyle().resource)
self:_initialize(parent, mc, items)
end
Expand All @@ -45,7 +45,7 @@ end
function DropDown:select(indexOrPredicate)
if type(indexOrPredicate) ~= "function" then
local index = indexOrPredicate
local index < const > = indexOrPredicate
if index > 0 and index <= #self._items then
self._caption_tb:parseText(self:_getTextOfItem(self._items[index]))
self._selected = index
Expand All @@ -54,7 +54,7 @@ function DropDown:select(indexOrPredicate)
self._selected = 0
end
else
local fn = indexOrPredicate
local fn < const > = indexOrPredicate
local found = false
for index, item in ipairs(self._items) do
if fn(item) then
Expand All @@ -69,10 +69,10 @@ function DropDown:select(indexOrPredicate)
end
end
local p = self:getPlacement()
local sz = self._caption_tb.textSize
local mx = p.width - sz.x
local my = p.height - sz.y
local p < const > = self:getPlacement()
local sz < const > = self._caption_tb.textSize
local mx < const > = p.width - sz.x
local my < const > = p.height - sz.y
self._caption_tb.X = mx / 2
self._caption_tb.Y = my / 2
Expand Down Expand Up @@ -114,7 +114,7 @@ function DropDown:setTextColor(textColor)
end
function DropDown:setTextSize(size)
local tf = self._caption_tb:getTextFormat()
local tf < const > = self._caption_tb:getTextFormat()
tf.size = size * 20
self._caption_tb:setTextFormat(tf)
self._preferredSize.height = size + self._textSizeMargin
Expand Down Expand Up @@ -149,16 +149,16 @@ end
function DropDown:place(x, y, width, height)
Widget.place(self, x, y, width, height)
local p = self:getPlacement()
local p < const > = self:getPlacement()
self._background_mc.width = p.width
self._background_mc.height = p.height
self._arrow_mc.X = p.width - self._arrow_mc.width
self._arrow_mc.Y = (p.height - self._arrow_mc.height) / 2
local sz = self._caption_tb.textSize
local mx = p.width - sz.x
local my = p.height - sz.y
local sz < const > = self._caption_tb.textSize
local mx < const > = p.width - sz.x
local my < const > = p.height - sz.y
self._caption_tb.X = mx / 2
self._caption_tb.Y = my / 2
end
Expand Down Expand Up @@ -199,7 +199,7 @@ function DropDown:_initialize(parent, mc, items)
end
function DropDown:_loadStyle()
local style = self:getStyle()
local style < const > = self:getStyle()
self:setColor(style.background)
self:setListColor(style.list)
self:setTextColor(style.text)
Expand Down Expand Up @@ -238,7 +238,7 @@ function DropDown:_onMousePress()
self._background_mc:gotoAndStop("active")
self._arrow_mc:gotoAndStop("active")
local ancestor = self:getAncestor()
local ancestor < const > = self:getAncestor()
self._list = ListBox(ancestor, 4, 4, 20, self:getStyle().resourceListBox)
self._list.__layout = ILayout.FLOAT
Expand All @@ -252,14 +252,14 @@ function DropDown:_onMousePress()
self._list:add(self:_getTextOfItem(item))
end
local p = self:getPlacement()
local ps = self._list:getPreferredSize()
local itemHeight = self._textSize + 5
local p < const > = self:getPlacement()
local ps < const > = self._list:getPreferredSize()
local itemHeight < const > = self._textSize + 5
-- Transform local coordinate into ancestor frame as
-- list box is temporarily added as child to ancestor in
-- order to be top most.
local pp = self:localToGlobal({ x = 0, y = p.height})
local pp < const > = self:localToGlobal({ x = 0, y = p.height})
self._list:place(
pp.x,
Expand All @@ -273,7 +273,7 @@ function DropDown:_onMousePress()
self._list:setModal()
-- Fade in list.
local duration = self:getStyle().fadeDuration
local duration < const > = self:getStyle().fadeDuration
if duration > 0 then
self._tween = Tween(
0,
Expand All @@ -297,7 +297,7 @@ function DropDown:_onListClick(index)
end
function DropDown:_onListMouseDown(event)
local mp = self._list:getMousePosition()
local mp < const > = self._list:getMousePosition()
if self._list:hitTest(mp) == nil then
self:_removeList()
if self._cancelFn ~= nil then
Expand All @@ -306,6 +306,7 @@ function DropDown:_onListMouseDown(event)
end
return true
end
]]>
</text>
</object>
5 changes: 3 additions & 2 deletions data/Source/System/UiKit/Scripts/Ease.xdi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end
function Ease.inOutCubic(f)
if f < 0.5 then return 4 * f * f * f end
local p = 2 * f - 2
local p < const > = 2 * f - 2
return 0.5 * p * p * p + 1
end
Expand All @@ -65,7 +65,7 @@ end
function Ease.inOutQuart(f)
if f < 0.5 then return 8 * f * f * f * f end
local p = f - 1
local p < const > = f - 1
return -8 * p * p * p * p + 1
end
Expand Down Expand Up @@ -159,6 +159,7 @@ end
function Ease.inOutBounce(f)
end
]]>
</text>
</object>
Loading

0 comments on commit 430678c

Please sign in to comment.