Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
482 commits
Select commit Hold shift + click to select a range
c7ee588
add getStandardStyle and parse standard styles as well as fixing up t…
JXSnack Jul 16, 2025
35547e3
add VRect standard style
JXSnack Jul 16, 2025
13608d9
add TabWidgetStandardStyle
JXSnack Jul 16, 2025
66b401c
add LineInputStandardStyle
JXSnack Jul 16, 2025
d2a5583
add ImageStandardStyle
JXSnack Jul 16, 2025
de81aff
add DropdownStandardStyle
JXSnack Jul 16, 2025
5a82d37
add CheckBoxStandardStyle
JXSnack Jul 16, 2025
f77618a
reorder
JXSnack Jul 16, 2025
8af47fb
add log for registering
JXSnack Jul 16, 2025
9cbe4bc
make reserved not required
JXSnack Jul 16, 2025
a95d2c7
remove unneeded reserve method
JXSnack Jul 16, 2025
1206976
color -> background-color
JXSnack Jul 16, 2025
5d7da03
no longer reserve cursor
JXSnack Jul 16, 2025
2a9e03a
no longer reserve cursor and overlay
JXSnack Jul 16, 2025
d9cd5e0
add TODO
JXSnack Jul 16, 2025
d849567
no more standard overlay
JXSnack Jul 16, 2025
30b6957
import
JXSnack Jul 16, 2025
5909ade
add clear test option
JXSnack Jul 16, 2025
0e4372b
rect color -> background-color
JXSnack Jul 16, 2025
8fdef13
fix crash
JXSnack Jul 16, 2025
52e5834
mold standard registry
JXSnack Jul 16, 2025
fa9a5b0
more elegant solution done
JXSnack Jul 16, 2025
4baa18b
make tab widget font be styled
JXSnack Jul 16, 2025
88d667e
remove redundant argument
JXSnack Jul 16, 2025
ae837db
background-color and background-color-selected are now correctly impl…
JXSnack Jul 16, 2025
e5d96aa
item-spacing-left and item-spacing-right are now correct styles
JXSnack Jul 16, 2025
b8ec545
make font and placeholder-font be proper styles
JXSnack Jul 16, 2025
c976d72
mark padding as deprecated
JXSnack Jul 16, 2025
6eb47fc
line input now uses padding correctly
JXSnack Jul 16, 2025
6beb970
label now uses padding correctly
JXSnack Jul 16, 2025
fb27fca
VDropdown now correctly implements fonts
JXSnack Jul 16, 2025
842a7bd
VDropdown now correctly implements padding
JXSnack Jul 16, 2025
5625c77
allow quick modifications with state
JXSnack Jul 16, 2025
c75db60
fix mixup
JXSnack Jul 16, 2025
70693ae
basic modifiers!
JXSnack Jul 16, 2025
9dfcfac
hover font colors
JXSnack Jul 16, 2025
ca998a6
correct padding
JXSnack Jul 16, 2025
7ff12a1
only change font color when hovered
JXSnack Jul 16, 2025
b35fb8b
add VHasPlaceholderFont
JXSnack Jul 16, 2025
3784d12
use VHasFont
JXSnack Jul 16, 2025
40252de
use VHasFont and VHasPlaceholderFont
JXSnack Jul 16, 2025
fbd116a
removal schedule notice for 1.12
JXSnack Jul 16, 2025
7e0db68
undo removing itemHoverColor and add new notice
JXSnack Jul 16, 2025
fc6c4ac
use correct new itemHoverFont
JXSnack Jul 16, 2025
4c52050
modifyFontColor on label has been generalized and made more idiomatic
JXSnack Jul 16, 2025
45f5159
add linear easing
JXSnack Jul 17, 2025
41f3b91
add base composite
JXSnack Jul 17, 2025
9613b85
add basic pipeline
JXSnack Jul 17, 2025
a3952ea
add basic animation engine
JXSnack Jul 17, 2025
3c0086c
app now has pipeline
JXSnack Jul 17, 2025
f879100
widget now has animation engine
JXSnack Jul 17, 2025
9481b8b
apply animations to getStyle
JXSnack Jul 17, 2025
b576c0e
add Once
JXSnack Jul 18, 2025
443a25d
add setSafe method
JXSnack Jul 18, 2025
514e531
add equals and hashCode
JXSnack Jul 18, 2025
675a95a
value default null
JXSnack Jul 18, 2025
791be1b
isSet method
JXSnack Jul 18, 2025
bb2444b
make pipeline be once
JXSnack Jul 18, 2025
602b97b
remove isOf method
JXSnack Jul 18, 2025
cf649e9
empty composites
JXSnack Jul 18, 2025
e9e4794
applyCompositions -> applyComposites
JXSnack Jul 18, 2025
45ed7d9
add frameTime to composite
JXSnack Jul 18, 2025
c33bc19
basic VAnimation
JXSnack Jul 18, 2025
09709fd
implement composite uniform generator
JXSnack Jul 18, 2025
139fae9
move VeraPipeline.java
JXSnack Jul 18, 2025
64ff49b
docstring for uniforms
JXSnack Jul 18, 2025
b0a6246
ctx
JXSnack Jul 18, 2025
f43bd7b
update composites to fit new design
JXSnack Jul 18, 2025
32c8d00
give context to pass
JXSnack Jul 18, 2025
794b3e3
make require app
JXSnack Jul 18, 2025
c59c2bd
add LoopMode
JXSnack Jul 18, 2025
66a445f
discardTime -> unwindTime
JXSnack Jul 18, 2025
fc32273
simple builder
JXSnack Jul 18, 2025
4cc62d3
basic keyframe
JXSnack Jul 18, 2025
e479fc6
add easeIn easing
JXSnack Jul 18, 2025
e5224a9
add unwindEasing
JXSnack Jul 18, 2025
3b4e0a0
unwindEasing in builder
JXSnack Jul 18, 2025
5aef081
actually give correct animation
JXSnack Jul 18, 2025
1cdbc5d
make easeIn @NotNull and default to Easings.LINEAR
JXSnack Jul 18, 2025
0a6d3eb
add getCombinedTime
JXSnack Jul 20, 2025
f206798
me sound smart
JXSnack Jul 20, 2025
e796428
add isNewFrame argument
JXSnack Jul 20, 2025
401e59d
actually load composites
JXSnack Jul 20, 2025
0135ddc
add affects method
JXSnack Jul 20, 2025
b8f70e2
no more getCombinedTime, the class is final anyways
JXSnack Jul 20, 2025
0624e47
LinkedHashSet -> HashMap
JXSnack Jul 20, 2025
9f58774
activate now doesnt override by default
JXSnack Jul 20, 2025
64d4acb
add getTimeSinceActive method
JXSnack Jul 20, 2025
25bb522
add docstring
JXSnack Jul 20, 2025
a66f7a9
count the amount of times a style is modified
JXSnack Jul 20, 2025
0b323e3
add affects method
JXSnack Jul 20, 2025
f155bf8
basic animation composite
JXSnack Jul 20, 2025
812dd5b
better animation ahdnling
JXSnack Jul 20, 2025
b668e07
add getTotalTime
JXSnack Jul 20, 2025
b22aa87
composite now takes in as argument for apply
JXSnack Jul 20, 2025
e5cf0e3
remove in from ctx
JXSnack Jul 20, 2025
751f00e
actually define pipeline Once
JXSnack Jul 20, 2025
3b3e1cc
add apply for integers
JXSnack Jul 21, 2025
f6f8439
crash fix
JXSnack Jul 21, 2025
6380108
test animations
JXSnack Jul 21, 2025
8e6af80
net.snackbag.core.V4x moved into separate v4 package
JXSnack Jul 21, 2025
96022c2
add animation transition
JXSnack Jul 21, 2025
4364a04
reformat
JXSnack Jul 21, 2025
384cf8b
actually set the animation
JXSnack Jul 21, 2025
fcf0ae7
imports
JXSnack Jul 21, 2025
78ddcc8
also animate style with other getStyle method
JXSnack Jul 21, 2025
1217e14
fix keyframe styles no longer correct
JXSnack Jul 21, 2025
4587e77
make protected
JXSnack Jul 21, 2025
21a4371
fix builder
JXSnack Jul 21, 2025
2224d9c
basic calculateStyle method
JXSnack Jul 21, 2025
fa8bb33
fix margin
JXSnack Jul 21, 2025
61d3a7b
fix indent
JXSnack Jul 21, 2025
91ee466
applyWidget & apply -> applyStyle + no more abstract
JXSnack Jul 21, 2025
c3f1dd9
imports
JXSnack Jul 21, 2025
38d0562
fix name
JXSnack Jul 21, 2025
284f735
simpler AnimationComposite
JXSnack Jul 21, 2025
7a498b9
remove redundant variable
JXSnack Jul 21, 2025
3b21bc8
use generateUniforms to clear animations
JXSnack Jul 21, 2025
6c89559
cache animation times
JXSnack Jul 21, 2025
b1e71c5
call applyWidget
JXSnack Jul 21, 2025
542016c
DiscardComposite -> UnwindComposite
JXSnack Jul 21, 2025
b44e724
micro optimizations
JXSnack Jul 21, 2025
8730bea
correct active check
JXSnack Jul 21, 2025
360e820
getIfActive -> getIfEverActive
JXSnack Jul 21, 2025
ffbe52f
add setSize method
JXSnack Jul 21, 2025
5291dec
undo unwinding
JXSnack Jul 22, 2025
c256e53
call update
JXSnack Jul 22, 2025
939e051
equals and hashCode
JXSnack Jul 22, 2025
378aaf6
getKeyframes
JXSnack Jul 22, 2025
9ea8423
totalTime now contains unwindTime
JXSnack Jul 22, 2025
c390311
ms -> timeSinceActive
JXSnack Jul 22, 2025
858a056
save animation
JXSnack Jul 22, 2025
ad6054b
basic unwind system
JXSnack Jul 22, 2025
c444eca
b key now unwinds
JXSnack Jul 22, 2025
bf39df8
very basic and unoptimized UnwindComposite
JXSnack Jul 22, 2025
00b69db
shorten
JXSnack Jul 22, 2025
4b32236
add monotone end
JXSnack Jul 22, 2025
8afd5a2
update calculateStyle arguments
JXSnack Jul 22, 2025
8b3f1d4
add QOL events class
JXSnack Jul 22, 2025
d4e899d
add animation events
JXSnack Jul 22, 2025
5d31fb5
move to new QOL events class
JXSnack Jul 22, 2025
439420a
auto unwind
JXSnack Jul 22, 2025
f61ed85
move to new events
JXSnack Jul 22, 2025
11d36dd
move to new events
JXSnack Jul 22, 2025
5b95658
move to new events
JXSnack Jul 22, 2025
3e1162a
move to new events
JXSnack Jul 22, 2025
fc801e1
rename event CHECKED from checked to check-state-changed
JXSnack Jul 22, 2025
e9a7957
move to new event system
JXSnack Jul 22, 2025
6717c8f
move to new event system
JXSnack Jul 22, 2025
8daba6e
move to new event system
JXSnack Jul 22, 2025
27fdbe8
move to new event system
JXSnack Jul 22, 2025
8ba5d5d
move to new event system
JXSnack Jul 22, 2025
f6fd818
move to new event system
JXSnack Jul 22, 2025
0811044
move to new event system
JXSnack Jul 22, 2025
993dc62
UnwindComposite -> WindingComposite
JXSnack Jul 22, 2025
5da150a
add kill method
JXSnack Jul 22, 2025
03d5c2e
fire UNWIND_BEGIN event
JXSnack Jul 22, 2025
16cecbd
fire UNWIND_BEGIN event
JXSnack Jul 22, 2025
76a45b1
add REWIND_BEGIN
JXSnack Jul 22, 2025
4ead1f4
add kill shortcut
JXSnack Jul 22, 2025
9053161
add onAnimationUnwindBegin and onAnimationRewindBegin
JXSnack Jul 22, 2025
7f4bfea
very very basic rewind that doesnt do anything but send an event
JXSnack Jul 22, 2025
db83d9d
create RewindContext map
JXSnack Jul 22, 2025
b9ac937
basic rewind function
JXSnack Jul 22, 2025
81674e1
add getAllRewinding
JXSnack Jul 22, 2025
4c46d99
isRewinding
JXSnack Jul 22, 2025
cadf779
change unwind keybind
JXSnack Jul 22, 2025
b868979
add rewind keybind
JXSnack Jul 22, 2025
6ea4441
kill rewind
JXSnack Jul 22, 2025
dbc4377
basic rewinding
JXSnack Jul 22, 2025
19dafc9
undo
JXSnack Jul 22, 2025
bc4898b
unwinding now also has context
JXSnack Jul 23, 2025
1c61628
fix
JXSnack Jul 23, 2025
6d09667
fix rewind-unwind stacking
JXSnack Jul 24, 2025
98faed9
actually cache styles???
JXSnack Jul 24, 2025
1390e00
microoptimizations
JXSnack Jul 24, 2025
4b090c7
test hover animation
JXSnack Jul 24, 2025
de67c21
add activateOrRewind method
JXSnack Jul 24, 2025
8b01f3a
dont unwind if the animation isnt running
JXSnack Jul 24, 2025
8dd60e9
add isActive method and rename old isActive to isUnbothered
JXSnack Jul 24, 2025
9568ce9
undo isUnbothered shenanigans
JXSnack Jul 24, 2025
7df512d
check if is active before unwinding
JXSnack Jul 24, 2025
8cabcd4
check if is active before unwinding
JXSnack Jul 24, 2025
75984c8
check if is active before rewinding
JXSnack Jul 24, 2025
e2ab7f9
auto kill
JXSnack Jul 24, 2025
21344f7
use unwindOnFinish
JXSnack Jul 24, 2025
1613d5d
give autoUnwindAtEnd for monotone end
JXSnack Jul 24, 2025
feef5d9
add autoUnwindAtEnd setting for animations
JXSnack Jul 24, 2025
c1ac46d
cut back on loop modes
JXSnack Jul 27, 2025
4a2dc08
call animation begin event
JXSnack Aug 18, 2025
3db4292
test looping
JXSnack Aug 18, 2025
6d02481
fix ConcurrentModificationException
JXSnack Aug 18, 2025
cc2e307
kill ifn't looping
JXSnack Aug 18, 2025
98c8603
call animation finish event
JXSnack Aug 18, 2025
67b2146
move widgets to new system
JXSnack Aug 19, 2025
5c371f1
fix hover state being handled incorrectly
JXSnack Aug 19, 2025
50d05d3
fix hover state being handled incorrectly
JXSnack Aug 19, 2025
d832920
add QOL firstOf method
JXSnack Aug 19, 2025
9596eb0
add event postprocessor and therefore rename PreProcessorContext -> P…
JXSnack Aug 19, 2025
320ac21
increase keyframe time for testing
JXSnack Aug 19, 2025
09d4fec
attempt to make a hover style with transition
JXSnack Aug 19, 2025
be3cba9
implement event postprocessor as afterBuiltinEvent
JXSnack Aug 19, 2025
8cc3eb5
fire finish event
JXSnack Aug 19, 2025
55cb958
fire finish event
JXSnack Aug 19, 2025
595c52c
add all() to ColorModifier
JXSnack Aug 20, 2025
b354a4c
remove debug "updated" println
JXSnack Aug 20, 2025
cd99f95
very basic alignment
JXSnack Aug 20, 2025
9329103
height is now height and not max height
JXSnack Aug 20, 2025
e295ec1
do applyAlignment when posOf (should probably get cached though)
JXSnack Aug 20, 2025
37f4a95
add VLayoutAlignmentFlag
JXSnack Aug 20, 2025
900546f
calculate alignment for vertical
JXSnack Aug 20, 2025
44ac414
calculate horizontal alignment
JXSnack Aug 20, 2025
8025b8b
fix getting width
JXSnack Aug 20, 2025
175a7c7
parallelStream -> stream for less overhead
JXSnack Aug 20, 2025
1377f99
add the ability to keep the final style
JXSnack Aug 20, 2025
3d206da
add keepFinalStyle on hoverAnimation
JXSnack Aug 20, 2025
87467c7
new testing
JXSnack Aug 20, 2025
cde45eb
add effective transform
JXSnack Aug 20, 2025
6b2be3c
label padding is 0 by default now
JXSnack Aug 20, 2025
90f8415
use effective height & width
JXSnack Aug 20, 2025
751e752
render overlay
JXSnack Aug 20, 2025
3233d1a
rework label rendering
JXSnack Aug 20, 2025
7c74f39
note new discoveries
JXSnack Aug 20, 2025
a6bff54
fix center alignment halving original position
JXSnack Aug 25, 2025
efc1be6
Deprecate alsoAdd() and automatically add to add on object initializa…
JXSnack Aug 26, 2025
a4aabab
remove .alsoAdd from shortcuts
JXSnack Aug 26, 2025
e67e782
remove debug enable shortcut
JXSnack Aug 26, 2025
7aa3870
fully remove debug mode
JXSnack Aug 26, 2025
1217ded
empty layout alignment test app
JXSnack Aug 26, 2025
a03810d
fix mixin
JXSnack Sep 25, 2025
d47aa41
add featureset
JXSnack Sep 25, 2025
6dd49d4
fix animation unwinding random keyframe halt
JXSnack Oct 11, 2025
492d4d7
add INTERNAL_TRANSITION_ANIMATION_NAME
JXSnack Oct 23, 2025
bba50ce
add more to roadmap
JXSnack Oct 24, 2025
320739d
animation toString
JXSnack Oct 25, 2025
d747dbc
rename methods same -> isSame and sameColors -> hasSameColors for cla…
JXSnack Oct 25, 2025
f0fba4b
get keys methods
JXSnack Oct 25, 2025
45567a5
get keys methods
JXSnack Oct 25, 2025
8abfc4c
get keys method
JXSnack Oct 25, 2025
3aefa46
transition animation
JXSnack Oct 25, 2025
6f4e770
test transition animation
JXSnack Oct 25, 2025
53b42dd
make easings identifiable by name
JXSnack Oct 25, 2025
2c7aa71
register all easings in the registrar
JXSnack Oct 25, 2025
21458af
add caution message
JXSnack Oct 25, 2025
421998e
add easing SVT
JXSnack Oct 25, 2025
3f529af
add easing standard styles
JXSnack Oct 25, 2025
d33aa65
use transition style to test
JXSnack Oct 25, 2025
a929a91
add inherits metho
JXSnack Oct 25, 2025
a7fd747
better docstring
JXSnack Oct 25, 2025
dbbec95
mark codeblock
JXSnack Oct 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Vera
Because UI should be simple.

