formatting the text of a label

Geyser is an object oriented framework for creating, updating and organizing GUI elements within Mudlet.
Post Reply
branden7
Posts: 16
Joined: Wed Oct 23, 2013 6:27 pm

formatting the text of a label

Post by branden7 » Wed Oct 23, 2013 10:20 pm

Making a lot of progress thanks to how helpful everyone is here...
Still a few questions, though.

Can anyone suggest a way to color the text of a label.
I tried using cecho() but it doesnt seem to let me do that in a label.

I have a label box that displays the name and condition of my target. It would be nice to just directly copy over the colors from the MUD, but failing that I can color them myself.

Note that cecho doesnt throw any sort of error, it just makes the label not display anything.

here's what I am looking at:
Code: [show] | [select all] lua
GUI.Box2:echo("You are Fighting: " .. target .. "<br> Condition:<br>" .. condition);
and the box looks like this:
Code: [show] | [select all] lua
GUI.Box2 = Geyser.Label:new({
  name = "GUI.Box2",
  x = 0, y = "50%",
  width = "50%",
  height = "50%",
},GUI.Right)
GUI.Box2:setStyleSheet(GUI.BoxCSS:getCSS())
GUI.Box2:echo("<center>GUI.Box2")
Should I just be using a miniConsole?
this is probably just an issue of me not really knowing lua....if anyone has a reference to formatting that would be great.

fetaera
Posts: 191
Joined: Sat Aug 03, 2013 7:00 pm

Re: formatting the text of a label

Post by fetaera » Thu Oct 24, 2013 6:15 pm

Miniconsoles are certainly faster, but there's no reason not to use a label. My UI uses them exclusively with no problem.

In answer to your question, though, colours are passed differently in this instance. Take the following snippet as an example:
Code: [show] | [select all] lua
local out = [[<p align="center" style="font-size: 11px; font-family: ']] .. ccc.ui_font .. [['">]] .. "<span style=\"color:OrangeRed\">" .. table.concat(todisplay, "<br \>") .. [[</span></p><br>]]

ui.labels.affs:echo(out)
Hope that helps.

branden7
Posts: 16
Joined: Wed Oct 23, 2013 6:27 pm

Re: formatting the text of a label

Post by branden7 » Thu Oct 24, 2013 6:29 pm

Yeah it was that [[ ]] syntax that I was missing. I think that will help greatly.

Thanks!

branden7
Posts: 16
Joined: Wed Oct 23, 2013 6:27 pm

Re: formatting the text of a label

Post by branden7 » Thu Oct 24, 2013 6:49 pm

Yep...that thing helps and my labels now work better than the MiniConsole boxes I was trying to use.

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: formatting the text of a label

Post by Nyyrazzilyss » Mon Mar 07, 2016 4:42 am

Bringing back a very old thread, however:

I've been using cecho with a miniconsole window. I couldn't find a way to set callbacks for enter/exit/etc on miniconsoles, so i'm having to change it to a label. The text I was sending out with cecho though isn't css formatted, it was more stuff like <green>some text<red>999\n<green>more text<blue>0\n etc etc. This means switching from using a miniconsole to a label for that window has also cost me all my colouring/formatting.

Was there an easy function to reformat from cecho to echo, since cecho doesn't work with labels? Or even better, an easy way to add cecho to labels?

(edit)

I wrote a quick function to switch from cecho format to echo. It works for me, though it's more then likely restricted as to how well it works/what it's checking for. Is there a prexisting function to do this?

Code: [show] | [select all] lua
function parseLine(xline)
	local fontsize = 14
	local retval=""

	for k,v in pairs( string.split(xline, "<") ) do
		if v ~= "" then
			local tmp = 	string.split(v, ">")
		
			retval = retval .. [[<span style="color:]] .. tmp[1] .. [[">]] .. 
				 string.gsub(tmp[2], " ", "&nbsp;")
				 .. [[</span>]]
		end
	end

	retval = [[<p style="font-size:]] .. fontsize .. [[px;font-style:normal;font-family: 'Bitstream Vera Sans Mono'">]] .. retval .. [[</font></p>]]
	retval = string.gsub(retval, "\n", "<br>")

	return(retval)
end

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests