Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
WTF stack corruption
  • Loading branch information
ArthaTi committed Dec 23, 2024
1 parent 8b31fcd commit b518f56
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 12 deletions.
10 changes: 7 additions & 3 deletions source/fluid/separator.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fluid.utils;
import fluid.backend;
import fluid.structs;

import fluid.io.canvas;

@safe:

Expand All @@ -29,6 +30,8 @@ alias hseparator = simpleConstructor!(Separator, (a) {
/// ditto
class Separator : Node {

CanvasIO canvasIO;

public {

bool isHorizontal;
Expand All @@ -37,6 +40,7 @@ class Separator : Node {

override void resizeImpl(Vector2) {

use(canvasIO);
minSize = Vector2(1, 1);

}
Expand All @@ -45,14 +49,14 @@ class Separator : Node {

auto style = pickStyle();

style.drawBackground(io, outer);
style.drawBackground(io, canvasIO, outer);

if (isHorizontal) {

auto start = Vector2(start(inner).x, center(inner).y);
auto end = Vector2(end(inner).x, center(inner).y);

style.drawLine(io, start, end);
style.drawLine(io, canvasIO, start, end);

}

Expand All @@ -61,7 +65,7 @@ class Separator : Node {
auto start = Vector2(center(inner).x, start(inner).y);
auto end = Vector2(center(inner).x, end(inner).y);

style.drawLine(io, start, end);
style.drawLine(io, canvasIO, start, end);

}

Expand Down
30 changes: 22 additions & 8 deletions source/fluid/style.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import fluid.typeface;

import fluid.io.canvas;

public import fluid.theme : makeTheme, Theme, Selector, rule, Rule, when, WhenRule, children, ChildrenRule, Field,
public import fluid.theme : makeTheme, Theme, Selector, rule, Rule, when, WhenRule, children, ChildrenRule, Field,
Breadcrumbs;
public import fluid.border;
public import fluid.default_theme;
Expand Down Expand Up @@ -144,7 +144,7 @@ struct Style {

public {

/// Breadcrumbs associated with this style. Used to keep track of tree-aware theme selectors, such as
/// Breadcrumbs associated with this style. Used to keep track of tree-aware theme selectors, such as
/// `children`. Does not include breadcrumbs loaded by parent nodes.
Breadcrumbs breadcrumbs;

Expand Down Expand Up @@ -217,7 +217,7 @@ struct Style {
}

}

/// ditto
void drawBackground(FluidBackend backend, CanvasIO io, Rectangle rect) const {

Expand Down Expand Up @@ -247,6 +247,20 @@ struct Style {

}

/// ditto
void drawLine(FluidBackend backend, CanvasIO canvasIO, Vector2 start, Vector2 end) const {

// New I/O system used
if (canvasIO) {

canvasIO.drawLine(start, end, 1, lineColor);

}

else drawLine(backend, start, end);

}

/// Get a side array holding both the regular margin and the border.
float[4] fullMargin() const {

Expand Down Expand Up @@ -479,7 +493,7 @@ unittest {

assert(sides.sideX == 1);
assert(sides.sideY == 2);

}

/// Returns a side array created from either: another side array like it, a two item array with each representing an
Expand Down Expand Up @@ -669,7 +683,7 @@ unittest {

}

/// Check if a rectangle is located above (`isAbove`), below (`isBelow`), to the left (`isToLeft`) or to the right
/// Check if a rectangle is located above (`isAbove`), below (`isBelow`), to the left (`isToLeft`) or to the right
/// (`isToRight`) of another rectangle.
///
/// The four functions wrap `isBeyond` which accepts a `Side` argument to specify direction at runtime.
Expand Down Expand Up @@ -741,12 +755,12 @@ bool isBeyond(Rectangle subject, Rectangle reference, Style.Side side) {
// side ↑ ↑ side.reverse side ↑ side ↑
const condition = abs(distanceInternal) > abs(distanceExternal);

// ↓ subject There is an edgecase though. If one box entirely overlaps the other on one axis,
// ↓ subject There is an edgecase though. If one box entirely overlaps the other on one axis,
// +====================+ it will be simultaneously to the left, and to the right, creating an ambiguity.
// | ↓ reference |
// | ↓ reference |
// | +------------+ | This is unwated in scenarios like focus switching. A scrollbar placed to the right
// | | | | of the page, should be focused by the right key, not by up or down.
// +===| |===+
// +===| |===+
// | | For this reason, we require both `distanceInternal` and `distanceExternal` to have
// +------------+ the same sign, as it normally would, but not in case of an overlap.
return condition
Expand Down
5 changes: 4 additions & 1 deletion tests/legacy/separator.d
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
@Migrated
module legacy.separator;

import fluid;
import legacy;

@safe:

@("[TODO] Legacy: vseparator draws a vertical line, hseparator draws a horizontal line")
@("vseparator draws a vertical line, hseparator draws a horizontal line")
@Migrated
unittest {

import fluid.theme;
Expand Down
49 changes: 49 additions & 0 deletions tests/nodes/separator.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module nodes.separator;

import fluid;

@safe:

@("separator draws a vertical or horizontal line")
unittest {

import fluid.theme;

auto theme = nullTheme.derive(
rule!Separator(
lineColor = color("#000"),
),
);

// Vertical
{
auto separator = vseparator();
auto root = sizeLock!htestSpace(
.sizeLimit(100, 100),
.layout!(1, "fill"),
theme,
separator
);

root.isHorizontal = true;
root.drawAndAssert(
separator.drawsLine().from(50, 0).to(50, 100).ofWidth(1).ofColor("#000"),
);
}

// Horizontal
{
auto separator = hseparator();
auto root = sizeLock!vtestSpace(
.sizeLimit(100, 100),
.layout!(1, "fill"),
theme,
separator
);

root.drawAndAssert(
separator.drawsLine().from(0, 0).to(100, 50).ofWidth(1).ofColor("#000"),
);
}

}

0 comments on commit b518f56

Please sign in to comment.