From fa5ec3f0804cb0df3c2c31fdf69d4cf176f57402 Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 19 Nov 2017 05:19:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20"=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B7=D1=80=D0=B0=D1=87=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=B2=D0=B5=D0=BD=D1=82=D0=BE=D0=B2"=20=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=B1=D0=B0=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications/Control/Main.lua | 10 +----- Applications/Control/Modules/1.lua | 3 -- Applications/Control/Modules/2.lua | 3 -- Applications/Control/Modules/3.lua | 3 -- Applications/Control/Modules/4.lua | 3 -- lib/GUI.lua | 49 ++++++++++++++++-------------- 6 files changed, 28 insertions(+), 43 deletions(-) diff --git a/Applications/Control/Main.lua b/Applications/Control/Main.lua index 2524780f..3da0924f 100644 --- a/Applications/Control/Main.lua +++ b/Applications/Control/Main.lua @@ -49,7 +49,7 @@ window.onResize = function(width, height) window.contentContainer.width = width window.contentContainer.height = window.backgroundPanel.height - window.tabBar.children[window.tabBar.selectedItem].onTouch() + window.tabBar:getItem(window.tabBar.selectedItem).onTouch() end ---------------------------------------------------------------------------------------------------------------- @@ -57,12 +57,4 @@ end loadModules() window.onResize(80, 25) -mainContainer:draw() -buffer.draw() - - - - - - diff --git a/Applications/Control/Modules/1.lua b/Applications/Control/Modules/1.lua index b7f412f5..f986f3a0 100644 --- a/Applications/Control/Modules/1.lua +++ b/Applications/Control/Modules/1.lua @@ -180,9 +180,6 @@ module.onTouch = function() input.text = "" end end - - mainContainer:draw() - buffer.draw() end ---------------------------------------------------------------------------------------------------------------- diff --git a/Applications/Control/Modules/2.lua b/Applications/Control/Modules/2.lua index b985add3..e767408e 100644 --- a/Applications/Control/Modules/2.lua +++ b/Applications/Control/Modules/2.lua @@ -100,9 +100,6 @@ module.onTouch = function() module.onTouch() end end - - mainContainer:draw() - buffer.draw() end ---------------------------------------------------------------------------------------------------------------- diff --git a/Applications/Control/Modules/3.lua b/Applications/Control/Modules/3.lua index 441cc01a..89e8a290 100644 --- a/Applications/Control/Modules/3.lua +++ b/Applications/Control/Modules/3.lua @@ -139,9 +139,6 @@ module.onTouch = function() executeButton.colors.disabled.text = 0xD2D2D2 tree.onItemExpanded() - - mainContainer:draw() - buffer.draw() end ---------------------------------------------------------------------------------------------------------------- diff --git a/Applications/Control/Modules/4.lua b/Applications/Control/Modules/4.lua index 1a291e76..c0bd7ae9 100644 --- a/Applications/Control/Modules/4.lua +++ b/Applications/Control/Modules/4.lua @@ -43,9 +43,6 @@ module.onTouch = function() buffer.draw() end end - - mainContainer:draw() - buffer.draw() end ---------------------------------------------------------------------------------------------------------------- diff --git a/lib/GUI.lua b/lib/GUI.lua index a26e10b2..0af992fd 100755 --- a/lib/GUI.lua +++ b/lib/GUI.lua @@ -3390,56 +3390,62 @@ end local function tabBarDraw(tabBar) local totalWidth = 0 - for i = 1, #tabBar.children do + for i = 2, #tabBar.children do totalWidth = totalWidth + tabBar.children[i].width + tabBar.spaceBetweenTabs end local x = math.floor(tabBar.width / 2 - (totalWidth - tabBar.spaceBetweenTabs) / 2) - for i = 1, #tabBar.children do - tabBar.children[i].localX = x + for i = 2, #tabBar.children do tabBar.children[i].colors.default.background = tabBar.colors.default.background tabBar.children[i].colors.default.text = tabBar.colors.default.text tabBar.children[i].colors.pressed.background = tabBar.colors.selected.background tabBar.children[i].colors.pressed.text = tabBar.colors.selected.text - tabBar.children[i].pressed = i == tabBar.selectedItem + tabBar.children[i].localX = x x = x + tabBar.children[i].width + tabBar.spaceBetweenTabs end - buffer.square(tabBar.x, tabBar.y, tabBar.width, tabBar.height, tabBar.colors.default.background, tabBar.colors.default.text, " ") + tabBar.backgroundPanel.colors.background = tabBar.colors.default.background + tabBar.backgroundPanel.width, tabBar.backgroundPanel.height = tabBar.width, tabBar.height + GUI.drawContainerContent(tabBar) return tabBar end -local function tabBarTabEventHandler(mainContainer, object, eventData) +local function tabBarTabEventHandler(mainContainer, tabBarTab, eventData) if eventData[1] == "touch" then - object.parent.selectedItem = object:indexOf() + tabBarTab.parent.selectedItem = tabBarTab:indexOf() - 1 + for i = 2, #tabBarTab.parent.children do + tabBarTab.parent.children[i].pressed = tabBarTab.parent.selectedItem == i - 1 + end + + callMethod(tabBarTab.onTouch, mainContainer, tabBarTab, eventData) + mainContainer:draw() buffer.draw() - - callMethod(object.onTouch, mainContainer, object, eventData) end end local function tabBarAddItem(tabBar, text) local item = tabBar:addChild(GUI.button(1, 1, unicode.len(text) + tabBar.horizontalTabOffset * 2, tabBar.height, tabBar.colors.default.background, tabBar.colors.default.text, tabBar.colors.selected.background, tabBar.colors.selected.text, text)) - item.switchMode = true item.eventHandler = tabBarTabEventHandler + if #tabBar.children - 1 == tabBar.selectedItem then + item.pressed = true + end + return item end local function tabBarGetItem(tabBar, index) - return tabBar.children[index] + return tabBar.children[index + 1] end function GUI.tabBar(x, y, width, height, horizontalTabOffset, spaceBetweenTabs, backgroundColor, textColor, backgroundSelectedColor, textSelectedColor, ...) local tabBar = GUI.container(x, y, width, height) - tabBar.horizontalTabOffset = horizontalTabOffset - tabBar.spaceBetweenTabs = spaceBetweenTabs tabBar.colors = { default = { background = backgroundColor, @@ -3450,33 +3456,32 @@ function GUI.tabBar(x, y, width, height, horizontalTabOffset, spaceBetweenTabs, text = textSelectedColor } } + + tabBar.horizontalTabOffset = horizontalTabOffset + tabBar.spaceBetweenTabs = spaceBetweenTabs tabBar.selectedItem = 1 - tabBar.draw = tabBarDraw + tabBar.backgroundPanel = tabBar:addChild(GUI.panel(1, 1, 1, 1, backgroundColor)) + tabBar.addItem = tabBarAddItem tabBar.getItem = tabBarGetItem - - local items = {...} - for i = 1, #items do - tabBar:addItem(items[i]) - end + tabBar.draw = tabBarDraw return tabBar end ----------------------------------------------------------------------------------------------------- - -- buffer.clear() -- buffer.draw(true) -- local mainContainer = GUI.fullScreenContainer() -- mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x262626)) --- local tabBar = mainContainer:addChild(GUI.tabBar(3, 2, 80, 3, 4, 0, 0xE1E1E1, 0x2D2D2D, 0xC3C3C3, 0x2D2D2D)) +-- local tabBar = mainContainer:addChild(GUI.tabBar(3, 2, 80, 3, 3, 0, 0xE1E1E1, 0x2D2D2D, 0xC3C3C3, 0x2D2D2D)) -- tabBar:addItem("Вкладка 1") -- tabBar:addItem("Вкладка 2") -- tabBar:addItem("Вкладка 3").onTouch = function() --- -- Do something +-- GUI.error("aefae") -- end -- mainContainer:draw()