Giter Site home page Giter Site logo

basalt's Introduction

Basalt - A UI Framework for CC:Tweaked

GitHub Repo stars Discord

Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's wiki or download. Note: Basalt is still under developement and you may find bugs!

Check out the wiki for more information. If you have questions, feel free to join the discord server: discord.gg/yNNnmBVBpE.

Demo

Demo of Basalt

basalt's People

Contributors

cyberbit avatar damianu avatar emmaknijn avatar erb3 avatar noryie avatar quittung avatar samkist avatar seaside53 avatar toastonrye avatar yarillo4 avatar znepb 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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

basalt's Issues

bug: XML labels not automatically resizing

What happened?

When labels are used with XML, they terminate unexpectedly. This occurs whether or not a space is present in the string, leading me to believe that the XML has a default size parameter that it sets, instead of calculating the size from the label text.

image

I tested this on CraftOS PC, as well as in 1.19.2 CC:Tweaked.

MRE:

local basalt = require("basalt")

basalt.createFrame():loadLayout("test.xml")
basalt.autoUpdate()

test.xml

<label text="HelloWorld" y="1" />
<label text="Hello World" y="2" />
<label text="HelloWorld" y="3" width="10" />
<label text="Hello World" y="4" width = "11" />

Computercraft client

Ingame (Default)

Relevant log output

No response

Latest Basalt Version

  • I use the latest stable version

bug: Key press transfers to the next Input when `setFocus` in used inside `onKey`

Note: I'm not sure if this is a bug or expected behaviour.

Describe the bug

Say you have inputs A and B. If you use B:setFocus() inside of A:onKey, pressing a key inside of A will output it to B.

To Reproduce

  1. Run the following basalt snippet:
local A = main_frame:addInput("A")
	:setPosition(1, 1)
	:setSize(20, 1)
	:show()

local B = main_frame:addInput("B")
	:setPosition(1, 2)
	:setSize(20, 1)
	:show()

A:onKey(function(self, event, key)
	B:setFocus()
end)
  1. Click on Input A, and press 'a'.

The output 'a' will be produced to B.

Expected behavior

Again... I'm now sure if this is a bug, or expected behaviour. However, I expected the 'a' to appear in the first input, and then the focus be set to B.

Screenshots

Clip.onKey.mp4

Checklist

[x] I am running the latest version.
Tick the box if you are running the latest version!

bug: DEV branch; basalt.debug crashes when called inside a thread

What happened?

Attempt to debug a thread by displaying a value using basalt.debug crashes the program.

Computercraft client

CraftOSPC

Relevant log output

I wish this was copypastable

basalt.lua:2209: Thread Error Occured - cannot resume running coroutine

2209 in eventHandler
713 in eventHandler
71 in cab (one of the minified functions)
this was in an xpcall
80 in autoUpdate

Latest Basalt Version

  • I use the latest stable version

bug: installer errors

What happened?

A while after running pastebin run ESs1mg7P packed, whilst the installer is running, the following error occurs:
image

Computercraft client

Ingame (Default)

Relevant log output

N/A

Latest Basalt Version

  • I use the latest stable version

feature: Move The Examples From Frame To A Seperate Area For Examples

Is your feature request related to a problem? Please describe.
It Is Extremely Annoying when I Have To Go To The Frame Section In The Docs To Find Examples And New Users Would Not Know Where To Find Them

Describe the solution you'd like
I Think The Examples Should Be Moved From The Frame Section To Somewhere Else

Describe alternatives you've considered
I have Considered Adding Something To Tell The User Where The Examples Are But I Think It Would Still Be Too Hard To Find

Additional context
image

bug: [1.7] Button Click events seems to produce a table instead of a string

Describe the bug

When a button gets clicked, instead of a string like "mouse_click" or "mouse_up" the event (2nd parameter) is a table.

To Reproduce

Steps to reproduce the behavior:

  1. A small program can be used to test the behaviour:
local basalt = require("basalt")

local main = basalt.createFrame()

main:addButton()
:setText("Start")
:setPosition(1, 1)
:setSize("7", "1")
:onClick(function(self, event, button, x, y)
	basalt.debug("Event ("..tostring(event)..") = {")
	if type(event) == "table" then
		for k, v in pairs(event) do
			basalt.debug(k.."="..tostring(v)..",")
		end
	end
	basalt.debug("}")
end)

