Giter Club home page Giter Club logo

catui's Introduction

996.icu

catui

A very light-weight GUI framework for the Löve2D

LOVE Version

11.0+

What do I want in my GUI library?

  • Simple
  • Light-weight
  • Extensible
  • Rich events

Explain

You should expand your own control, but you can also use the control folder under the control

Example

require "catui"

local myBtn = UIControl:new()
myBtn:setPos(100, 100)
myBtn:setSize(100, 40)

myBtn.events:on(UI_DRAW, function()
    local box = self:getBoundingBox()
    local x, y = box.left, box.top
    local w, h = box:getWidth(), box:getHeight()
    love.graphics.setColor(0, 1, 0, 1)
    love.graphics.rectangle(x, y, w, h)
end, myBtn)

myBtn.events:on(UI_CLICK, function()
    print("my buton is click")
end)

UIManager:getInstance().rootCtrl.coreContainer:addChild(myBtn)

API DOC

Goto Read

Screenshot

Screenshot

License LICENSE

Copyright (c) 2019 田伟汉

"Anti 996" License Version 1.0 (Draft)

Permission is hereby granted to any individual or legal entity
obtaining a copy of this licensed work (including the source code,
documentation and/or related items, hereinafter collectively referred
to as the "licensed work"), free of charge, to deal with the licensed
work for any purpose, including without limitation, the rights to use,
reproduce, modify, prepare derivative works of, distribute, publish
and sublicense the licensed work, subject to the following conditions:

1. The individual or the legal entity must conspicuously display,
without modification, this License and the notice on each redistributed
or derivative copy of the Licensed Work.

2. The individual or the legal entity must strictly comply with all
applicable laws, regulations, rules and standards of the jurisdiction
relating to labor and employment where the individual is physically
located or where the individual was born or naturalized; or where the
legal entity is registered or is operating (whichever is stricter). In
case that the jurisdiction has no such laws, regulations, rules and
standards or its laws, regulations, rules and standards are
unenforceable, the individual or the legal entity are required to
comply with Core International Labor Standards.

3. The individual or the legal entity shall not induce, suggest or force
its employee(s), whether full-time or part-time, or its independent
contractor(s), in any methods, to agree in oral or written form, to
directly or indirectly restrict, weaken or relinquish his or her
rights or remedies under such laws, regulations, rules and standards
relating to labor and employment as mentioned above, no matter whether
such written or oral agreements are enforceable under the laws of the
said jurisdiction, nor shall such individual or the legal entity
limit, in any methods, the rights of its employee(s) or independent
contractor(s) from reporting or complaining to the copyright holder or
relevant authorities monitoring the compliance of the license about
its violation(s) of the said license.

THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN ANY WAY CONNECTION WITH THE
LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE LICENSED WORK.

The MIT License (MIT)

Copyright (c) 2016 WilhanTian  田伟汉

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

catui's People

Contributors

okass avatar scorbiclife avatar wilhantian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

catui's Issues

Love 11.0 color scheme change

All colors specified are in the range 0..255, but as of Love 11.0 colors are in a 0..1 range. Here are all the occurrences I was able to find with grep 'color = {' -rinI ., there might be more:

     1	./doc/modules/catui.Control.UIButton.html:369:         color = {r, g, b, a}
     2	./doc/modules/catui.Control.UIButton.html:390:         color = {r, g, b, a}
     3	./doc/modules/catui.Control.UIButton.html:411:         color = {r, g, b, a}
     4	./doc/modules/catui.Control.UIButton.html:432:         color = {r, g, b, a}
     5	./doc/modules/catui.Control.UIButton.html:476:         color = {r, g, b, a}
     6	./catui/UITheme.lua:35:theme.button.upColor = {57, 69, 82, 255}
     7	./catui/UITheme.lua:36:theme.button.downColor = {30, 35, 41, 255}
     8	./catui/UITheme.lua:37:theme.button.hoverColor = {71, 87, 103, 255}
     9	./catui/UITheme.lua:38:theme.button.disableColor = {48, 57, 66, 255}
    10	./catui/UITheme.lua:39:theme.button.strokeColor = {25, 30, 35, 255}
    11	./catui/UITheme.lua:43:theme.button.fontColor = {255, 255, 255, 255}
    12	./catui/UITheme.lua:47:theme.scrollBar.upColor = {84, 108, 119, 255}
    13	./catui/UITheme.lua:48:theme.scrollBar.hoverColor = {112, 158, 184, 255}
    14	./catui/UITheme.lua:49:theme.scrollBar.downColor = {84, 108, 119, 255}
    15	./catui/UITheme.lua:50:theme.scrollBar.backgroundColor = {47, 59, 69, 255}
    16	./catui/UITheme.lua:52:theme.content.backgroundColor = {31, 36, 43, 255}
    17	./catui/UITheme.lua:55:theme.checkBox.upColor = {255, 255, 255, 255}
    18	./catui/UITheme.lua:56:theme.checkBox.downColor = {0, 150, 224, 255}
    19	./catui/UITheme.lua:57:theme.checkBox.hoverColor = {0, 150, 224, 255}
    20	./catui/UITheme.lua:58:theme.checkBox.disableColor = {84, 108, 119, 255}
    21	./catui/UITheme.lua:61:theme.progressBar.color = {57, 104, 149, 255}
    22	./catui/UITheme.lua:62:theme.progressBar.backgroundColor = {47, 59, 69, 255}
    23	./catui/UITheme.lua:64:theme.editText.backgroundColor = {255, 255, 255, 255}
    24	./catui/UITheme.lua:65:theme.editText.focusStrokeColor = {57, 104, 149, 255}
    25	./catui/UITheme.lua:66:theme.editText.unfocusStrokeColor = {41, 50, 59, 255}
    26	./catui/UITheme.lua:67:theme.editText.cursorColor = {82, 139, 255, 255}
    27	./catui/Control/UILabel.lua:39:    color = {0, 0, 0, 255},
    28	./catui/Control/UIButton.lua:219:-- @tab color color = {r, g, b, a}
    29	./catui/Control/UIButton.lua:227:-- @tab color color = {r, g, b, a}
    30	./catui/Control/UIButton.lua:235:-- @tab color color = {r, g, b, a}
    31	./catui/Control/UIButton.lua:243:-- @tab color color = {r, g, b, a}
    32	./catui/Control/UIButton.lua:259:-- @tab color color = {r, g, b, a}

