Jump to content


xgaarocha's Content

There have been 2 items by xgaarocha (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#221612 [OpenPeripheral 1.1.1] Get "glasses_text" width

Posted by xgaarocha on 16 June 2015 - 06:30 PM in Peripheral Help and Discussion

Sorry for not answering quicker, I had some family problems.

Anyhow, I've worked out that characters are 5 pixels wide, times the scale. The only character I've found to be less than 5 pixels is the exclamation mark, which is 2 pixels wide.
Anyhow, here's the code i've come up with: (CHAR_HEIGHT is just there so I don't forget the value :P)
function GetTextWidth(textObject)
local CHAR_WIDTH = 5
local CHAR_HEIGHT = 8
local EXCLAMATION_WIDTH = 2
local text = textObject.getText()
local scale = textObject.getScale()
local width = 0

for i = 1, #str do
    if text:sub(i,i) == "!" then
       width = width + CHAR_WIDTH * scale  
    end
end

return width
end



#220176 [OpenPeripheral 1.1.1] Get "glasses_text" width

Posted by xgaarocha on 06 June 2015 - 11:59 PM in Peripheral Help and Discussion

I've been trying to find a way to get the width (in pixels, not characters) for glasses_text objects but I can't find out how.
I've generated and looked trough the doc, searched on Google and still didn't find anything.

I know there was a function (now deprecated): glass.getStringWidth(str) but I also read that It didn't work correctly, as it assumed the font was monospace when it wasn't.

I want to know if there is any function that is hidden from the docs that can get me the width? The only solution I can think of is to manually find the width of every character, taking into account the scale property and adding up the width of every character.

Thanks for you attention.