basalt.autoUpdate()
  1. Run the program.
  2. Click the "Start" button.
  3. Open the Basalt debug window.
  4. See something like the attached screenshot.

Expected behavior

Once the button is clicked, the Basalt debug window will contain:

Event (mouse_click) = {
}

Screenshots

If applicable, add screenshots to help explain your problem.

basalt_error2

^ The contents of the event.

Additional context

Add any other context about the problem here.
N/A ?

Checklist

[ X ] I am running the latest version.
Tick the box if you are running the latest version!

bug: basalt overrides custom palettes

What happened?

basalt overrides custom palettes

-- Modified version of @1Turtle's GNOME  palette
-- black set back to default
-- and using the phoenix installer orange
local GNOME = {
    ["black"]     = 0x111111,
    ["blue"]      = 0x2A7BDE,
    ["brown"]     = 0xA2734C,
    ["cyan"]      = 0x2AA1B3,
    ["gray"]      = 0x5E5C64,
    ["green"]     = 0x26A269,
    ["lightBlue"] = 0x33C7DE,
    ["lightGray"] = 0xD0CFCC,
    ["lime"]      = 0x33D17A,
    ["magenta"]   = 0xC061CB,
    ["orange"]    = 0xD06018,
    ["pink"]      = 0xF66151,
    ["purple"]    = 0xA347BA,
    ["red"]       = 0xC01C28,
    ["white"]     = 0xFFFFFF,
    ["yellow"]    = 0xF3F03E
}

for color, code in pairs(GNOME) do
    term.setPaletteColor(colors[color], code)
end

Computercraft client

CraftOSPC

Relevant log output

No response

Latest Basalt Version

  • I use the latest stable version

feature: Return true errors upon failure on `basalt.autoUpdate`

Is your feature request related to a problem? Please describe.

It seems like basalt.autoUpdate() does not return true errors upon failure. Instead, it prints the error itself, and returns normally. This causes some things that depend on true errors to fail, such as pcall or xpcall.

This effectively makes implementing custom backtraces for basalt impossible. As a real example of this, running basalt inside of mbs will not print the backtrace, as mbs expects the program to raise an actual error upon failure.

The main usage I have for this is to log the backtrace:

--- ...

local function log_traceback()
	utils.log(debug.traceback())
end

utils.log('Running main loop')
local ok, res = xpcall(basalt.autoUpdate, log_traceback)
if not ok then
	error(res)
end
utils.log('Execution succeeded')

In the code above, log_traceback and the code inside the if will never execute, regardless of the failure status of autoUpdate.

Minimal Working Example

local filePath = "/basalt.lua"
if not(fs.exists(filePath))then
    shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", ""))
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame()

local thread = main:addThread()
local function yourCustomHandler()
    while true do
        os.sleep(1)
        error("Horrible error") --Error
    end
end
thread:start(yourCustomHandler)

local success, err = pcall(basalt.autoUpdate)
if success then
	-- Currently, it'll follow this path, as though the execution succeeded.
	print('Success')
else
	-- I wish it would follow this path, which is the failure path.
	print('Error: ', err)
end

Describe the solution you'd like

Calling error with the message displayed passed as an argument that can be catched.

bug: [TITLE]โ€œonEventโ€disable

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

Checklist

[ ] I am running the latest version.
Tick the box if you are running the latest version!

[BUG?] setTextAlign a nil value

The function documented here, "setTextAlign" is nil.
How to replicate:

local basalt = dofile("lib/basalt")
local mainFrame = basalt.createFrame("mainFrame"):show()
local label = mainFrame:addLabel("label"):setSize(45,1):setValue("This is a label"):setTextAlign("center","center"):show()
basalt.autoUpdate()

This errors: test.lua:3: attempt to call method 'setTextAlign' (a nil value)

It seems it's on Button, not Object?

bug: `Input` doesn't reset the cursor position after getting emptied by `setValue`

Describe the bug

The previous position of the Input's cursor is maintained when a setValue call is followed by a setFocus call, even when the input is empty.

Minimal Working Example

--Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
    shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")

local input = main:addInput('input')
	:setPosition(1, 1)
	:setSize(20, 1)
	:setValue('Some Text')

local button = main:addButton('button')
	:setPosition(1, 2)
	:setSize(20, 1)
	:setValue('Button')
	:onClickUp(function()
		-- Important part
		input:setValue('')
		input:setFocus()
	end)

basalt.autoUpdate()
Clip.input.cursor.mp4

Steps to reproduce the behavior:

  1. Type something in the Input
  2. Clear it with input:setValue('')
  3. Focus on it with input:setFocus()

Expected behavior

The cursor would return to the rightmost side of the input.

Checklist

[x] I am running the latest version.

bug: animation `:wait` doesn't work with 'built-in' animations

Description

Using :wait before one of the build-in animations (:size, :position, offset, etc) will not wait before executing the animation.

Minimal Working Example

-- Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
		shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")
local W, H = main:getSize()

-- Frame using built-in animation (size) will not properly wait.
local frame_not_working = main:addFrame("frame_not_working")
	frame_not_working:setSize(math.floor(W/2)-2, H-2)
	frame_not_working:setPosition(2, 2)
	frame_not_working:setBackground(colors.black)
	frame_not_working:setBorder(colors.white)

local animation_not_working = main:addAnimation("animation_not_working")
	:setObject(frame_not_working)
	:setMode("linear")
	-- This will fail. It will not wait 3 seconds.
	:wait(3)
	:size(math.floor(W/2)-2, 0, 0.5)
	:onDone(function()
		frame_not_working:remove()
	end)

-- Frame avoiding built-in animation (manually resizing) will wait.
local frame_working = main:addFrame("frame_working")
	frame_working:setSize(math.floor(W/2)-2, H-2)
	frame_working:setPosition(math.floor(W/2)+1, 2)
	frame_working:setBackground(colors.black)
	frame_working:setBorder(colors.white)

local animation_working = main:addAnimation("animation_working")
	:setObject(frame_working)
	-- This will succeed, it will wait 3 seconds.
	:wait(3)

for _ = 1, H-3 do
	animation_working:add(function()
		frame_working:setSize(0, -1, 'r')
	end)
		:wait(0.01)
end
animation_working:onDone(function()
		frame_working:remove()
	end)

-- Execute.
animation_not_working:play()
animation_working:play()

basalt.autoUpdate()
output.mp4

Expected behavior

Wait the amount specified in :wait before starting built-in animation.

Checklist

[โœ”๏ธ] I am running the latest version.

bug: Calling `removeLine()` to empty `Textfield` deforms the first line of the `Textfield`'s box

Minimal Working Example

image

local filePath = "/basalt.lua"
if not(fs.exists(filePath))then
    shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", ""))
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")

-- This is fine.
local textfield_0 = main:addTextfield('textfield_0')
	:setPosition(1, 1)
	:setSize(20, 3)
	-- two addLine
	:addLine('Value')
	:addLine('Another Value')
	-- no removeLine

-- This is fine.
local textfield_1 = main:addTextfield('textfield_1')
	:setPosition(1, 5)
	:setSize(20, 3)
	-- two addLine
	:addLine('Value')
	:addLine('Another Value')
	-- one removeLine
	:removeLine()

-- This gets deformed.
local textfield_2 = main:addTextfield('textfield_2')
	:setPosition(1, 9)
	:setSize(20, 3)
	-- two addLine
	:addLine('Value')
	:addLine('Another Value')
	-- two removeLine
	:removeLine()
	:removeLine()

basalt.autoUpdate()

As seen in the MWE above, textfield_2 gets deformed by the second call to removeLine().

Expected behavior

The Textfield maintains its shape.

image

Checklist

[X] I am running the latest version.

bug: Textfield newline deletion attempting to index field of nil value

Describe the bug

The textfield object crashes the basalt when new line is added and removed.

To Reproduce

Steps to reproduce the behavior:

  1. create textField
  2. add new line using enter
  3. press backspace

Expected behavior
It should remove line, instead of crashing.

Screenshots

bug

Additional context

No matter the surrounding, the textfield fails under the above conditions.

Checklist

  • I am running the latest version.

Tick the box if you are running the latest version!

bug: setActiveFrame does not change the active frame

