summaryrefslogtreecommitdiff
path: root/tests/ui/desktop.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-02 00:43:32 +0800
committerruki <[email protected]>2018-01-01 22:21:14 +0800
commit827f07629755347bed82cb51bc1735b2984e284c (patch)
tree7a69d659d67281211df0da854d60c3d53e253b71 /tests/ui/desktop.lua
parent1bf42f883ad6c68ebc48c2b574233fb0fb27aecf (diff)
add window
Diffstat (limited to 'tests/ui/desktop.lua')
-rw-r--r--tests/ui/desktop.lua83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/ui/desktop.lua b/tests/ui/desktop.lua
new file mode 100644
index 000000000..48539a14f
--- /dev/null
+++ b/tests/ui/desktop.lua
@@ -0,0 +1,83 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file desktop.lua
+--
+
+-- imports
+import("core.ui.log")
+import("core.ui.rect")
+import("core.ui.view")
+import("core.ui.label")
+import("core.ui.event")
+import("core.ui.button")
+import("core.ui.application")
+
+-- the demo application
+local demo = application()
+
+-- init demo
+function demo:init()
+
+ -- init name
+ application.init(self, "demo")
+
+ -- show desktop, menubar and statusbar
+ self:insert(self:desktop())
+ self:insert(self:menubar())
+ self:insert(self:statusbar())
+
+ -- init title
+ self:menubar():title():text_set("Menu Bar (Hello)")
+
+ -- add title label
+ self:desktop():insert(label:new("title", rect {0, 0, 12, 1}, "hello xmake!"), {centerx = true})
+
+ -- add yes button
+ self:desktop():insert(button:new("yes", rect {0, 1, 7, 2}, "< Yes >"), {centerx = true})
+
+ -- add no button
+ self:desktop():insert(button:new("no", rect {0, 2, 6, 3}, "< No >"), {centerx = true})
+end
+
+-- on event
+function demo:event_on(e)
+ if view.event_on(self, e) then
+ return true
+ end
+ if e.type == event.ev_keyboard then
+ self:statusbar():info():text_set(e.key_name)
+ if e.key_name == "s" then
+ self:statusbar():show(not self:statusbar():state("visible"))
+ elseif e.key_name == "m" then
+ self:menubar():show(not self:menubar():state("visible"))
+ elseif e.key_name == "d" then
+ self:desktop():show(not self:desktop():state("visible"))
+ elseif e.key_name == "q" then
+ self:quit()
+ end
+ end
+end
+
+-- main entry
+function main(...)
+ demo:run(...)
+end