Hi @pspeed, regarding to our talk here:
Basically I do have an Listbox, that is a Grid with X and Y number of attached cells. Not all of them are necessary visible.
The content of the cell in Listbox is written in that line. (My modified Listbox looks a bit different. Original Listboxs model is one-dimensional (row), while I have two dimensions (row and column)
But however in both cases CellRenderer.getView is called
@Override
public Panel getView( T value, boolean selected, Panel existing ) {
if( existing == null ) {
existing = new Button(valueToString(value), elementId, style);
} else {
((Button)existing).setText(valueToString(value));
}
return existing;
}
}
So in the end the Button that is attached to the Grid(Listbox) is - as you said in the WIP threat - able to take picture and text.
In order to get a specific picture attached we need to add a line
existing = new Button(Background choosen picture);
So the issue is: The picture has to be available in the Assetlist therefore it has to be loaded.
Texture txt = getApplication().getAssetManager().loadTexture("/Pictures/MyPic.png");
QuadBackgroundComponent qC= new QuadBackgroundComponent(txt);
How can I have the pics available ?
There is for sure some ways to do it. Thats how I thought it is less invasive:
CustomCellRenderer extents CustomcellRenderer
it will need a
-
private ArrayList<String[]> contents = new ArrayList<String[]>();
= A list of 3 variables (row, column, Adress or name of the picture) -
- AssetManager
I am not sure what is best now. Loading the picture and creating the Button whenever the Listbox is refreshed or is it better to prepare the Buttons before. Since in my project I have a Style Appstate I am currently thinking to go with that approach.
When the CustomCellRenderer is created I do
attrs = style.getSelector(new ElementId("exit").child("button"), "style");
Texture txt = getApplication().getAssetManager().loadTexture("/Pictures/MyPic.png");
QuadBackgroundComponent qC= new QuadBackgroundComponent(txt);
attrs.set("background",qC);
While refreshing the Listbox all I have to do is
if (cell == the correct cell) {
existing = new Button("", new ElementId("exit").child("button"));
else
make sure background is removed and otherwise existing = super.getView(value, selected, existing);
}
But how do I know what is the correct cell ? There is several options as well. First abusing the (String) content of the value and check that out. Or and thats what I thought.
Overwrite protected Panel getListCell( int row, int col, Panel existing )
from Listbox and check that (Array)List from the CellRenderer if it has to draw a picture or just set a text.
→ For that reason I thought I extend Listbox and CustomCellRenderer to not mess around with them (what I could by doing things like if CellRenderer instance of…) for some specific use case
Questions:
If I set that style (for all the possible buttons) how can I remove it from style e.g. on closing the Listbox ?
Is that aproach logical/usefull at all or is there just an easy way