Skip to content

Commit

Permalink
Merge pull request 'Rework the tour' (#156) from tour into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthaTi authored and Gitea committed Apr 29, 2024
2 parents aa2ad25 + 579823b commit c1ecefa
Show file tree
Hide file tree
Showing 13 changed files with 1,014 additions and 46 deletions.
70 changes: 40 additions & 30 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
"authors": [
"Artha"
],
"subConfigurations": {
"bindbc-freetype": "staticBC"
},
"libs": ["freetype"],
"lflags-windows": ["/LIBPATH:$PACKAGE_DIR/libraries/windows"],
"lflags-osx": ["-L$PACKAGE_DIR/libraries/macos"],
"lflags-linux": ["-L$PACKAGE_DIR/libraries/ubuntu"],
"copyFiles-windows": [
"$PACKAGE_DIR/libraries/windows/freetype.dll",
"$PACKAGE_DIR/libraries/windows/raylib.dll"
],
"configurations": [
{
"name": "default",
"targetType": "library",
"subConfigurations": {
"bindbc-freetype": "staticBC"
},
"libs": ["freetype"],
"lflags-windows": ["/LIBPATH:$PACKAGE_DIR/libraries/windows"],
"lflags-osx": ["-L$PACKAGE_DIR/libraries/macos"],
"lflags-linux": ["-L$PACKAGE_DIR/libraries/ubuntu"],
"copyFiles-windows": [
"$PACKAGE_DIR/libraries/windows/freetype.dll",
"$PACKAGE_DIR/libraries/windows/raylib.dll"
]
"targetType": "staticLibrary"
},
{
"name": "dynamic",
"targetType": "dynamicLibrary"
},
{
"libs": [
Expand All @@ -33,6 +37,7 @@
"version": "~>11.3"
},
"bindbc-freetype": "~>1.1.1",
"bindbc-loader": "~>1.1.3",
"elemi": {
"optional": true,
"version": "~>1.2.2"
Expand All @@ -49,22 +54,11 @@
"stringImportPaths": [
"resources"
],
"excludedSourceFiles": [
"source/fluid/module_view.d"
],
"subPackages": [
{
"dependencies": {
"libdparse": "~>0.23.2",
"fluid": { "path": "." }
},
"name": "tour",
"libs": [
"raylib"
],
"sourcePaths": [
"tour"
],
"targetPath": "build",
"targetType": "executable"
},
"./tour",
{
"dependencies": {
"libdparse": "~>0.23.2",
Expand All @@ -75,12 +69,13 @@
"raylib"
],
"preBuildCommands": [
"echo Warning: fluid:showcase is deprecated in favor of fluid:tour"
"echo Deprecated: fluid:showcase has been renamed to fluid:tour"
],
"sourcePaths": [
"tour"
],
"targetPath": "build",
"targetName": "fluid-tour",
"targetType": "executable"
},
{
Expand All @@ -90,8 +85,23 @@
"sourcePaths": [],
"targetType": "executable",
"targetPath": "build"
},
{
"name": "module_view",
"versions": ["Fluid_ModuleView"],
"sourceFiles": ["source/fluid/module_view.d"],
"sourcePaths": [],
"targetType": "library",
"targetPath": "build",
"subConfigurations": {
"fluid": "dynamic"
},
"dependencies": {
"fluid": { "path": "." },
"fluid-tree-sitter": "~>0.1.5",
"fluid-tree-sitter:d": "~>0.1.5"
}
}
],
"targetPath": "build",
"targetType": "library"
"targetPath": "build"
}
2 changes: 1 addition & 1 deletion dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"ddmp": "0.0.1-0.dev.3",
"elemi": "1.2.2",
"fluent-asserts": "0.13.3",
"fluid-tree-sitter": "0.1.5",
"libdparse": "0.23.2",
"raylib-d": "5.0.1",
"stdx-allocator": "2.77.5"
}
}
34 changes: 27 additions & 7 deletions source/fluid/code_input.d
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class CodeInput : TextInput {
CodeHighlighter highlighter;
CodeIndentor indentor;

/// Additional context to pass to the highlighter. Will not be displayed, but can be used to improve syntax
/// highlighting and code analysis.
Rope prefix;

/// ditto
Rope suffix;

/// Character width of a single indent level.
int indentWidth = 4;
invariant(indentWidth <= maxIndentWidth);
Expand Down Expand Up @@ -169,6 +176,14 @@ class CodeInput : TextInput {

}

/// Get the full value of the text, including context provided via `prefix` and `suffix`.
Rope sourceValue() const {

// TODO This will allocate. Can it be avoided?
return prefix ~ value ~ suffix;

}

/// Get a rope representing given indent level.
Rope indentRope(int indentLevel = 1) const {

Expand Down Expand Up @@ -223,20 +238,22 @@ class CodeInput : TextInput {

protected void reparse() {

const fullValue = sourceValue;

// Parse the file
if (highlighter) {

highlighter.parse(value);
highlighter.parse(fullValue);

// Apply highlighting to the label
contentLabel.text.styleMap = highlighter.save;
contentLabel.text.styleMap = highlighter.save(cast(int) prefix.length);

}

// Pass the file to the indentor
if (indentor && cast(Object) indentor !is cast(Object) highlighter) {

indentor.parse(value);
indentor.parse(fullValue);

}

Expand Down Expand Up @@ -541,7 +558,7 @@ class CodeInput : TextInput {

const indentEnd = lineHomeByIndex(i);

return max(0, previousLineIndent + indentor.indentDifference(indentEnd));
return max(0, previousLineIndent + indentor.indentDifference(indentEnd + prefix.length));

}

Expand Down Expand Up @@ -1810,13 +1827,16 @@ interface CodeHighlighter {
out (r; r.end != byteIndex, "query() must not return empty ranges");

/// Produce a TextStyleSlice range using the result.
/// Params:
/// offset = Number of bytes to skip. Apply the offset to all resulting items.
/// Returns: `CodeHighlighterRange` suitable for use as a `Text` style map.
final save() {
final save(int offset = 0) {

static struct HighlighterRange {

CodeHighlighter highlighter;
TextStyleSlice front;
int offset;

bool empty() const {

Expand All @@ -1827,7 +1847,7 @@ interface CodeHighlighter {
// Continue where the last token ended
void popFront() {

do front = highlighter.query(front.end);
do front = highlighter.query(front.end + offset).offset(-offset);

// Pop again if got a null token
while (front.styleIndex == 0 && front !is front.init);
Expand All @@ -1842,7 +1862,7 @@ interface CodeHighlighter {

}

return HighlighterRange(this, query(0));
return HighlighterRange(this, query(offset).offset(-offset), offset);

}

Expand Down
2 changes: 2 additions & 0 deletions source/fluid/label.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Label : Node {
/// Text of this label.
Text!Label text;

alias value = text;

/// If true, the content of the label should not be wrapped into new lines if it's too long to fit into one.
bool isWrapDisabled;

Expand Down
Loading

0 comments on commit c1ecefa

Please sign in to comment.