Describe the bug

When I call basalt.setActiveFrame, nothing happens. The current frame is still the previous frame.

To Reproduce

Steps to reproduce the behavior:

  1. Copy the example usage from https://basalt.madefor.cc/#/objects/Basalt/setActiveFrame
  2. Run it
  3. Notice how it doesn't swap back and forth when you press the button

Expected behavior

It should set the active frame, make it so it is displayed, and receive events.

Checklist

[x] I am running the latest version.
Assuming the latest version is the latest release on github (1.7), yes I am.

bug: Container.removeChild does not work with strings

Describe the bug

When trying to use the function removeChild with an ID of an element this gives an error

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://basalt.madefor.cc/#/objects/Container/removeChild
  2. Copy the example
  3. Run it
  4. See error in the 1st screenshot

Expected behavior

The specified children of the container gets removed.

Probable cause

The problems seems to be that when passing a string it tries to call the method getName() which is a method of basalt Object's (2nd screenshot)

Screenshots

Code_gCAWxLm3vT
brave_BbiDgzqQDV

Checklist

[x] I am running the latest version.

bug: XML number buttons crash Basalt

Describe the bug

When using buttons in XML, if the text is set to only numbers, Basalt crashes. This bug only happens when you create buttons via XML.
If the text field has any non-numeric character the bug doesn't happen.

To Reproduce

Steps to reproduce the behavior:

  1. Create a XML layout with a button with the text "123"
  2. Add this layout to a frame.
  3. Run.
  4. Crash.

Expected behavior

It should just show the numbers, as it does when you programmatically create a button.

Checklist

[x] I am running the latest version.
Tick the box if you are running the latest version!

feature: prioritize active dropdown boxes if they are in the same Z-Index

Problem

Currently, if you have multiple dropdowns in a frame, they are prioritized in the order they were added (last in the top).

This means that if you are adding a bunch of dropdowns in a column (perhaps using a for loop), the dropdown box of the ones above will be overshadowed by the label of the ones below.

Minimal Working Example

-- Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
	shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")

for i = 1, 3 do
	local fg_color, bg_color
	if i % 2 == 0 then
		fg_color = colors.black
		bg_color = colors.white
	else
		fg_color = colors.white
		bg_color = colors.black
	end

	main:addDropdown('dropdown_'..i)
		:setPosition(20, 6 + (2*i))
		:setSize(10, 1)
		:addItem('Option 1')
		:addItem('Option 2')
		:addItem('Option 3')
		:addItem('Option 4')
		:addItem('Option 5')
		:setForeground(fg_color)
		:setBackground(bg_color)
		:selectItem(1)
end

basalt.autoUpdate()
output.mp4

Desired Solution

For me, a reasonable solution would be to prioritize rendering the dropdown box over the dropdown label whenever they are in the same index.

Alternative Solutions

From basalt's part:

  • Reverse the priority order (i.e. make later added items less prioritized).
    • I wouldn't like this solution, as I would expect items added later to be rendered above items added beforehand, including dropdowns.
  • Prioritize rendering active dropdowns.
    • I wouldn't like this solution, as I wouldn't expect a dropdown to be "brought to the front" just because it was clicked. For example, in the setup below, the dropdown stays behind after being clicked. That's the behaviour I would expect, and the dropdown getting "popped" up would be weird in that scenario.
output.mp4

From my part:

  • Reversing the for loop. (i.e. for i = 3, 1, -1 do)
  • Manually setting the index. (i.e. :setZIndex(3 - i))
    Both of these workarounds resolve the issue.
output.mp4

Additional context

Although the workarounds (from my part) are quite simple, I think it's reasonable for a developer using the API to assume the dropdowns boxes (on the same level) would be prioritized over labels.

As an example, in the Windows API for GUI, it's true (and expected) that if you add a couple of dropdowns in a column one after another, when you click on the first dropdown, its box won't be overshadowed by the dropdowns below it. I think it's reasonable to assume the same behaviour in basalt.


Edit: I now realize this is probably a bug report, not a feature request... oh well ยฏ\_(ใƒ„)_/ยฏ

feature: fill in both sides of the border (i.e. the full box) when a frame becomes 1-wide

Problem

Making a frame with borders 1-wide creates seemingly undefined behaviour (in terms of how the borders will be drawn). In general, only one side is drawn at a time, leading to the other side being "open".

Minimal Working Example

-- Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
	shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")
local W, H = main:getSize()

local frame = main:addFrame("frame")
frame:setSize(W-2, math.floor(H/2))
	frame:setPosition(2, 5)
	frame:setBackground(colors.black)
	frame:setBorder(colors.white)

local animation = main:addAnimation("animation")
	:setObject(frame)
	:size(1, math.floor(H/2), 0.5, 0.5)

animation:play()

basalt.autoUpdate()
output.mp4

Desired Solution

When becoming one-wide, a frame with border of color X should be completely filled by color X (simulating drawing on both sides of the border).

Minimal Working Example (Simulation)

-- Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
		shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")
local W, H = main:getSize()

local frame = main:addFrame("frame")
frame:setSize(W-2, math.floor(H/2))
	frame:setPosition(2, 5)
	frame:setBackground(colors.black)
	frame:setBorder(colors.white)

local animation = main:addAnimation("animation")
	:setObject(frame)
	:size(2, math.floor(H/2), 0.5, 0.5)
	:onDone(function()
		frame:setSize(1, math.floor(H/2))
		frame:setBackground(colors.white)
	end)

animation:play()

basalt.autoUpdate()
output.mp4

bug: Setting high ZIndex for parent after adding children overshadows interactions with said children

Minimal Working Example

Minecraft_.1.16.5.-.Singleplayer.2022-11-22.04-31-52.mp4
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
    shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")

local function visual_button(btn)
    btn:onClick(function(self) btn:setBackground(colors.black) btn:setForeground(colors.lightGray) end)
    btn:onClickUp(function(self) btn:setBackground(colors.gray) btn:setForeground(colors.black) end)
    btn:onLoseFocus(function(self) btn:setBackground(colors.gray) btn:setForeground(colors.black) end)
end