Textbox is not showing text!

I am executed folder catui-master but when I started to write in text field, nothing happend! Blue cursor was moving, but text did not appear. Everything except this was working

scrollbar按钮拖拽时消失

-------------------------------------
-- (callback)
-- on bar move
-------------------------------------
function UIScrollBar:onBarMove(x, y, dx, dy)
    if not self.barDown then return end

    local bar = self.bar

    if self.dir == "vertical" then
        local after = bar:getY() + dy
        if after < 0 then
            after = 0
        elseif after + bar:getHeight() > self:getHeight() then
            after = self:getHeight() - bar:getHeight()
        end
-- 增加除数为0的判定
        local spaceHeight = self:getHeight() - bar:getHeight()
        if spaceHeight == 0 then spaceHeight = 1 end
        self.barPosRatio = after / spaceHeight
    else
        local after = bar:getX() + dx
        if after < 0 then
            after = 0
        elseif after + bar:getWidth() > self:getWidth() then
            after = self:getWidth() - bar:getWidth()
        end
-- 增加除数为0的判定
        local spaceWidth = self:getWidth() - bar:getWidth()
        if spaceWidth == 0 then spaceWidth = 1 end
        self.barPosRatio = after / spaceWidth
    end
    self:setBarPos(self.barPosRatio)
end

根据当前输出改变滚动条位置应该怎么写?

我给UILabel加了一个自动高度的函数

-- 宽度不变,自动高度
function UILabel:setAutoHeight()
  local width,height = self:getSize()
  local autoHeight = self.drawable:getHeight()
  self:setSize(width, autoHeight)
  return autoHeight
end

然后初始化控件

function InitContenter()
  love.graphics.setBackgroundColor(35/255, 42/255, 50/255, 1)
  local mgr = UIManager:getInstance()
  local content = UIContent:new()
  content:setPos(10, 10)
  local win_width = love.graphics.getWidth()
  local win_height= love.graphics.getHeight()
  
  content:setSize(win_width, win_height)
  content:setContentSize(win_width, win_height)
  content.backgroundColor = {31/255, 36/255, 43/255, 0.5}
  -- content:removeChild(content.hBar) -- 移除控件的子对象使用这个
  --UIControl.removeChild(content, content.vBar) 
  UIControl.removeChild(content, content.hBar) -- 移除控件的原生对象用这个
  --content.isCross = true
  content.visible = false
  mgr.rootCtrl.coreContainer:addChild(content)
  
  local label = UILabel:new("catui/font/visat.ttf", "show text", 14)
  label:setAnchor(0, 0.5)
  label:setAutoSize(false)
  label:setSize(content:getWidth(),content:getHeight())
  label:setAnchor(0,0)
  label:setClip(false)
  label:setFontColor({1, 1, 0, 1})
  content:addChild(label)
  content:setClip(false)
  content:setPos(0,0)
  content.visible = true
  return mgr
end

之后显示文本

function ShowDebugText(show_text,...)
  local text = ""
  for i,v in ipairs({...}) do
      text = text .. " " .. tostring(v)
  end
  local root = UIManager:getInstance():getRootCtrl()
  local content = (root.coreContainer:getChildren())[1]
  local label = content.contentCtrl.children[1]
  show_text = show_text .."\n".. text
  label:setText(show_text)
  --print(show_text)
  local labelHeight = label:setAutoHeight()
  local contentHeight = content:getContentHeight()
  local barHeight = math.floor(contentHeight*math.min(1.0,contentHeight*1.0/labelHeight))
  -- 要根据当前显示的行数,改变滚动条的位置
  content.vBar.bar:setHeight(barHeight)
  content.contentCtrl:setY(math.min(0,contentHeight-labelHeight))
  print("update barHeight:"..tostring(barHeight))
  return show_text
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.