Setting element images in code

Discussion of features and help with problems encountered while using libRocket

Setting element images in code

Postby dinger on Mon Aug 20, 2012 6:47 pm

Hey all,

I'm curious about the best way to set the image of a radio button/div in code. The method mentioned in [] does not seem ideal for me since I will be getting images from an external source then displaying them in code, so I cannot use an image path in the rcss. The radio buttons are also thumbnail images which, once selected, will update a div with the larger radio button image.

Ideally, I would have the rml/rcss set the layout for the radio buttons/div and in an onload event query the radio buttons/div and set the initial images. Then, when the user selects a different radio button the div would be updated with the larger image.

One way this could be achieved is via a custom decorator that takes an image source and checks if the image changed each frame, but that seems a bit hackish to me.

Posts: 1
Joined: Mon Aug 20, 2012 6:28 pm

Re: Setting element images in code

Postby ceilventia on Fri Feb 27, 2015 10:28 am

Maybe you could try this.

myElement->SetInnerRML( "<img src=\"path/Img.tga\"/>" );
Posts: 2
Joined: Fri Feb 27, 2015 10:08 am

Re: Setting element images in code

Postby aquawicket on Sat Mar 07, 2015 8:26 am

You should be able to use full paths to set the image. I'm not sure relative paths work.
So you may need to resolve the full path of the file first.
Then you simply update the element's "src" attribute.

Code: Select all
<img id="image1" src="test.png"></img>

Code: Select all
std::string filename = "C:/folder1/newimage.png";  //Full path to image
element->SetAttribute("src", filename.c_str());
Posts: 8
Joined: Fri Jun 27, 2014 6:07 am

Return to Using libRocket