From a1f59a60d6aaf58371d2063bc50e4816dfbe9bcb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 13 Apr 2019 09:59:23 +0200 Subject: [PATCH] examples/options: Add a double text widget --- examples/menus/options/init.lua | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/menus/options/init.lua b/examples/menus/options/init.lua index 6cf003b..c5e3940 100644 --- a/examples/menus/options/init.lua +++ b/examples/menus/options/init.lua @@ -27,7 +27,9 @@ local OptionsMenu = Scene:extend() local ListBox = require "gamecore.modules.menusystem.listbox" local Widget = require "gamecore.modules.menusystem.widgets" -local SubMenuWidget = Widget.Text:extend() +local DoubleTextWidget = Widget.Text:extend() + +local SubMenuWidget = DoubleTextWidget:extend() local SceneWidget = Widget.Text:extend() local ExitWidget = Widget.Text:extend() @@ -62,7 +64,7 @@ end function OptionsMenu:addSubMenu(name, fullname) self:addMenu(name) SubMenuWidget(self, "main", name, fullname) - SubMenuWidget(self, name, "main", "< Back", 1) + SubMenuWidget(self, name, "main", "Back", 1, "<") end function OptionsMenu:addScene(submenu, scene, fullname) @@ -77,14 +79,30 @@ end -- WIDGETS -- Widgets used by menus +-- DoubleText widget : a two-side text widget + +function DoubleTextWidget:new(menu, font, label1, label2) + DoubleTextWidget.super.new(self, menu, font, label1) + self.label2 = label2 or "" +end + +function DoubleTextWidget:drawCanvas() + local w, h + w = math.floor(self.width) + h = math.floor(self.height / 2) - (self.font:getHeight() / 2) + self.font:draw(self.label, 4, h, -1, "left") + self.font:draw(self.label2, w-4, h, -1, "right") +end + -- Submenu widget :: go to a submenu -function SubMenuWidget:new(scene, menu, newmenu, fullname, order) +function SubMenuWidget:new(scene, menu, newmenu, fullname, order, label2) self.scene = scene local widgetmenu = self.scene.menusystem.menus[menu] local font = self.scene.assets.fonts["medium"] + local label2 = label2 or ">" self.newmenu = newmenu - SubMenuWidget.super.new(self, widgetmenu, font, fullname) + SubMenuWidget.super.new(self, widgetmenu, font, fullname, label2) self.order = order or 0 end