Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package powerlessri.harmonics.gui.widget;
- import com.google.common.base.Preconditions;
- import powerlessri.harmonics.gui.ITexture;
- import powerlessri.harmonics.gui.Texture;
- import powerlessri.harmonics.gui.widget.button.ColoredTextButton;
- import powerlessri.harmonics.gui.widget.button.SimpleIconButton;
- import powerlessri.harmonics.gui.widget.button.TextButton;
- import powerlessri.harmonics.gui.widget.panel.Panel;
- import powerlessri.harmonics.gui.widget.panel.VerticalList;
- public class TextDropdown extends Dropdown<IWidget, Panel<IWidget>, VerticalList<ColoredTextButton>> {
- public static final ITexture TOGGLE_TO_EXPAND = Texture.portion();
- public static final ITexture TOGGLE_TO_EXPAND_HOVERED = Texture.portion();
- public static final ITexture TOGGLE_TO_COLLAPSE = Texture.portion();
- public static final ITexture TOGGLE_TO_COLLAPSE_HOVERED = Texture.portion();
- private TextField textField;
- public TextDropdown(int width, int height) {
- this(width, height, height * 8);
- }
- public TextDropdown(int width, int height, int listHeight) {
- super(new Panel<IWidget>() {
- {
- this.setDimensions(width, height);
- }
- @Override
- public void onInitialAttach() {
- TextDropdown parent = (TextDropdown) this.getParent();
- Preconditions.checkState(parent != null);
- this.addChildren(new TextField(width, height));
- SimpleIconButton toggle = new SimpleIconButton(TOGGLE_TO_EXPAND, TOGGLE_TO_EXPAND_HOVERED);
- toggle.setClickAction(b -> {
- parent.toggle();
- if (parent.isExpanded()) {
- toggle.setTextures(TOGGLE_TO_COLLAPSE, TOGGLE_TO_COLLAPSE_HOVERED);
- } else {
- toggle.setTextures(TOGGLE_TO_EXPAND, TOGGLE_TO_EXPAND_HOVERED);
- }
- });
- toggle.alignRight(getXRight());
- this.addChildren(toggle);
- }
- }, new VerticalList<>(width, listHeight));
- this.setBackgroundRenderer(0, IBackgroundRenderer.NOTHING);
- textField = (TextField) getLabel().getPanels().get(0);
- }
- public void addOption(String option) {
- getPanel().addChildren(ColoredTextButton.ofText(option, b -> {
- textField.setText(option);
- toggle();
- }));
- }
- public TextField getTextField() {
- return textField;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement