Skip to content

Commit

Permalink
Change InputMapSpace to InputMapChain
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthaTi committed Dec 25, 2024
1 parent e972a17 commit 5422c35
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 27 deletions.
28 changes: 17 additions & 11 deletions source/fluid/input_map_space.d → source/fluid/input_map_chain.d
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module fluid.input_map_space;
module fluid.input_map_chain;

import std.algorithm;

import fluid.node;
import fluid.space;
import fluid.utils;
import fluid.input;
import fluid.types;
import fluid.node_chain;

import fluid.io.action;

import fluid.future.stack;

@safe:

alias inputMapSpace = nodeBuilder!InputMapSpace;
alias inputMapChain = nodeBuilder!InputMapChain;

class InputMapSpace : Space, ActionIO {
class InputMapChain : NodeChain, ActionIO {

private struct ReceivedInputEvent {
InputEvent event;
Expand All @@ -38,21 +38,27 @@ class InputMapSpace : Space, ActionIO {

}

this(InputMapping map, Node[] nodes...) {
super(nodes);
this(InputMapping map, Node next = null) {
super(next);
this.map = map;
}

override void resizeImpl(Vector2 space) {
override void beforeResize(Vector2) {

auto frame = this.implementIO();
super.resizeImpl(space);
auto frame = this.controlIO();
frame.start();
frame.release();

}

override void drawImpl(Rectangle outer, Rectangle inner) {
override void afterResize(Vector2) {

super.drawImpl(outer, inner);
auto frame = this.controlIO();
frame.stop();

}

override void afterDraw(Rectangle, Rectangle) {

// Process all input events
processEvents();
Expand Down
2 changes: 1 addition & 1 deletion source/fluid/io/action.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface ActionIO : IO {
/// and `focusImpl`, which only trigger if no input action has been activated.
///
/// Note that `CoreAction.frame` might, or might not, be emitted if another action event has been emitted during
/// the same frame. `InputMapSpace` will only emit `CoreAction.frame` is no other input action has been handled.
/// the same frame. `InputMapChain` will only emit `CoreAction.frame` is no other input action has been handled.
static InputEvent frameEvent() {

const code = InputEventCode(ioID!ActionIO, 1);
Expand Down
8 changes: 4 additions & 4 deletions source/fluid/node_chain.d
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ abstract class NodeChain : Node {
return _nextChain;
}

protected abstract void beforeResize(Vector2 space);
protected abstract void afterResize(Vector2 space);
protected void beforeResize(Vector2 space) { }
protected void afterResize(Vector2 space) { }

protected abstract void beforeDraw(Rectangle outer, Rectangle inner);
protected abstract void afterDraw(Rectangle outer, Rectangle inner);
protected void beforeDraw(Rectangle outer, Rectangle inner) { }
protected void afterDraw(Rectangle outer, Rectangle inner) { }

alias resizeChild = Node.resizeChild;

Expand Down
2 changes: 1 addition & 1 deletion source/fluid/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ else {

public import
fluid.backend,
fluid.input_map_space,
fluid.actions,
fluid.button,
fluid.checkbox,
Expand All @@ -45,6 +44,7 @@ public import
fluid.hover_chain,
fluid.image_view,
fluid.input,
fluid.input_map_chain,
fluid.io,
fluid.label,
fluid.map_frame,
Expand Down
2 changes: 1 addition & 1 deletion tests/nodes/code_input.d
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ unittest {

auto input = codeInput();
auto focus = focusChain(input);
auto root = inputMapSpace(map, focus);
auto root = inputMapChain(map, focus);
focus.currentFocus = input;
root.draw();

Expand Down
2 changes: 1 addition & 1 deletion tests/nodes/focus_chain.d
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ unittest {

auto tracker = focusTracker();
auto focus = focusChain(tracker);
auto root = inputMapSpace(map, focus);
auto root = inputMapChain(map, focus);

root.draw();
assert(tracker.focusImplCalls == 0);
Expand Down
6 changes: 3 additions & 3 deletions tests/nodes/hover_chain.d
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ unittest {
auto map = InputMapping();
map.bindNew!(FluidInputAction.press)(MouseIO.codes.left);

auto root = inputMapSpace(
auto root = inputMapChain(
.nullTheme,
map,
hover = hoverChain(
Expand Down Expand Up @@ -291,7 +291,7 @@ unittest {
auto map = InputMapping();
map.bindNew!(FluidInputAction.press)(MouseIO.codes.left);

auto root = inputMapSpace(
auto root = inputMapChain(
map,
hover = hoverChain(
.nullTheme,
Expand Down Expand Up @@ -361,7 +361,7 @@ unittest {
auto map = InputMapping();
map.bindNew!(FluidInputAction.press)(MouseIO.codes.left);

auto root = inputMapSpace(
auto root = inputMapChain(
map,
hover = hoverChain(
.nullTheme,
Expand Down
10 changes: 5 additions & 5 deletions tests/new_io/input_map_space.d → tests/nodes/input_map_chain.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module new_io.input_map_space;
module nodes.input_map_chain;

import fluid;

Expand Down Expand Up @@ -55,7 +55,7 @@ class ActionTester : InputNode!Node {

alias actionTester = nodeBuilder!ActionTester;

@("InputMapSpace can trigger input events")
@("InputMapChain can trigger input events")
unittest {

// Create bindings
Expand All @@ -66,7 +66,7 @@ unittest {
map.bindNew!(FluidInputAction.submit)(KeyboardIO.codes.enter);

auto tester = actionTester();
auto root = inputMapSpace(map, tester);
auto root = inputMapChain(map, tester);

root.draw();
assert(tester.pressed == 0);
Expand Down Expand Up @@ -105,14 +105,14 @@ unittest {

}

@("InputMapSpace emits a fallback event")
@("InputMapChain emits a fallback event")
unittest {

auto map = InputMapping();
map.bindNew!(FluidInputAction.press)(KeyboardIO.codes.space);

auto tester = actionTester();
auto root = inputMapSpace(map, tester);
auto root = inputMapChain(map, tester);

root.draw();
assert(tester.frameCalls == 0);
Expand Down

0 comments on commit 5422c35

Please sign in to comment.