local working_frame = main:addFrame("working_frame")
	:setPosition(2, 2)
	:setSize(20, 10)
	:setBackground(colors.black)
	-- This will work fine (notice that it's done before adding the children).
	:setZIndex(1000)

local working_input = working_frame:addInput("input")
	:setPosition(2, 2)
	:setSize(18, 1)
	:setDefaultText("Search Text")

local working_button = working_frame:addButton("button")
	:setPosition(2, 4)
	:setSize(18, 1)
	:setValue("Search")
visual_button(working_button)


local not_working_frame = main:addFrame("not_working_frame")
	:setPosition(23, 2)
	:setSize(20, 10)
	:setBackground(colors.black)

local not_working_input = not_working_frame:addInput("input")
	:setPosition(2, 2)
	:setSize(18, 1)
	:setDefaultText("Search Text")

local not_working_button = not_working_frame:addButton("button")
	:setPosition(2, 4)
	:setSize(18, 1)
	:setValue("Search")
visual_button(not_working_button)

-- This will effectively disable the children (notice that it's done after adding the children).
not_working_frame:setZIndex(1000)


main:show()
basalt.autoUpdate()

Expected behavior

Children being interactable after changing the ZIndex of parent.

Checklist

[X] I am running the latest version.

docs: State what classes each object inherit from, with links to those classes.

Where?

In each class that inherits from other classes.

Possible solution

I really like the way the roblox documentation does this, it lists the methods the object itself has (like currently done), but beneath that it has dropdowns for "Inherited from <X>"

image

Others

The current way does work, but having something like this will reduce the need to click back and forth through multiple pages.

I also notice that sometimes the In addition to the A and B methods, X objects have the following methods: statement is sometimes missing base class methods (currently I am looking at Input, which is missing ChangeableObject).

Checklist

  • I am looking at the latest version of the docs.

bug: Side-specific border coloring with .xml values does not work

Describe the bug

Side-specific border coloring when making the UI with .xml does not work properly.

To Reproduce

Steps to reproduce the behavior:

  1. Create a simple Basalt UI with .xml style
  2. Add an object with a side-specific border coloring:
<button x="2" y="2" text="Hello" borderBottom="blue" />
  1. Run the program
  2. See error:
    Basalt error: .../basaltDraw.lua:202: bad argument (string expected, got nil)

Expected behavior

A button with the text "Hello" should appear with a blue border only along the bottom

Additional context

Changing these four lines (138-141) in Object.lua seems to fix it! Just had to wrap the xmlValue(...) return with colors[...], like the other surrounding code does.

if(xmlValue("borderLeft", data)~=nil)then borderColors["left"] = colors[xmlValue("borderLeft", data)] end
if(xmlValue("borderTop", data)~=nil)then borderColors["top"] = colors[xmlValue("borderTop", data)] end
if(xmlValue("borderRight", data)~=nil)then borderColors["right"] = colors[xmlValue("borderRight", data)] end
if(xmlValue("borderBottom", data)~=nil)then borderColors["bottom"] = colors[xmlValue("borderBottom", data)] end

Checklist

[x] I am running the latest version.
Tick the box if you are running the latest version!

feature: Better image handling

Is your feature request related to a problem? Please describe.
I am frustrated cause its difficult to add support for another image format to Basalt (cimg2 in my case).

Describe the solution you'd like
I would like for there to be some kind of more modular way of handling images, perhaps with a separate library.

Describe alternatives you've considered
Modifying most Basalt code just so it might work.

Bug: Button OnClick not detecting clicks

I've installed basalt and set up my first program following the tutorial.
I've set up a button by using

local btnGate = controlfram
:addButton()
:setPosition(2,2)
:setText("[ OPEN ]")
:setBackground(colors.yellow)

I originally had the onclick set up as part of the call chain, but have movied it to be it's own section

btnGate:onClick(function(self,event,button,x,y)
basalt.debug("CLICK EVENT")
if (event == "mouse_click") and (button == 1) then
basalt.debug("CLICKED")
open("gate") --My function call for my gates
end
end)

after this I have the basalt.autoUpdate() call.
The program starts up, and I can drag the movableframe around like it's supposed to, but clicking a button never does anything. And the debug events are never called. I'm not sure why.

Checklist

[ X] I am running the latest version.

[FEATURE REQUEST] Bigfont

Type: Feature request

Hey,

I think it would be cool if we could implement something like Bigfont by Wojbie or something similar for labels.
I have an example of BigFont beeing used, see image below:
image
Here you can see the "PixelTech INC" sized big, using BigFont, and under the "maybe?", using normal text.

I can imagine the api to be something like this:
label:setFontSize(font size), where font size is 1 for normal, 2 for bigger, 3 for even bigger, etc, etc.

bug: Broken basalt.update()

Describe the bug

basal.autoUpdate() works fine for me, however basalt.update() seems to be messing up events

To Reproduce

Steps to reproduce the behavior:

  1. Swap basalt.autoUpdate() for
while true do basalt.update(os.pullEventRaw())

Expected behavior

Given code being equivalent of autoUpdate (without drawFrames)

Additional context

I think it's due to xpcall not passing parameters in computercraft's lua version.
https://github.com/Pyroxenium/Basalt/blob/master/Basalt/main.lua#L409
Swapped my update for:

    update = function(event, ...)
        local args = {...}
        local function f()
            basaltUpdateEvent(event, table.unpack(args))
        end

       local ok, err = xpcall(f, debug.traceback)
        if not(ok)then
            basaltError(err)
            return
        end
    end,

and it works fine now

Checklist

[ ] I am running the latest version.
Tick the box if you are running the latest version!

docs: Latest 1.7 docs suggests their is a `Basalt.setTheme()`

** Where? **
https://github.com/Pyroxenium/Basalt/blame/d4c72514ef560af88c7f7557ba6f35ddaa2dc724/docs/objects/Basalt.md#LL29C45-L29C45

As the title says, the docs contain a Basalt.setTheme() function which appears to no longer exist.
When I load Basalt and run the Basalt.setTheme() from the Lua prompt (or any other file) I get the following error (even if I pass a correct table):
basalt_error

** Possible solutions **

  1. Remove the function from the docs.
  2. Update the docs to contain the new alternative.
  3. Resurrect the old setTheme() function.

** Others **
I have downloaded the recent Minified/Packed Version a few minutes ago.

** Checklist **
[ X ] I am looking at the latest version of the docs.

feature: Allow to register custom XML parsers

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Parsing XML (or HTML) can be a challenge in Lua. Having the ability to register custom XML parsers will allow people to do this.

Describe the solution you'd like
A clear and concise description of what you want to happen.

The creation of a system that allows people to make custom XML parsers which support custom tags. Each custom tag should be predefined.

Example lua:

-- This function will allow people to do what they want if a tag is parsed for example add it to a layout.
-- This function will be called for all tags. Parent tags (tags with child tags) will have this function run first on them, this could allow custom data to be passed to child tags.
local function parse(tag)
    local name = tag.name -- the name of the tag
    local attrs = tag.attrs -- the tag's attributes
    local children = tag.children -- the tag's children (a table of other tags in the same format) (or a string if it is just text e.g. `<p>text here</p>`)
    if name == "p" then
        if not tag.inDiv then
            frame:addLabel():setText(children) -- amusing `frame` is a `Frame` and `children` is a `string`
        end
    end
    if name == "div" then
        for k,v in pairs(children) do
            v.inDiv = true -- set a custom value on the children of this div
        end
    end
end

local tags = {
    p = { -- define a tag called "p"
        children = "string" -- this will allow only strings inside a `p` if other types are found (like and other tag) then there will be an error. Single numbers should be parsed as a string.
    },
    div = { -- define a tag called "div"
        children = "any" -- allow anything inside a div
    }
}

local parser = basalt.makeParser(tags, parse)
-- The parser object shall work like the normal XML parser with the same `:loadLayout`. In addition there should be a `:loadString` which takes the XML code as a string instead of a file name.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Copying your existing XML parser and modifying it.

Additional context
Add any other context or screenshots about the feature request here.

This will allow me to make a better HTML parser for my CC Browser and have a very nice UI.

feature: Custom colors

It seems we're limited to using the standard colors provided by the colors library. Using colors created with colors.packRGB results in an error, as the color lookup in the tHex library fails. I'd Like to be able to use custom colors for gradients in heat graphs and darkening buttons when clicked.

Are there plans to support custom colors, and is this even supported by the monitors?

bug: scrolling `Frame` does not account for extended `Dropdown`

Note: I'm not sure if this is a bug report or a feature request (i.e. if this is unintended or intended behaviour).


Describe the bug

An expanded Dropdown may have items inaccessible, as Frame scrolling is disabled while the dropdown is expanded.

Minimal Working Example

clip.dropwown.inaccessible.mp4
local filePath = "/basalt.lua"
if not(fs.exists(filePath))then
    shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", ""))
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame"):setScrollable()

local w, h = term.getSize()

for i=1,5 do
	main:addDropdown('dropdown_'..tostring(i))
		:setPosition(2, h+i-2)
		:setSize(10, 1)
		:addItem('Item 1')
		:addItem('Item 2')
		:addItem('Item 3')
		:show()
end

basalt.autoUpdate()

In the example above, Item 2 and Item 3 are inaccessible, as:

  1. They are not visible even in that maximum scroll down of the Frame
  2. Further scrolling is disabled while the Dropdown is expanded

Expected behavior

Be able to scroll further down the Frame while the Dropdown is expanded.

Checklist

[x] I am running the latest version.

bug: `addLine` skips the first line, even if it's empty

Minimal Working Example

--Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
    shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")

local button = main:addTextfield('button')
	:setSize(20, 5)
	:addLine('something')

basalt.autoUpdate()

image

Expected behavior

If the first line is empty, addLine would add the text to the first line.


[X] I am running the latest version.
Tick the box if you are running the latest version!

bug: gps.locate() doesn't return anything

Describe the bug

When using gps.locate() inside a thread, it wont return the gps coordinates

Expected behavior

Returning the gps values inside a thread.

[ x] I am running the latest version.

On the dev branch of basalt os.pullEvent in threads doesn't support filters

Describe the bug

When you use os.pullEvent in a thread the filter is ignored.

To Reproduce

local basalt = require("basalt")

local main = basalt.createFrame():setTheme({FrameBG = colors.lightGray, FrameFG = colors.black})
local thread = main:addThread()
thread:start(function()
  while true do
    print(textutils.serialize({os.pullEvent("key_up")}))
  -- Now I'm not sure if this code would work
  -- Just because the basalt event handler isn't running when I try to start this thread
  -- but my point still stands
  -- if it does work, this will error. It will instead catch one of the basalt events, one that has functions in the table returned therefor crashing the program.
  end
end)

basalt.autoUpdate()

Expected behavior

The example above wouldn't crash, because it would only ever resume on "key_up" events

Screenshots
N/A

Additional context
N/A

Checklist

[ ] I am running the latest version.
Tick the box if you are running the latest version!

I am running the DEV branch, from when you told me to update it

bug: long text on button overflows the button's bounding box

Describe the bug

If the text (or value) in the button is longer than its width, the text will overflow the button's bounding box.

Minimal Working Example

-- Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
		shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")

main:addButton('button')
	:setPosition(20, 8)
	:setSize(10, 3)
	:setValue('some very very long name')

basalt.autoUpdate()

image

Expected behavior

The text would be "cut off" the bounding box of the button.
image

Checklist

[โœ”๏ธ] I am running the latest version

bug: Loading image

Image doesn't appers on screen.

Steps to reproduce the behavior:

  1. Coppy example from https://basalt.madefor.cc/#/objects/Image
  2. Paste in my programm
  3. Add require() and autoUpdate() function
  4. Run programm

Expected: Image appers on screen

[ V] I am running the latest version.
Tick the box if you are running the latest version!

bug: Unable to create input fields

I cannot create input fields

Steps to reproduce the behavior:

  1. Use addInput() to create a input field
  2. Run to see errors

I expect it to create a input field

image

Checklist

[V] I am running the latest version.
Tick the box if you are running the latest version!

bug: atempt to perform arithmetic on a table value

Describe the bug

I'm trying to run a code snippet shared in https://basalt.madefor.cc/#/objects/Frame

local basalt = require("basalt") -- we need basalt here

local main = basalt.createFrame():setTheme({FrameBG = colors.lightGray, FrameFG = colors.black}) -- we change the default bg and fg color for frames

local sub = { -- here we create a table where we gonna add some frames
    main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"), -- obviously the first one should be shown on program start
    main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"):hide(),
    main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"):hide(),
}

local function openSubFrame(id) -- we create a function which switches the frame for us
    if(sub[id]~=nil)then
        for k,v in pairs(sub)do
            v:hide()
        end
        sub[id]:show()
    end
end

local menubar = main:addMenubar():setScrollable() -- we create a menubar in our main frame.
    :setSize("{parent.w}")
    :onChange(function(self, val)
        openSubFrame(self:getItemIndex()) -- here we open the sub frame based on the table index
    end)
    :addItem("Example 1")
    :addItem("Example 2")
    :addItem("Example 3")

-- Now we can change our sub frames, if you want to access a sub frame just use sub[subid], some examples:
sub[1]:addButton():setPosition(2, 2)

sub[2]:addLabel():setText("Hello World!"):setPosition(2, 2)

sub[3]:addLabel():setText("Now we're on example 3!"):setPosition(2, 2)
sub[3]:addButton():setText("No functionality"):setPosition(2, 4):setSize(18, 3)

basalt.autoUpdate()

But it throws an error dynamicValues.lua:51: attempt to preform arithmetic on a table value

To Reproduce

Steps to reproduce the behavior:

  1. Clone the repository move Basalt as basalt
  2. Create a file called test.lua in computer
  3. Paste the given code
  4. Run the code and get the error

Expected behavior

Example code should work

Screenshots

image

Additional context

Checklist

[X] I am running the latest version.
Tick the box if you are running the latest version!

bug: "addObject" function doesn't seem to do anything

Describe the bug

Calling the addObject function with a directory path doesn't seem to do anything at all - custom object modules are not required.

It looks like all this function does is add the provided path to newObjects in main.lua, but newObjects is only ever visted when main.lua is first evaluated (i.e. when the module is required, before the addObject function can even be called).

To Reproduce

Steps to reproduce the behavior:

  1. Add a custom object module to a folder that has a debug print or something at the top
  2. Pass the folder to basalt.addObject("...") in a test program
  3. Run the program and observe that the custom modules are not imported

Expected behavior

The custom object modules would be imported and registered as object types in Basalt.

Checklist

  • I am running the latest version.

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.