Coder Social home page Coder Social logo

primeui's Introduction

PrimeUI

A collection of UI component primitives for ComputerCraft.

PrimeUI provides a number of small, mostly self-contained basic UI components that are designed to be embedded directly in a program. These components are left as generic as possible to support many use cases, and are annotated so that even beginners can understand and modify the code.

Usage

PrimeUI is designed to be copy and pasted directly into a program. First, copy the contents of util.lua to the program, skipping over the return line at the bottom. Then copy the contents of each component you need below that function, skipping over the lines with require at the top. After that, you can use each component as directed by the docs.

Alternatively, a single-file packed version is available in the Releases section. This provides all of the components in PrimeUI as a single table.

test.lua contains an example of how to use the various functions. Refer to this for usage examples. EmmyLua docs are provided for VS Code completion.

License

PrimeUI is donated to the public domain under CC0. Feel free to use any portion of the code as desired, though I'd appreciate leaving a notice that it came from PrimeUI.

primeui's People

Contributors

badgeminer avatar mcjack123 avatar

Stargazers

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

Watchers

 avatar

primeui's Issues

Support for rendering and interaction on monitor

right now, the flow I use is

moni.clear()
prime.button(moni, ...)
parallel.waitForAny(prime.run, function()
  while true do
    -- event loop
  end
end)

this works, but interactions are on the computer, not the monitor (touch events, keyboard-only components don't make sense). if I get to it, I'll pr something tmr, otherwise take this quick sample I wrote in 5 minutes (take it with a grain of salt - there's probably something I forgor) - note this is only for buttons, but the general concept stays

function PrimeUI.button(win, x, y, text, action, fgColor, bgColor, clickedColor, periphName) -- periphName = string | nil
  -- ...
  if event == "mouse_click" and periphName == nil and button == 1 and clickX >= screenX and clickX < screenX + #text + 2 and clickY == screenY then
    -- ...
  elseif event == "monitor_touch" and periphName == button and clickX >= screenX and clickX < screenX + #text + 2 and clickY == screenY
    or event == "mouse_up" and button == 1 and buttonDown then -- buttonDown is false because the mouse_click event is blocked when clicked on the screen
    -- ..
  end
end

-----------

prime.button(monitorRight, 2, 4, string.char(25), function()
  -- ...
end, nil, nil, nil, "right")) -- this could probably be stripped down by using the win var, not sure

Demos for each component

While the test.lua is cool n all, it's missing most of the components. I'd like to see an actual component gallery including demos on how to do different things with components, including code examples. If this is too complicated, a GitHub wiki would also work. Some of these probably aren't possible, but I feel like this would really benefit some more advanced features.

Some example ideas for a wiki:

  • Editing text of a label on the fly
  • Listening for terminate using PrimeUI#addTask
  • Preselecting a specific selectionBox item
  • Returning multiple inputs
  • Enabling mouse scroll on selection boxes
  • ...

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.