jMonkeyEngine-Contributions / Lemur

Lemur is a jMonkeyEngine-based UI toolkit.
http://jmonkeyengine-contributions.github.io/Lemur/
BSD 3-Clause "New" or "Revised" License
116 stars 33 forks source link

DefaultCellRenderer ElementId #108

Open Aufricer opened 2 years ago

Aufricer commented 2 years ago

Hi PSpeed,

I am trying to write a custom CellRenderer. That right now is nothing except public class Picture_Renderer<T> extends DefaultCellRenderer {}

That in DefaulCellRenderer calls public DefaultCellRenderer() { //this(new ElementId(Button.ELEMENT_ID), Styles.ROOT_STYLE, null); // I believe the above is a mistake as we should be using the default // style if none is specified. It is a change in behavior, though. // 2020-11-27 this(new ElementId(Button.ELEMENT_ID), null, null); }

setting the Element_ID to "button" In Listbox , during making of the Element it calls

if( cellRenderer == null ) { // Create a default one cellRenderer = new DefaultCellRenderer<>(baseElementId.child("item"), style); } else { **cellRenderer.configureStyle(baseElementId.child("item"), style);** } where it should set the elementID to list.item (what it is doing with the default one)

But unfort. in defaultCellRenderer it never overwrites the elementID as it is not null

@Override public void configureStyle( ElementId elementId, String style ) { if( this.elementId == null ) { this.elementId = elementId; } if( this.style == null ) { this.style = style; } }

Due to the "wrong" elementID there can be issues with the styling grafik --> See the cells have an own "visible" background while usually they dont grafik

So - I will get around that but maybe it should be considered to either change the elementID in the constructor (why is it Button ?) or change the behaviour of public void configureStyle( ElementId elementId, String style ) to always let it set the style (do you mean if(!( this.elementId == null )) insteadt of if( this.elementId == null ) ?

pspeed42 commented 2 years ago

configureStyle() should only change the style if the user hasn't already specified one. If the user specifies their own style then it is assumed to be better than one that the list box would force.

Most subclasses should use a real super constructor and not rely on the default. But for code that did rely on the default constructor, I could not lightly change the behavior for any code that was relying on it. Prior to list box enforcing its own child styles (like list item) listbox items were buttons by default. (In fact, that's what DefaultCellRenderer is creating in get view.)

When creating your own DefaultCellRenderer subclass, either specify the element ID you want or call the super constructor with null: super(null, null) ...then you will inherit the list's styling for items.

Note: it is also fine to ask these sorts of questions on the jMonkeyEngine forum if you like. Sometimes these messages get lost in the github spam and I don't see them until late. (I was lucky this time. :) )

Aufricer commented 2 years ago

I will probably do. But as it is/was special usecases I am sometimes not sure it belongs to forum