-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
584e74c
commit 45a6f3d
Showing
9 changed files
with
202 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# Done to increase the memory available to gradle. | ||
org.gradle.jvmargs=-Xmx2G | ||
|
||
minecraft_version=1.21.2-rc1 | ||
yalmm_mappings=4 | ||
minecraft_version=1.21.2 | ||
yalmm_mappings=7 | ||
loader_version=0.16.7 | ||
|
||
# Mod Properties | ||
mod_version=6.0.1+1.21.2 | ||
mod_version=6.1.0 | ||
maven_group=dev.lambdaurora | ||
archives_base_name=spruceui | ||
|
||
# Dependencies | ||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api | ||
fabric_api_version=0.106.0+1.21.2 | ||
fabric_api_version=0.106.1+1.21.2 | ||
modmenu_version=12.0.0-beta.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidgetBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright © 2024 LambdAurora <[email protected]> | ||
* | ||
* This file is part of SpruceUI. | ||
* | ||
* Licensed under the MIT license. For more information, | ||
* see the LICENSE file. | ||
*/ | ||
|
||
package dev.lambdaurora.spruceui.widget.text; | ||
|
||
import dev.lambdaurora.spruceui.Position; | ||
import net.minecraft.network.chat.Text; | ||
import net.minecraft.util.FormattedCharSequence; | ||
|
||
import java.util.Objects; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Consumer; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Represents a text field widget builder. | ||
* | ||
* @author LambdAurora | ||
* @version 6.1.0 | ||
* @since 6.1.0 | ||
*/ | ||
public class SpruceTextFieldWidgetBuilder { | ||
private final Position position; | ||
private final int width; | ||
private final int height; | ||
private Text title; | ||
private Text placeholder; | ||
private Consumer<String> onChange; | ||
private Predicate<String> textPredicate; | ||
private BiFunction<String, Integer, FormattedCharSequence> renderTextProvider; | ||
|
||
public SpruceTextFieldWidgetBuilder(Position position, int width, int height) { | ||
this.position = position; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public SpruceTextFieldWidgetBuilder title(Text title) { | ||
this.title = title; | ||
return this; | ||
} | ||
|
||
public SpruceTextFieldWidgetBuilder placeholder() { | ||
this.placeholder = this.title; | ||
return this; | ||
} | ||
|
||
public SpruceTextFieldWidgetBuilder placeholder(Text placeholder) { | ||
this.placeholder = placeholder; | ||
return this; | ||
} | ||
|
||
public SpruceTextFieldWidgetBuilder onChange(Consumer<String> onChange) { | ||
this.onChange = onChange; | ||
return this; | ||
} | ||
|
||
public SpruceTextFieldWidgetBuilder textPredicate(Predicate<String> textPredicate) { | ||
this.textPredicate = textPredicate; | ||
return this; | ||
} | ||
|
||
public SpruceTextFieldWidgetBuilder renderTextProvider(BiFunction<String, Integer, FormattedCharSequence> renderTextProvider) { | ||
this.renderTextProvider = renderTextProvider; | ||
return this; | ||
} | ||
|
||
public SpruceTextFieldWidget build() { | ||
Objects.requireNonNull(this.title, "Text fields require a title."); | ||
var widget = new SpruceTextFieldWidget(this.position, this.width, this.height, this.title, this.placeholder); | ||
if (this.onChange != null) widget.setChangedListener(this.onChange); | ||
if (this.textPredicate != null) widget.setTextPredicate(this.textPredicate); | ||
if (this.renderTextProvider != null) widget.setRenderTextProvider(this.renderTextProvider); | ||
return widget; | ||
} | ||
|
||
public SpruceNamedTextFieldWidget buildNamed() { | ||
return new SpruceNamedTextFieldWidget(this.build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters