mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Improve multi-select list appearance
Optimize list item tap and render logic by passing index as parameter
This commit is contained in:
@@ -34,6 +34,7 @@ import forge.toolbox.FCheckBox;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
import forge.toolbox.FList;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -275,8 +276,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(Entry<T, Integer> value, float x, float y, int count) {
|
||||
Integer index = list.getIndexOf(value);
|
||||
public boolean tap(Integer index, Entry<T, Integer> value, float x, float y, int count) {
|
||||
if (allowMultipleSelections) {
|
||||
if (selectedIndices.contains(index)) {
|
||||
selectedIndices.remove(index);
|
||||
@@ -299,7 +299,18 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, Entry<T, Integer> value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
public void drawValue(Graphics g, Integer index, Entry<T, Integer> value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
if (allowMultipleSelections) {
|
||||
if (pressed) { //if multi-select mode, draw SEL_COLOR when pressed
|
||||
g.fillRect(SEL_COLOR, x - FList.PADDING, y - FList.PADDING, w + 2 * FList.PADDING, h + 2 * FList.PADDING);
|
||||
}
|
||||
//draw checkbox, with it checked based on whether item is selected
|
||||
float checkBoxSize = h / 2;
|
||||
float padding = checkBoxSize / 2;
|
||||
w -= checkBoxSize + padding;
|
||||
FCheckBox.drawCheckBox(g, selectedIndices.contains(index), x + w, y + padding, checkBoxSize, checkBoxSize);
|
||||
w -= padding;
|
||||
}
|
||||
renderer.drawValue(g, value, font, foreColor, pressed, x + 1, y, w - 2, h); //x + 1 and w - 2 to account for left and right borders
|
||||
}
|
||||
});
|
||||
@@ -321,8 +332,8 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
@Override
|
||||
protected FSkinColor getItemFillColor(int index) {
|
||||
if (selectedIndices.contains(index)) {
|
||||
return SEL_COLOR;
|
||||
if (!allowMultipleSelections && selectedIndices.contains(index)) {
|
||||
return SEL_COLOR; //don't show SEL_COLOR if in multi-select mode
|
||||
}
|
||||
if (index % 2 == 1) {
|
||||
return ALT_ROW_COLOR;
|
||||
|
||||
@@ -1053,13 +1053,13 @@ public class ConstructedScreen extends LaunchScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(Variant value, float x, float y, int count) {
|
||||
public boolean tap(Integer index, Variant value, float x, float y, int count) {
|
||||
value.toggle();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, Variant value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
public void drawValue(Graphics g, Integer index, Variant value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
String text = value.gameType.toString();
|
||||
float totalHeight = h;
|
||||
h = font.getMultiLineBounds(text).height + 5;
|
||||
|
||||
@@ -81,13 +81,13 @@ public class FilesPage extends TabPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(FilesItem value, float x, float y, int count) {
|
||||
public boolean tap(Integer index, FilesItem value, float x, float y, int count) {
|
||||
value.select();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, FilesItem value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
public void drawValue(Graphics g, Integer index, FilesItem value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
float offset = w * SettingsScreen.INSETS_FACTOR - FList.PADDING; //increase padding for settings items
|
||||
x += offset;
|
||||
y += offset;
|
||||
|
||||
@@ -268,7 +268,7 @@ public class SettingsPage extends TabPage {
|
||||
lstOptions = add(new FList<String>(options));
|
||||
lstOptions.setListItemRenderer(new FList.DefaultListItemRenderer<String>() {
|
||||
@Override
|
||||
public boolean tap(String value, float x, float y, int count) {
|
||||
public boolean tap(Integer index, String value, float x, float y, int count) {
|
||||
if (!value.equals(currentValue)) {
|
||||
valueChanged(value);
|
||||
}
|
||||
@@ -277,7 +277,7 @@ public class SettingsPage extends TabPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, String value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
public void drawValue(Graphics g, Integer index, String value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
float offset = w * SettingsScreen.INSETS_FACTOR - FList.PADDING; //increase padding for settings items
|
||||
x += offset;
|
||||
y += offset;
|
||||
@@ -316,13 +316,13 @@ public class SettingsPage extends TabPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(Setting value, float x, float y, int count) {
|
||||
public boolean tap(Integer index, Setting value, float x, float y, int count) {
|
||||
value.select();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, Setting value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
public void drawValue(Graphics g, Integer index, Setting value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
float offset = w * SettingsScreen.INSETS_FACTOR - FList.PADDING; //increase padding for settings items
|
||||
x += offset;
|
||||
y += offset;
|
||||
|
||||
@@ -365,8 +365,7 @@ public class DualListBox<T> extends FDialog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(T value, float x, float y, int count) {
|
||||
Integer index = ChoiceList.this.getIndexOf(value);
|
||||
public boolean tap(Integer index, T value, float x, float y, int count) {
|
||||
selectedIndices.clear();
|
||||
selectedIndices.add(index);
|
||||
if (renderer.tap(value, x, y, count)) {
|
||||
@@ -379,7 +378,7 @@ public class DualListBox<T> extends FDialog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
public void drawValue(Graphics g, Integer index, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
renderer.drawValue(g, value, font, foreColor, pressed, x, y, w, h);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ public class FCheckBox extends FLabel {
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g, float x, float y, float w, float h) {
|
||||
drawCheckBox(g, BOX_COLOR, CHECK_COLOR, isSelected(), x, y, w, h);
|
||||
drawCheckBox(g, isSelected(), x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ public class FCheckBox extends FLabel {
|
||||
drawContent(g, getWidth(), getHeight(), false);
|
||||
}
|
||||
|
||||
public static void drawCheckBox(Graphics g, boolean isChecked, float x, float y, float w, float h) {
|
||||
drawCheckBox(g, BOX_COLOR, CHECK_COLOR, isChecked, x, y, w, h);
|
||||
}
|
||||
public static void drawCheckBox(Graphics g, FSkinColor boxColor, FSkinColor checkColor, boolean isChecked, float x, float y, float w, float h) {
|
||||
g.drawRect(Utils.scaleMin(1), boxColor, x, y, w, h);
|
||||
if (isChecked) {
|
||||
|
||||
@@ -243,7 +243,7 @@ public class FGroupList<E> extends FScrollPane {
|
||||
}
|
||||
|
||||
public boolean tap(float x, float y, int count) {
|
||||
return renderer.tap(value, x, y, count);
|
||||
return renderer.tap(-1, value, x, y, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -256,7 +256,7 @@ public class FGroupList<E> extends FScrollPane {
|
||||
g.fillRect(fillColor, 0, 0, w, h);
|
||||
}
|
||||
|
||||
renderer.drawValue(g, value, font, FList.FORE_COLOR, pressed, FList.PADDING, FList.PADDING, w - 2 * FList.PADDING, h - 2 * FList.PADDING);
|
||||
renderer.drawValue(g, -1, value, font, FList.FORE_COLOR, pressed, FList.PADDING, FList.PADDING, w - 2 * FList.PADDING, h - 2 * FList.PADDING);
|
||||
|
||||
if (drawLineSeparators()) {
|
||||
g.drawLine(1, FList.LINE_COLOR, 0, h, w, h);
|
||||
|
||||
@@ -135,7 +135,7 @@ public class FList<E> extends FScrollPane implements Iterable<E> {
|
||||
E item = getItemAt(index);
|
||||
if (item == null) { return false; }
|
||||
|
||||
return renderer.tap(item, x, y - getItemTop(index), count);
|
||||
return renderer.tap(index, item, x, y - getItemTop(index), count);
|
||||
}
|
||||
|
||||
private float getItemTop(int index) {
|
||||
@@ -187,7 +187,7 @@ public class FList<E> extends FScrollPane implements Iterable<E> {
|
||||
g.fillRect(fillColor, 0, y, w, itemHeight);
|
||||
}
|
||||
|
||||
renderer.drawValue(g, items.get(i), font, FORE_COLOR, pressedIndex == i, PADDING, y + PADDING, valueWidth, valueHeight);
|
||||
renderer.drawValue(g, i, items.get(i), font, FORE_COLOR, pressedIndex == i, PADDING, y + PADDING, valueWidth, valueHeight);
|
||||
|
||||
y += itemHeight;
|
||||
|
||||
@@ -214,8 +214,8 @@ public class FList<E> extends FScrollPane implements Iterable<E> {
|
||||
|
||||
public static abstract class ListItemRenderer<V> {
|
||||
public abstract float getItemHeight();
|
||||
public abstract boolean tap(V value, float x, float y, int count);
|
||||
public abstract void drawValue(Graphics g, V value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h);
|
||||
public abstract boolean tap(Integer index, V value, float x, float y, int count);
|
||||
public abstract void drawValue(Graphics g, Integer index, V value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h);
|
||||
}
|
||||
|
||||
public static class DefaultListItemRenderer<V> extends ListItemRenderer<V> {
|
||||
@@ -225,12 +225,12 @@ public class FList<E> extends FScrollPane implements Iterable<E> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(V value, float x, float y, int count) {
|
||||
public boolean tap(Integer index, V value, float x, float y, int count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, V value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
public void drawValue(Graphics g, Integer index, V value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
g.drawText(value.toString(), font, color, x, y, w, h, false, HAlignment.LEFT, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,8 +378,7 @@ public class ListChooser<T> extends FContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(T value, float x, float y, int count) {
|
||||
Integer index = ChoiceList.this.getIndexOf(value);
|
||||
public boolean tap(Integer index, T value, float x, float y, int count) {
|
||||
if (allowMultipleSelections) {
|
||||
if (selectedIndices.contains(index)) {
|
||||
selectedIndices.remove(index);
|
||||
@@ -403,7 +402,18 @@ public class ListChooser<T> extends FContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
public void drawValue(Graphics g, Integer index, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
if (allowMultipleSelections) {
|
||||
if (pressed) { //if multi-select mode, draw SEL_COLOR when pressed
|
||||
g.fillRect(SEL_COLOR, x - FList.PADDING, y - FList.PADDING, w + 2 * FList.PADDING, h + 2 * FList.PADDING);
|
||||
}
|
||||
//draw checkbox, with it checked based on whether item is selected
|
||||
float checkBoxSize = h / 2;
|
||||
float padding = checkBoxSize / 2;
|
||||
w -= checkBoxSize + padding;
|
||||
FCheckBox.drawCheckBox(g, selectedIndices.contains(index), x + w, y + padding, checkBoxSize, checkBoxSize);
|
||||
w -= padding;
|
||||
}
|
||||
renderer.drawValue(g, value, font, foreColor, pressed, x, y, w, h);
|
||||
}
|
||||
});
|
||||
@@ -422,8 +432,8 @@ public class ListChooser<T> extends FContainer {
|
||||
|
||||
@Override
|
||||
protected FSkinColor getItemFillColor(int index) {
|
||||
if (selectedIndices.contains(index)) {
|
||||
return SEL_COLOR;
|
||||
if (!allowMultipleSelections && selectedIndices.contains(index)) {
|
||||
return SEL_COLOR; //don't show SEL_COLOR if in multi-select mode
|
||||
}
|
||||
if (index % 2 == 1) {
|
||||
return ALT_ITEM_COLOR;
|
||||
|
||||
Reference in New Issue
Block a user