Skip to content

Commit

Permalink
Finished docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmeowry committed May 25, 2023
1 parent f57cb9b commit af3b9d3
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import space.maxus.flare.ui.Composable;
Expand All @@ -15,14 +16,30 @@

import java.util.*;

/**
* A composition is a collection of multiple components, composed by relative coordinates.
* <br />
* See more in Flare docs: <a href="https://flare.maxus.space/ui/composable#composition">Composition</a>
*/
public interface Composition extends Composable, Configurable<Composition> {
/**
* Constructs a composition out of an array of packed composables
* @param comps Composable elements to be included
* @return A new composition
* @see space.maxus.flare.ui.ComposableLike#inside(ComposableSpace)
*/
@Contract("_ -> new")
static @NotNull Composition of(PackedComposable... comps) {
return new ExplicitComposition(Arrays.asList(comps));
}

@ApiStatus.Internal
List<PackedComposable> fitIn(ComposableSpace space);

/**
* Returns all composable elements inside this composition
* @return All composable elements inside this composition
*/
List<PackedComposable> children();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import space.maxus.flare.item.ItemProvider;
import space.maxus.flare.ui.Composable;
Expand All @@ -17,26 +18,76 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

/**
* A modal is a composable that opens an inner frame on click.
* <br />
* See more in Flare docs: <a href="https://flare.maxus.space/ui/composable#modal">Modal</a>
*
* @see Modals
*/
public interface Modal extends ProviderRendered, Configurable<Modal>, Disable {
/**
* Constructs a new modal
* @param provider Item provider for modal
* @param dimensions Dimensions of the modal window
* @param initializer The modal frame configurator
* @return A new modal
*/
static @NotNull Modal of(@NotNull ItemProvider provider, Dimensions dimensions, Consumer<ModalFrame> initializer) {
return new ModalImpl(provider, "A Flare Modal", initializer, dimensions, false);
}

/**
* Constructs a new modal builder
* @param provider Item provider for this modal
* @return A new modal builder
*/
static @NotNull Builder builder(@NotNull ItemProvider provider) {
return new ModalImpl.Builder(provider);
}

/**
* Returns the frame of this modal
* @return The frame of this modal
*/
ModalFrame getFrame();

/**
* A builder for modals
*/
interface Builder extends ComposableLike {
/**
* Sets the title of the modal frame
* @param title The title of the modal frame
* @return This builder
*/
@NotNull Builder title(@NotNull String title);

/**
* Sets the dimensions of the modal frame
* @param dimensions Dimensions of the modal frame
* @return This builder
*/
@NotNull Builder dimensions(@NotNull Dimensions dimensions);

/**
* Sets the modal frame initializer
* @param initializer The initializer for the modal frame
* @return This builder
*/
@NotNull Builder initializer(@NotNull Consumer<ModalFrame> initializer);

/**
* Disables the modal button
* @param disabled Disabled state
* @return This builder
*/
@NotNull Builder disabled(boolean disabled);

/**
* Builds this modal
* @return Built modal
*/
@NotNull Modal build();

@Override
Expand All @@ -45,11 +96,18 @@ default Composable asComposable() {
}
}

/**
* The modal frame
*/
@EqualsAndHashCode(callSuper = true)
@ToString
abstract class ModalFrame extends PageFrame {
@ApiStatus.Internal
@Getter
protected final AtomicBoolean isClosing = new AtomicBoolean(false);
/**
* The parent modal used
*/
@Getter
protected Modal parent;

Expand All @@ -64,6 +122,7 @@ public void close() {
}
}

@ApiStatus.Internal
record ModalProps(Modal self, Dimensions dimensions, String title, Consumer<ModalFrame> initializer) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,58 @@
import space.maxus.flare.ui.compose.Placeholder;
import space.maxus.flare.ui.space.Slot;

/**
* Contains certain utility modals
*/
@UtilityClass
public class Modals {
/**
* A Yes/No modal
*/
@Builder
public static final class YesNoModal implements ComposableLike {
/**
* The name of the modal
*/
@Builder.Default
private final String name = "Modal";
/**
* The description of the modal button
*/
@Builder.Default
private final String description = "Opens a modal";
/**
* The name of the decline button
*/
@Builder.Default
private final String declineName = "Decline";
/**
* The name of the accept button
*/
@Builder.Default
private final String acceptName = "Accept";
/**
* Handler for when the accept button is clicked
*/
@Builder.Default
private final Runnable onAccept = () -> {
};
/**
* Handler for when the decline button
*/
@Builder.Default
private final Runnable onDecline = () -> {
};
/**
* Extra information in the modal
*/
@Builder.Default
private final @Nullable String extraInformation = null;

/**
* Converts this modal into a modal builder
* @return The modal builder
*/
@SuppressWarnings("ConstantValue")
public Modal.@NotNull Builder asBuilder() {
return yesOrNoModalBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
import space.maxus.flare.ui.page.Pagination;
import space.maxus.flare.util.SafeComputable;

/**
* Pagination display is used to display pagination state.
* <br />
* See more in Flare docs: <a href="https://flare.maxus.space/ui/overview/#pagination-display">PaginationDisplay</a>
*/
public interface PaginationDisplay extends Composable, Configurable<PaginationDisplay> {
/**
* Returns the item builder for arrow forward button
* @param disabled Whether the button is disabled
* @return Item builder
*/
static @NotNull ItemStackBuilder arrowForwardButton(boolean disabled) {
return Items.builder(Material.PLAYER_HEAD)
.hideAllFlags()
Expand All @@ -34,6 +44,11 @@ public interface PaginationDisplay extends Composable, Configurable<PaginationDi
);
}

/**
* Returns the item builder for arrow backward button
* @param disabled Whether the button is disabled
* @return Item builder
*/
static @NotNull ItemStackBuilder arrowBackwardButton(boolean disabled) {
return Items.builder(Material.PLAYER_HEAD)
.hideAllFlags()
Expand All @@ -50,6 +65,14 @@ public interface PaginationDisplay extends Composable, Configurable<PaginationDi
);
}

/**
* Returns the item builder for page select button
* @param frame The page frame
* @param page The index of the page
* @param selected Whether the button is selected
* @param player The player viewer
* @return Item builder
*/
static @NotNull ItemStackBuilder pageNumber(Frame frame, int page, boolean selected, @Nullable Player player) {
return Items.builder(Material.PLAYER_HEAD, player)
.hideAllFlags()
Expand All @@ -69,39 +92,103 @@ public interface PaginationDisplay extends Composable, Configurable<PaginationDi
);
}

/**
* Creates a new pagination display
* @param pagination The pagination used
* @return New pagination display
*/
static @NotNull PaginationDisplay of(Pagination<?> pagination) {
return new PaginationDisplayImpl(pagination, 0, null, null, null, null);
}

/**
* Creates a new pagination display
* @param pagination The pagination used
* @param idx Currently selected page index
* @return New pagination display
*/
static @NotNull PaginationDisplay of(Pagination<?> pagination, int idx) {
return new PaginationDisplayImpl(pagination, 0, null, null, null, null);
}

/**
* Creates a new pagination builder
* @param pagination The pagination to use
* @return A new pagination builder
*/
static @NotNull Builder builder(Pagination<?> pagination) {
return new PaginationDisplayImpl.Builder(pagination);
}

/**
* Gets the current pagination
* @return The currently used pagination
*/
Pagination<?> getPagination();

/**
* Returns the reactive state of the selected page index
* @return The reactive state of the selected page index
*/
ReactiveState<Integer> selectedIndex();

/**
* Returns the reactive state of the selected page frame
* @return The reactive state of the selected page frame
*/
ReactiveState<Frame> selectedFrame();

/**
* Switches to another page index
* @param page Page index to switch to
*/
default void switchPage(int page) {
getPagination().switchPage(viewer(), page);
}

/**
* A pagination display builder
*/
interface Builder extends ComposableLike {
/**
* Sets the currently selected page index
* @param index Index to be set
* @return This builder
*/
@NotNull Builder selectedIndex(int index);

/**
* Sets the back button item provider
* @param back The provider to use
* @return This builder
*/
@NotNull Builder backButton(@Nullable ItemProvider back);

/**
* Sets the forward button item provider
* @param forward The provider to use
* @return This builder
*/
@NotNull Builder forwardButton(@Nullable ItemProvider forward);

/**
* Sets the selected page item builder
* @param page The provider to be set
* @return This builder
*/
@NotNull Builder selectedPage(@Nullable SafeComputable<Pair<Integer, Frame>, ItemStack> page);

/**
* Sets the unselected page item builder
* @param page The provider to be set
* @return This builder
*/
@NotNull Builder unselectedPage(@Nullable SafeComputable<Pair<Integer, Frame>, ItemStack> page);

/**
* Builds this pagination display
* @return Built pagination display
*/
@NotNull PaginationDisplay build();

@Override
Expand Down
Loading

0 comments on commit af3b9d3

Please sign in to comment.