Vera is a simple yet powerful Fabric UI library. There are currently no plans for a Forge version.\
[Submit a Logo](https://github.com/snackbag/vera/issues/new) [Visit Wiki](https://wiki.snackbag.net/w/vera)

## Features

- Various standard widgets
- Labels
- Checkboxes
- Dropdowns
- Images
- Text input
- Tabs
- Rectangles
- Easy creation of custom widgets
- Styling system written from the ground up
- Customizable animation system
- Style-composite rendering pipeline
- (Custom) easings!
- Layout system
- HUD-rendering
- 2D rendering developer QOL
- App hierarchy
- Simple keybindings
- Heavy optimization
- (Developer) QOL with [Verto](https://github.com/snackbag/verto)
- Extensive documentation

### Coming soon

- Full docstrings everywhere
- More standard composites
- Multi-versions
- More precise font options
- Vertex & fragment shaders
- Revised rendering API
- Double buffer rendering
- Vanilla-UI abilities
- Widget Compounds
5 changes: 2 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -206,7 +205,7 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/net/snackbag/mcvera/InternalCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.snackbag.mcvera;

import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.CommandRegistryAccess;
import net.snackbag.mcvera.test.LayoutTestApplication;
import net.snackbag.mcvera.test.StyleTestApplication;
import net.snackbag.mcvera.test.TestApplication;

public class InternalCommands {
public static void register(
CommandDispatcher<FabricClientCommandSource> dispatcher,
CommandRegistryAccess ra
) {
if (!FabricLoader.getInstance().isDevelopmentEnvironment()) return;

dispatcher.register(
ClientCommandManager.literal("vera")
.then(ClientCommandManager.literal("test")
.then(ClientCommandManager.literal("generic").executes((ctx) -> {
TestApplication.INSTANCE.show();
return 1;
}))
.then(ClientCommandManager.literal("styles").executes((ctx) -> {
StyleTestApplication.INSTANCE.show();
return 1;
}))
.then(ClientCommandManager.literal("layout").executes((ctx) -> {
LayoutTestApplication.INSTANCE.show();
return 1;
}))
)
.then(ClientCommandManager.literal("clear-tests")
.executes((ctx) -> {
TestApplication.INSTANCE = new TestApplication();
StyleTestApplication.INSTANCE = new StyleTestApplication();
LayoutTestApplication.INSTANCE = new LayoutTestApplication();
return 1;
})
)
);
}
}
36 changes: 28 additions & 8 deletions src/main/java/net/snackbag/mcvera/MCVeraData.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
package net.snackbag.mcvera;

import net.snackbag.vera.core.VeraApp;
import net.snackbag.vera.flag.VWindowPositioningFlag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;

public class MCVeraData {
public static Set<VeraApp> applications = new HashSet<>();
public static Set<VeraApp> visibleApplications = new HashSet<>();
public static LinkedHashSet<VeraApp> applications = new LinkedHashSet<>();
public static HashMap<VWindowPositioningFlag, LinkedHashSet<VeraApp>> visibleApplications = new HashMap<>();
public static List<VeraApp> appHierarchy = new ArrayList<>();

public static int appsWithMouseRequired = 0;

public static final List<Integer> pressedKeys = new ArrayList<>();
public static List<Integer> previousPressedKeys = new ArrayList<>();
public static final Set<VeraApp> debugApps = new HashSet<>();
public static int appsWithMouseRequired = 0;

/**
* Executes a method as the top hierarchy app. If there is no top app it won't execute the specified code.
*
* @param runnable code to execute
* @return whether something has been executed
*/
public static boolean asTopHierarchy(@NotNull Consumer<VeraApp> runnable) {
if (appHierarchy.isEmpty()) return false;

runnable.accept(appHierarchy.get(0));
return true;
}

public static @Nullable VeraApp getTopHierarchy() {
return appHierarchy.isEmpty() ? null : appHierarchy.get(0);
}
}
14 changes: 14 additions & 0 deletions src/main/java/net/snackbag/mcvera/MinecraftVera.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.fabricmc.api.ModInitializer;

import net.snackbag.vera.Vera;
import net.snackbag.vera.style.standard.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,5 +14,17 @@ public class MinecraftVera implements ModInitializer {
@Override
public void onInitialize() {
LOGGER.info("Loading Vera...");

LOGGER.info("Registering standard styles");
// sorted by "complicatedness" & importance
Vera.registrar.registerStandardStyle(new WidgetStandardStyle());

Vera.registrar.registerStandardStyle(new RectStandardStyle());
Vera.registrar.registerStandardStyle(new ImageStandardStyle());
Vera.registrar.registerStandardStyle(new CheckBoxStandardStyle());
Vera.registrar.registerStandardStyle(new LabelStandardStyle());
Vera.registrar.registerStandardStyle(new DropdownStandardStyle());
Vera.registrar.registerStandardStyle(new TabWidgetStandardStyle());
Vera.registrar.registerStandardStyle(new LineInputStandardStyle());
}
}
17 changes: 1 addition & 16 deletions src/main/java/net/snackbag/mcvera/MinecraftVeraClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
import com.google.gson.JsonObject;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.InputUtil;
import net.minecraft.resource.Resource;
import net.minecraft.util.Identifier;
import net.snackbag.mcvera.impl.MCVeraProvider;
import net.snackbag.mcvera.impl.MCVeraRenderer;
import net.snackbag.mcvera.test.TestHandler;
import net.snackbag.vera.Vera;
import net.snackbag.vera.core.VeraApp;

import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -25,24 +21,13 @@ public void onInitializeClient() {
MinecraftVera.LOGGER.info("Loading client Vera implementation...");
TestHandler.impl(false);

HudRenderCallback.EVENT.register((context, tickDelta) -> {
MCVeraRenderer.drawContext = context;
MCVeraRenderer renderer = MCVeraRenderer.getInstance();

for (VeraApp app : MCVeraData.visibleApplications) {
renderer.renderApp(app);
}
});

ClientTickEvents.END_CLIENT_TICK.register((client) -> {
// only when changing
if (MCVeraData.previousPressedKeys.equals(MCVeraData.pressedKeys)) return;
MCVeraData.previousPressedKeys = new ArrayList<>(MCVeraData.pressedKeys);

String combination = makeCombination(client);
for (VeraApp app : MCVeraData.visibleApplications) {
app.handleShortcut(combination);
}
Vera.forVisibleAndAllowedApps(app -> app.handleShortcut(combination));
});
}

Expand Down
45 changes: 30 additions & 15 deletions src/main/java/net/snackbag/mcvera/impl/MCVeraProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@
import net.snackbag.vera.Vera;
import net.snackbag.vera.core.VFont;
import net.snackbag.vera.core.VeraApp;
import net.snackbag.vera.event.Events;
import net.snackbag.vera.event.VShortcut;
import net.snackbag.vera.widget.VWidget;

import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

public class MCVeraProvider {
public void handleAppInitialization(VeraApp app) {
MCVeraData.applications.add(app);
Vera.registrar.applyStandardWidgetStyles(app.styleSheet);
MinecraftClient.getInstance().send(app::init);
MinecraftClient.getInstance().send(app::update);

app.addShortcut(new VShortcut(app, "LeftCtrl+LeftAlt+LeftShift+D", () -> {
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.of("Debug mode enabled"));
MCVeraData.debugApps.add(app);
}, false));
}

public void handleAppShow(VeraApp app) {
if (app.isVisible()) return;

MCVeraData.visibleApplications.add(app);
MCVeraData.visibleApplications.get(app.getPositioning()).add(app);
if (app.isMouseRequired()) MCVeraData.appsWithMouseRequired += 1;
MinecraftClient client = MinecraftClient.getInstance();
client.send(app::update);
Expand All @@ -44,7 +42,7 @@ public void handleAppHide(VeraApp app) {
if (!app.isVisible()) return;

if (app.isMouseRequired()) MCVeraData.appsWithMouseRequired -= 1;
MCVeraData.visibleApplications.remove(app);
MCVeraData.visibleApplications.get(app.getPositioning()).remove(app);
MinecraftClient client = MinecraftClient.getInstance();
client.send(app::update);

Expand Down Expand Up @@ -101,15 +99,11 @@ public int getMouseY() {
}

public void handleKeyPressed(int keyCode, int scanCode, int modifiers) {
for (VeraApp app : MCVeraData.visibleApplications) {
app.keyPressed(keyCode, scanCode, modifiers);
}
Vera.forVisibleAndAllowedApps(app -> app.keyPressed(keyCode, scanCode, modifiers));
}

public void handleCharTyped(char chr, int modifiers) {
for (VeraApp app : MCVeraData.visibleApplications) {
app.charTyped(chr, modifiers);
}
Vera.forVisibleAndAllowedApps(app -> app.charTyped(chr, modifiers));
}

public String getDefaultFontName() {
Expand All @@ -129,8 +123,29 @@ public void handleAppSetMouseRequired(VeraApp app, boolean mouseRequired) {
}

public void handleFilesDropped(List<Path> paths) {
Vera.forHoveredWidget(Vera.getMouseX(), Vera.getMouseY(), (widget) -> {
widget.fireEvent("files-dropped", paths);
VeraApp top = MCVeraData.getTopHierarchy();

int x = Vera.getMouseX();
int y = Vera.getMouseY();

if (top != null && top.isPointOverThis(x, y)) {
VWidget<?> widget = top.getTopWidgetAt(x, y);
if (widget != null) {
widget.events.fire(Events.Widget.FILES_DROPPED, paths);
return;
}
}

AtomicBoolean didSomething = new AtomicBoolean(false);
Vera.forAllVisibleApps(app -> {
if (didSomething.get()) return;
if (!app.isPointOverThis(x, y)) return;

VWidget<?> widget = app.getTopWidgetAt(x, y);
if (widget != null) {
widget.events.fire(Events.Widget.FILES_DROPPED, paths);
didSomething.set(true);
}
});
}
}
39 changes: 39 additions & 0 deletions src/main/java/net/snackbag/mcvera/impl/MCVeraRegistrar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.snackbag.mcvera.impl;

import net.snackbag.vera.style.animation.easing.VEasing;
import net.snackbag.vera.style.standard.VStandardStyle;
import net.snackbag.vera.style.VStyleSheet;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* Main Vera registry manager. Use with caution: there are (almost) no
* safety checks. Therefore, it is recommended to use the classes that directly
* implement registrar functionality than touching it yourself.
*/
public class MCVeraRegistrar {
private final List<VStandardStyle> standardStyles = new ArrayList<>();
private final HashMap<String, VEasing> easings = new HashMap<>();

public void registerStandardStyle(VStandardStyle style) {
standardStyles.add(style);
}

public void applyStandardWidgetStyles(VStyleSheet sheet) {
for (VStandardStyle standardStyle : standardStyles) {
standardStyle.reserve(sheet);
standardStyle.apply(sheet);
}
}

public void registerEasing(String name, VEasing easing) {
easings.put(name.toLowerCase(), easing);
}

public @Nullable VEasing getEasingIgnoreCase(String name) {
return easings.getOrDefault(name.toLowerCase(), null);
}
}
Loading