diff options
| author | ruki <[email protected]> | 2018-01-24 00:49:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-23 22:54:12 +0800 |
| commit | 08b707b41d5b0c98713812be50d03ea2b021385c (patch) | |
| tree | 173caa18ab365feea0fce53879c89e3ba71dea0a | |
| parent | b10e053feb5d657b9c76b50b5907480edf637163 (diff) | |
insert bool config to menuconf
| -rw-r--r-- | LICENSE.md | 2 | ||||
| -rw-r--r-- | xmake/core/ui/mconfdialog.lua | 3 | ||||
| -rw-r--r-- | xmake/core/ui/menuconf.lua | 52 | ||||
| -rw-r--r-- | xmake/core/ui/panel.lua | 19 | ||||
| -rw-r--r-- | xmake/core/ui/view.lua | 14 |
5 files changed, 83 insertions, 7 deletions
diff --git a/LICENSE.md b/LICENSE.md index 5c2338864..21ed6a4fe 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2016-2017 TBOOX Open Source Group + Copyright 2016-2018 TBOOX Open Source Group Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/xmake/core/ui/mconfdialog.lua b/xmake/core/ui/mconfdialog.lua index aa42c75c3..392836f8e 100644 --- a/xmake/core/ui/mconfdialog.lua +++ b/xmake/core/ui/mconfdialog.lua @@ -61,7 +61,8 @@ end -- get menu config function mconfdialog:menuconf() if not self._MENUCONF then - self._MENUCONF = menuconf:new("mconfdialog.menuconf", self:box():bounds()) + local bounds = self:box():panel():bounds() + self._MENUCONF = menuconf:new("mconfdialog.menuconf", rect:new(math.floor(bounds:width() / 3), 0, bounds:width(), bounds:height())) end return self._MENUCONF end diff --git a/xmake/core/ui/menuconf.lua b/xmake/core/ui/menuconf.lua index 132360e53..57f70f4d7 100644 --- a/xmake/core/ui/menuconf.lua +++ b/xmake/core/ui/menuconf.lua @@ -25,10 +25,11 @@ -- load modules local log = require("ui/log") local view = require("ui/view") -local label = require("ui/label") +local rect = require("ui/rect") local panel = require("ui/panel") local event = require("ui/event") local curses = require("ui/curses") +local button = require("ui/button") -- define module local menuconf = menuconf or panel() @@ -39,14 +40,55 @@ function menuconf:init(name, bounds) -- init panel panel.init(self, name, bounds) + self:insert({default = false, description = "bool config item"}) + self:insert({default = true, new = true, description = {"bool config item2", "more"}}) end --- draw menuconf -function menuconf:draw(transparent) +-- insert a config item +-- +-- description +-- - {description = "config item description"} +-- - {description = {"config item description", "line2", "line3", "more description ..."}} +-- +-- bool config +-- - {default = true/false, description = "bool config item", new = true/false} +-- +function menuconf:insert(config) + + -- init a config item view + local item = button:new("menuconf.config." .. self:count(), rect:new(0, self:count(), self:width(), 1), self:_text(config)) + + -- attach this config + item:extra_set("config", config) + + -- insert this config item + panel.insert(self, item) + + -- invalidate + self:invalidate() +end + +-- get text from the given config +function menuconf:_text(config) + + -- get text (first line in description) + local text = config.description or "" + if type(text) == "table" then + text = text[1] or "" + end + + -- update text + if type(config.default) == "boolean" then + text = (config.default and "[*] " or "[ ] ") .. text + end - -- draw background - panel.draw(self, transparent) + -- new config? + if config.new then + text = text .. " (NEW)" + end + -- ok + return text end -- return module diff --git a/xmake/core/ui/panel.lua b/xmake/core/ui/panel.lua index fac72a2ab..2cc092664 100644 --- a/xmake/core/ui/panel.lua +++ b/xmake/core/ui/panel.lua @@ -162,6 +162,25 @@ function panel:remove(v) self:invalidate() end +-- clear views +function panel:clear() + + -- clear parents + for v in self:views() do + v:parent_set(nil) + end + + -- clear views and cache + self._VIEWS:clear() + self._VIEWS_CACHE = {} + + -- reset the current view + self._CURRENT = nil + + -- invalidate + self:invalidate() +end + -- select the child view function panel:select(v) diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index 6e73d2336..b49e53d66 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -78,6 +78,9 @@ function view:init(name, bounds) -- init actions self._ACTIONS = object() + -- init extras + self._EXTRAS = object() + -- init name self._NAME = name @@ -339,6 +342,17 @@ function view:attr_set(name, value) return self end +-- get extra data +function view:extra(name) + return self._EXTRAS[name] +end + +-- set extra data +function view:extra_set(name, value) + self._EXTRAS[name] = value + return self +end + -- get action function view:action(name) return self._ACTIONS[name] |
