mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Cleanup filters layout
This commit is contained in:
@@ -112,10 +112,10 @@ public class FDeckChooser extends FScreen {
|
||||
float fieldHeight = cmbDeckTypes.getHeight();
|
||||
|
||||
cmbDeckTypes.setBounds(x, y, width, fieldHeight);
|
||||
y += cmbDeckTypes.getHeight() + PADDING;
|
||||
lstDecks.setBounds(x, y, width, height - y - fieldHeight - 2 * PADDING); //leave room for buttons at bottom
|
||||
y += cmbDeckTypes.getHeight() + 1;
|
||||
lstDecks.setBounds(x, y, width, height - y - fieldHeight - PADDING); //leave room for buttons at bottom
|
||||
|
||||
y = height - fieldHeight - PADDING;
|
||||
y += lstDecks.getHeight();
|
||||
float buttonWidth = (width - PADDING) / 2;
|
||||
btnViewDeck.setBounds(x, y, buttonWidth, fieldHeight);
|
||||
x += buttonWidth + PADDING;
|
||||
|
||||
@@ -31,13 +31,11 @@ import forge.itemmanager.views.ItemView;
|
||||
import forge.menu.FMenuItem;
|
||||
import forge.menu.FPopupMenu;
|
||||
import forge.menu.FSubMenu;
|
||||
import forge.toolbox.FCheckBox;
|
||||
import forge.toolbox.FContainer;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
import forge.toolbox.FEvent.FEventType;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FTextField;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.LayoutHelper;
|
||||
@@ -62,10 +60,6 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
private final Class<T> genericType;
|
||||
private ItemManagerConfig config;
|
||||
|
||||
private final FCheckBox chkEnableFilters = new FCheckBox();
|
||||
|
||||
private final FTextField txtFilterLogic = new FTextField();
|
||||
|
||||
private final ItemFilter<? extends T> mainSearchFilter;
|
||||
|
||||
private final FLabel btnFilters = new FLabel.ButtonBuilder()
|
||||
@@ -132,28 +126,7 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
views.get(i).initialize(i);
|
||||
}
|
||||
|
||||
//build enable filters checkbox
|
||||
chkEnableFilters.setText("(*)");
|
||||
chkEnableFilters.setSelected(true);
|
||||
chkEnableFilters.setCommand(new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
lockFiltering = true;
|
||||
boolean enabled = chkEnableFilters.isSelected();
|
||||
for (ItemFilter<? extends T> filter : orderedFilters) {
|
||||
filter.setEnabled(enabled);
|
||||
}
|
||||
txtFilterLogic.setEnabled(enabled);
|
||||
mainSearchFilter.setEnabled(enabled);
|
||||
mainSearchFilter.updateEnabled(); //need to call updateEnabled since no listener for filter checkbox
|
||||
lockFiltering = false;
|
||||
applyFilters();
|
||||
}
|
||||
});
|
||||
|
||||
//build display
|
||||
add(chkEnableFilters);
|
||||
add(txtFilterLogic);
|
||||
add(mainSearchFilter.getWidget());
|
||||
add(btnFilters);
|
||||
add(lblCaption);
|
||||
@@ -215,7 +188,6 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
addItem(new FMenuItem("Show Filters", cmdHideFilters));
|
||||
}
|
||||
else {
|
||||
addMenu.setEnabled(mainSearchFilter.isEnabled());
|
||||
addItem(addMenu);
|
||||
addItem(new FMenuItem("Reset Filters", cmdResetFilters));
|
||||
addItem(new FMenuItem("Hide Filters", cmdHideFilters));
|
||||
@@ -303,26 +275,16 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
|
||||
@Override
|
||||
public void doLayout(float width, float height) {
|
||||
LayoutHelper helper = new LayoutHelper(this);
|
||||
float fieldHeight = txtFilterLogic.getHeight();
|
||||
LayoutHelper helper = new LayoutHelper(this, 3, 0);
|
||||
float fieldHeight = ItemFilter.PANEL_HEIGHT;
|
||||
if (!hideFilters) {
|
||||
int number = 0;
|
||||
StringBuilder logicBuilder = new StringBuilder();
|
||||
for (ItemFilter<? extends T> filter : orderedFilters) {
|
||||
filter.setNumber(++number);
|
||||
logicBuilder.append(number + "&");
|
||||
helper.fillLine(filter.getPanel(), ItemFilter.PANEL_HEIGHT);
|
||||
helper.newLine();
|
||||
}
|
||||
txtFilterLogic.setText(logicBuilder.toString());
|
||||
helper.newLine();
|
||||
helper.include(chkEnableFilters, 41, fieldHeight);
|
||||
helper.offset(-1, 0); //ensure widgets line up
|
||||
helper.include(txtFilterLogic, txtFilterLogic.getAutoSizeWidth(), fieldHeight);
|
||||
helper.fillLine(mainSearchFilter.getWidget(), ItemFilter.PANEL_HEIGHT);
|
||||
helper.newLine(-3);
|
||||
}
|
||||
helper.newLine();
|
||||
helper.offset(1, 0); //align filters button with expand/collapse all button
|
||||
helper.include(btnFilters, 61, fieldHeight);
|
||||
float captionWidth = lblCaption.getAutoSizeBounds().width;
|
||||
float ratioWidth = lblRatio.getAutoSizeBounds().width;
|
||||
@@ -811,7 +773,7 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
|
||||
List<Predicate<? super T>> predicates = new ArrayList<Predicate<? super T>>();
|
||||
for (ItemFilter<? extends T> filter : orderedFilters) { //TODO: Support custom filter logic
|
||||
if (filter.isEnabled() && !filter.isEmpty()) {
|
||||
if (!filter.isEmpty()) {
|
||||
predicates.add(filter.buildPredicate(genericType));
|
||||
}
|
||||
}
|
||||
@@ -862,8 +824,6 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
for (ItemFilter<? extends T> filter : orderedFilters) {
|
||||
filter.getPanel().setVisible(visible);
|
||||
}
|
||||
chkEnableFilters.setVisible(visible);
|
||||
txtFilterLogic.setVisible(visible);
|
||||
mainSearchFilter.getWidget().setVisible(visible);
|
||||
|
||||
if (initialized) {
|
||||
@@ -890,18 +850,11 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
||||
public void resetFilters() {
|
||||
lockFiltering = true; //prevent updating filtering from this change until all filters reset
|
||||
for (ItemFilter<? extends T> filter : orderedFilters) {
|
||||
filter.setEnabled(true);
|
||||
filter.reset();
|
||||
}
|
||||
mainSearchFilter.reset();
|
||||
lockFiltering = false;
|
||||
|
||||
if (mainSearchFilter.isEnabled()) {
|
||||
applyFilters();
|
||||
}
|
||||
else {
|
||||
chkEnableFilters.setSelected(true); //this will apply filters in itemStateChanged handler
|
||||
}
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,58 +3,34 @@ package forge.itemmanager.filters;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FImage;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.itemmanager.ItemManager;
|
||||
import forge.toolbox.FCheckBox;
|
||||
import forge.toolbox.FContainer;
|
||||
import forge.toolbox.FDisplayObject;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.toolbox.FTextField;
|
||||
import forge.util.LayoutHelper;
|
||||
|
||||
|
||||
public abstract class ItemFilter<T extends InventoryItem> {
|
||||
public final static float PANEL_HEIGHT = 28;
|
||||
private static final float REMOVE_BUTTON_SIZE = 17;
|
||||
private final static float PADDING = 3;
|
||||
private static final float PADDING = 3;
|
||||
public static final int DEFAULT_FONT_SIZE = 11;
|
||||
public static final float PANEL_HEIGHT = FTextField.getDefaultHeight(DEFAULT_FONT_SIZE) + 2 * PADDING;
|
||||
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||
|
||||
protected final ItemManager<? super T> itemManager;
|
||||
private FilterPanel panel;
|
||||
private Widget widget;
|
||||
private final FCheckBox chkEnable = new FCheckBox();
|
||||
private RemoveButton btnRemove;
|
||||
|
||||
protected ItemFilter(ItemManager<? super T> itemManager0) {
|
||||
itemManager = itemManager0;
|
||||
chkEnable.setSelected(true); //enable by default
|
||||
}
|
||||
|
||||
public FilterPanel getPanel() {
|
||||
if (panel == null) {
|
||||
panel = new FilterPanel();
|
||||
|
||||
chkEnable.setCommand(new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
updateEnabled();
|
||||
applyChange();
|
||||
}
|
||||
});
|
||||
panel.add(chkEnable);
|
||||
|
||||
getWidget(); //initialize widget
|
||||
if (!isEnabled()) {
|
||||
updateEnabled();
|
||||
}
|
||||
panel.add(widget);
|
||||
|
||||
btnRemove = new RemoveButton();
|
||||
panel.add(btnRemove);
|
||||
panel.add(getWidget());
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
@@ -77,25 +53,6 @@ public abstract class ItemFilter<T extends InventoryItem> {
|
||||
return getWidget();
|
||||
}
|
||||
|
||||
public void setNumber(int number) {
|
||||
chkEnable.setText("(" + number + ")");
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return chkEnable.isSelected();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled0) {
|
||||
chkEnable.setSelected(enabled0);
|
||||
}
|
||||
|
||||
public void updateEnabled() {
|
||||
boolean enabled = isEnabled();
|
||||
for (FDisplayObject child : widget.getChildren()) {
|
||||
child.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyChange() {
|
||||
itemManager.applyFilters();
|
||||
}
|
||||
@@ -143,15 +100,7 @@ public abstract class ItemFilter<T extends InventoryItem> {
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
float x = PADDING;
|
||||
float y = PADDING;
|
||||
float w = width - 2 * PADDING;
|
||||
float h = height - 2 * PADDING;
|
||||
chkEnable.setBounds(x, y, 43, h);
|
||||
x += chkEnable.getWidth();
|
||||
widget.setBounds(x, y, w - REMOVE_BUTTON_SIZE - x, h);
|
||||
x += widget.getWidth();
|
||||
btnRemove.setBounds(x, y, REMOVE_BUTTON_SIZE, height);
|
||||
widget.setBounds(0, PADDING, width, height - 2 * PADDING);
|
||||
}
|
||||
|
||||
public void drawOverlay(Graphics g) {
|
||||
@@ -170,50 +119,4 @@ public abstract class ItemFilter<T extends InventoryItem> {
|
||||
doWidgetLayout(helper);
|
||||
}
|
||||
}
|
||||
|
||||
private class RemoveButton extends FLabel {
|
||||
private RemoveButton() {
|
||||
super(new FLabel.Builder()
|
||||
.command(new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
itemManager.removeFilter(ItemFilter.this);
|
||||
}
|
||||
}));
|
||||
setIcon(new RemoveIcon());
|
||||
}
|
||||
|
||||
private class RemoveIcon implements FImage {
|
||||
@Override
|
||||
public float getWidth() {
|
||||
return REMOVE_BUTTON_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return REMOVE_BUTTON_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(forge.Forge.Graphics g, float x, float y, float w, float h) {
|
||||
float thickness = 2;
|
||||
float offset = 4;
|
||||
float x1 = offset;
|
||||
float y1 = offset;
|
||||
float x2 = w - offset - 1;
|
||||
float y2 = h - offset - 1;
|
||||
|
||||
if (!RemoveButton.this.isPressed()) {
|
||||
g.setAlphaComposite(0.6f);
|
||||
}
|
||||
|
||||
g.drawLine(thickness, FORE_COLOR, x1, y1, x2, y2);
|
||||
g.drawLine(thickness, FORE_COLOR, x2, y1, x1, y2);
|
||||
|
||||
if (!RemoveButton.this.isPressed()) {
|
||||
g.resetAlphaComposite();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class ToggleButtonsFilter<T extends InventoryItem> extends ItemF
|
||||
protected void doWidgetLayout(LayoutHelper helper) {
|
||||
float availableWidth = helper.getParentWidth() - (buttons.size() - 1) * (helper.getGapX() - 1); //account for gaps
|
||||
float buttonWidth = availableWidth / buttons.size();
|
||||
float buttonHeight = helper.getParentHeight() - 2 * helper.getGapY();
|
||||
float buttonHeight = helper.getParentHeight();
|
||||
|
||||
for (FLabel btn : buttons) {
|
||||
helper.include(btn, buttonWidth, buttonHeight);
|
||||
@@ -72,8 +72,7 @@ public abstract class ToggleButtonsFilter<T extends InventoryItem> extends ItemF
|
||||
|
||||
private ToggleButton(FImage icon) {
|
||||
super(new FLabel.Builder()
|
||||
.icon(icon).iconScaleAuto(false)
|
||||
.fontSize(11)
|
||||
.icon(icon).fontSize(11).iconScaleFactor(0.9f)
|
||||
.selectable(true).selected(true)
|
||||
.command(new FEventHandler() {
|
||||
@Override
|
||||
|
||||
@@ -144,6 +144,10 @@ public class FLabel extends FDisplayObject implements IButton {
|
||||
command = command0;
|
||||
}
|
||||
|
||||
public float getAlphaComposite() {
|
||||
return alphaComposite;
|
||||
}
|
||||
|
||||
public boolean isPressed() {
|
||||
return pressed;
|
||||
}
|
||||
@@ -205,7 +209,7 @@ public class FLabel extends FDisplayObject implements IButton {
|
||||
float h = getHeight();
|
||||
|
||||
g.startClip(0, 0, w, h); //start clip to ensure nothing escapes bounds
|
||||
|
||||
|
||||
boolean applyAlphaComposite = (opaque && !pressed);
|
||||
if (applyAlphaComposite) {
|
||||
g.setAlphaComposite(alphaComposite);
|
||||
|
||||
@@ -91,7 +91,7 @@ public final class LayoutHelper {
|
||||
public void include(final FDisplayObject obj, float width, float height) {
|
||||
if (width <= 0 || height <= 0) { return; }
|
||||
|
||||
if (x + width > parentWidth) {
|
||||
if (x + width > parentWidth + 1) { //+1 to avoid wrapping from rounding error
|
||||
newLine();
|
||||
if (width > parentWidth) {
|
||||
width = parentWidth;
|
||||
|
||||
Reference in New Issue
Block a user