use of com.spinyowl.legui.component.SelectBox in project legui by SpinyOwl.
the class ExampleGui method createSelectBox.
private void createSelectBox() {
SelectBox<Object> selectBox = new SelectBox<>(20, 260, 100, 20);
selectBox.addElement(0.25f);
selectBox.addElement(0.5d);
selectBox.addElement(1);
selectBox.addElement("MyText");
selectBox.addElement(new Long(2L));
selectBox.setVisibleCount(7);
selectBox.setElementHeight(20);
selectBox.addSelectBoxChangeSelectionEventListener((SelectBoxChangeSelectionEventListener<Object>) event -> {
Dialog dialog = new Dialog("SelectBox clicked", 300, 100);
Label valueLabel = new Label("Value: " + event.getNewValue().toString(), 10, 10, 300, 20);
dialog.getContainer().add(valueLabel);
Label classLabel = new Label("Class: " + event.getNewValue().getClass().getName(), 10, 30, 300, 20);
dialog.getContainer().add(classLabel);
dialog.show(event.getFrame());
});
this.add(selectBox);
Button sbb = new Button("Add element", 130, 260, 70, 20);
sbb.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
if (event.getAction() == CLICK) {
selectBox.addElement("Dynamic#" + selectBox.getElements().size());
}
});
this.add(sbb);
}
use of com.spinyowl.legui.component.SelectBox in project legui by SpinyOwl.
the class SelectBoxClickListener method process.
@Override
public void process(MouseClickEvent event) {
SelectBox<T> box = selectBox;
if (event.getAction() == CLICK && selectBox.isEnabled()) {
Frame frame = event.getFrame();
SelectBox.SelectBoxLayer selectBoxLayer = box.getSelectBoxLayer();
boolean collapsed = box.isCollapsed();
box.setCollapsed(!collapsed);
if (collapsed) {
Vector2f layerSize = new Vector2f(frame.getContainer().getSize());
selectBoxLayer.setSize(layerSize);
frame.addLayer(selectBoxLayer);
} else {
frame.removeLayer(selectBoxLayer);
}
}
}
use of com.spinyowl.legui.component.SelectBox in project legui by SpinyOwl.
the class SelectBoxAnimation method animate.
/**
* This method used to update animated object. Called by animator every frame. Removed from
* animator and stops when this method returns true. <p> Returns true if animation is finished and
* could be removed from animator.
*
* @param delta delta time (from previous call).
* @return true if animation is finished and could be removed from animator.
*/
@Override
protected boolean animate(double delta) {
SelectBox selectBox = this.selectBox.get();
SelectBoxScrollablePanel selectionListPanel = this.selectionListPanel.get();
if (selectBox == null || selectionListPanel == null) {
return true;
}
if (selectBox.isCollapsed()) {
return false;
}
deltaSum += delta;
if (deltaSum < 0.01d) {
return false;
}
float buttonWidth = selectBox.getButtonWidth();
selectionListPanel.getVerticalScrollBar().getStyle().setMaxWidth(buttonWidth);
selectionListPanel.getVerticalScrollBar().getStyle().setMaxWidth(buttonWidth);
int visibleCount = Math.min(selectBox.getVisibleCount(), selectBox.getElements().size());
float elementHeight = selectBox.getElementHeight();
Vector2f size = selectBox.getSize();
Vector2f wsize = new Vector2f(size.x, visibleCount * elementHeight);
Vector2f wpos = new Vector2f();
Vector2f sbPos = selectBox.getAbsolutePosition();
Vector2f pSize = selectBox.getSelectBoxLayer().getSize();
if (sbPos.y + wsize.y + size.y > pSize.y && sbPos.y - wsize.y > 0) {
wpos.set(sbPos.x, sbPos.y - wsize.y);
} else {
wpos.set(sbPos.x, sbPos.y + size.y);
}
selectionListPanel.setSize(wsize);
selectionListPanel.setPosition(wpos);
selectionListPanel.getContainer().getSize().y = selectionListPanel.getContainer().count() * elementHeight;
selectionListPanel.getContainer().getSize().x = size.x - selectionListPanel.getVerticalScrollBar().getSize().x;
deltaSum = 0;
return false;
}
use of com.spinyowl.legui.component.SelectBox in project legui by SpinyOwl.
the class SelectBoxFocusListener method process.
@Override
public void process(FocusEvent event) {
if (!event.isFocused() && !selectBox.isCollapsed() && selectBox.isEnabled()) {
boolean collapse = true;
Component nextFocus = event.getNextFocus();
for (SelectBox<T>.SelectBoxElement<T> selectBoxElement : selectBox.getSelectBoxElements()) {
if (nextFocus == selectBoxElement) {
collapse = false;
}
}
if (nextFocus == selectBox.getExpandButton() || nextFocus == selectBox.getSelectionButton() || nextFocus == selectBox.getSelectionListPanel() || nextFocus == selectBox.getSelectionListPanel().getVerticalScrollBar()) {
collapse = false;
}
if (selectBox.isCollapsed() != collapse) {
selectBox.setCollapsed(collapse);
event.getFrame().removeLayer(selectBox.getSelectBoxLayer());
}
}
}
Aggregations