pdce is my old text editor project, it became a pain to debug so i basically quit finishing it, so now il do a full rewrite using the right tools for the job. pdce repo: https://codeberg.org/pastbear/pdce
#Rewriting pdce
1 messages · Page 1 of 1 (latest)
so
in my optinion the worst part was the text drawing
like handling all key input manualy is super painfull
so we need something like a textbox but one that can be wildly moved around
Ooo
cause ard.simpledisplay is good for games
but for a thing where its main job is writing text
we need a inbuilt textbox
and since im doing full rewrite i can chose other libs
but id llove to stay in arsd domain
cause arsd has crazy reliability
also
im jsut used to it
so arsd.minigui coudl work
is that a good idea?
technically yes but im only able to check if it works on linux with x11
but thats ok cause using arsd stuff is basicaly always os agnostic
this is what arsd.textlayouter is
minigui builds its (custom) text edit out of it and you can do other things too
but what you mean by this?
like as in the mai nppoint of pdce is that your view shifts with your cursor
like a dinamic movement effect
inspired by: https://github.com/tsoding/ded
there like a video demo?
cuz im thinking you could do a normal algorithm but apply after effects to it
like a matrix transform
oh so it basically just centers the camera on the caret w/ some animated transition
that's not that hard to do.... i think
actually you could prolly do it w/ a stock text edit through an animated transform matrix. lemme mess with it a few mins
lol i have a function that tracks caret position externally (for input method engines) but it isn't readable or hookable inside the process. well i can still hack something in
yea
im seeing if i can redirect drawing to an image w/o changing the lib now. i think i can
why into an image tho
cuz then you can transform and blit the image to the screen
but the problem here is that the clip for scrolling is still off so not as much of a help without auto adjusting that too...
i have to go in like 10 mins tho
o ok
yeah i dont think ill have anything by then. like in theory i guess i could do a dummy draw then a real draw after changing the transofrm. that'd work too
basically im just auto-scrolling w/ the cursor
yea
il be back tomorrow
for me so like 7 hours or so
doesnt have to be done now
well i can do that actually i think
literally do a fake draw then auto-scroll and draw again
lol that almost works except the scroll bar hits its bounds so not quite
yea
import arsd.minigui;
import arsd.textlayouter;
class AnimatedTextEdit : CustomTextEdit {
this(Widget parent) {
super(parent);
}
override TextDisplayHelper textDisplayHelperFactory(TextLayouter textLayout, ScrollMessageWidget smw) {
return new MyTextDisplayHelper(textLayout, smw);
}
static class MyTextDisplayHelper : TextDisplayHelper {
this(TextLayouter textLayout, ScrollMessageWidget smw) {
super(textLayout, smw);
}
override Rectangle paintContent(WidgetPainter painter, const Rectangle bounds) {
TextLayouter.CaretInformation ci;
l.getDrawableText(delegate bool(txt, style, info, carets...) {
foreach(caret; carets) {
ci = caret;
}
return true;
});
painter.originX = painter.originX + this.width / 2 - ci.boundingBox.upperLeft.x;
painter.originY = painter.originY + this.height / 2 - ci.boundingBox.upperLeft.y;
super.paintContent(painter, bounds);
return bounds;
}
}
}
void main() {
auto window = new Window;
auto ate = new AnimatedTextEdit(window);
window.loop();
}
that kinda sorta works
no animation but you could do that by setting a timer and tracking the difference and like lerping it in between.
and of course it breaks once you actually start to scroll, since then it is double transforming and hitting the clip barrier, etc. so to actually work well it'd have to take all that into account too
but a starting point
k. lemme know
@radiant tangle im back
this works ima try improve it
nice. i think i saw you hit a scroll edge there in the video ll
o btw
is there a way to color words / characters differently
for syntax highlighting
@radiant tangle
yeah a couple ways, easiest is to overload umm..... like drawTextSegment or something. only works on stuff together in one line but easiest by far
other way is to attach styles to the text itself and that's a half-finished api so kinda painfu
https://forum.dlang.org/post/[email protected]
override void drawTextSegment(MyTextStyle ignoredGenericStyle, WidgetPainter painter, Point upperLeft, scope const(char)[] text) {
if(lv.searching.length && text.indexOf(lv.searching) != -1) {
// this line matched the search, draw a special background around it
// a subpainter lets us modify color and then return to previous
// settings automatically when it goes out of scope
auto subpainter = painter;
subpainter.outlineColor = Color.yellow;
subpainter.fillColor = Color.yellow;
subpainter.drawRectangle(upperLeft, subpainter.textSize(text));
}
painter.drawText(upperLeft, text);
}
in the text display helper
but this thing can only match on single lines at a time at best
whats easiest for actual syntax highlighting tho
the drawTextSegment override is def the easiest
at least until i finsih the other api
for the otehr api you have to call like registerStyle for each particular thing then apply it to text sgments. but this all works on the TextLayouter which is an internal member
maybe i can demo this later too tho cuz it would be more reliable
well doing it on display would be better for highlighting anyway since as you edit it would auto update
it just has to workwith minimum context
yes
i guess you could build up context as it loops through the text segments as it draws. that might be slow idk
but it stopping early is actually why it goes white under. it thinks it drew in the whole window so it stops, but actually because the camera moved it leaves empty spots. i know how to address that just the library is designed for traditional movement so this is all a bit hacky lolol
still i think it is pretty cool that it is ONLY a bit hacky. like the lib is working pretty ok doing something it was never designed for
yea
im trying to make my on little hacky thing
rn im trying to find where minigui actually calls drawText fro msimpeldisplay
so i can tinker there
that's the default implementation of drawTextSegment
oooo
check class TextDisplayHelper
void drawTextSegment(MyTextStyle myStyle, WidgetPainter painter, Point upperLeft, scope const(char)[] text) {
painter.setFont(myStyle.font);
painter.drawText(upperLeft, text);
}
but like i tried the example oyu gave in the forum
and i coudl see any coloring
my brain rn is thinking of baically slapping transparent colored rectangles on the text t ocolor
but htats probabyl lots of pain
there's like 5 classes this stuff is split across.....
CustomTextEdit = the minigui wrapper doing user interface handling. inside:
TextLayouter = works all in memory
ScrollMessageWidget = wraps up the scroll bars
TextDisplayHelper = the middle part of the scroll message, the part that actually draws text
MyTextStyle = helper for styling
o okkkk
but TextDisplayHelper is the main one for you to edit cuz it is text display you want to customize
it was looking for a particular string so gotta have that
so idt highlight the sting you put in the search thing that said What
yeah
o ok
i got coloring but like it always colors ful lline
is there a hacky way to fix thta
well looks like you set outline color back
oh i know it is cuz the whole segment is drawn this way so you'd have to break it up
lemme demo and get back to you
drawText should really just return the new position to add more to it. golly this is an unnecessary pain. but still this kinda works
the point of the text style thing is to let the lib do this for you so maybe that is easier? just idk that's made more for like a WordPad style program rathar than syntax highlighting
but here's the changed code
override void drawTextSegment(
MyTextStyle ignoredGenericStyle,
WidgetPainter painter,
Point upperLeft,
scope const(char)[] text
) {
auto t = text.idup;
Color col = getComputedStyle().foregroundColor;
auto defaultCol = col;
size_t split = text.length;
size_t after = text.length;
foreach (word, c; owner.colorMap) {
auto idx = t.indexOf(word);
if(idx != -1) {
split = idx;
after = split + word.length;
col = c;
break;
}
}
if (owner.searching.length && t.indexOf(owner.searching) != -1) {
painter.fillColor = Color(40, 40, 40);
painter.outlineColor = Color(80, 80, 80);
painter.drawRectangle(upperLeft, painter.textSize(text));
}
painter.outlineColor = defaultCol;
painter.drawText(upperLeft, text[0 .. split]);
if(split != text.length) {
auto pos = upperLeft;
// i guess it isn't ignored style anymore lol
// but we need to advance the position past each part we draw
// note that painter.textSize exists but is the *visible* size
// meaning it ignores leading/trailing spaces, which leads to overlapping here.
pos.x += ignoredGenericStyle.font.stringWidth(text[0 .. split]);
painter.outlineColor = col;
painter.drawText(pos, text[split .. after]);
pos.x += ignoredGenericStyle.font.stringWidth(text[split .. after]);
painter.outlineColor = defaultCol;
painter.drawText(pos, text[after .. $]);
}
}
notice the split of the text means it woould only highlight one word per line still. you can fix that by doing multiple loops or splitting on words or something but this shows how to do the text split o different parts of it can be different colors
i got it to do multiple words on one line
awesome
it is binded to ctrl+R or right click, redo by default
method TextDisplayHelper.redo
o ok
so
i got some nice syntax highlighting
but i wana make it configurable without having ht user recompile
what config file language shoudl we use
json would be simpel cause its in d standard lib
@gritty turret
anyways ima use arsd.ini
cause ini is actually readable
while json isnt
ini should be fine
ok
@nova badge @pearl geyser repo is here
if you just asking gpt - it could not work
you need to understand the problem - make some debugging - try to identify the issue and ask more precisely
minigui has built in file dialogs too fyi
yea
i decided i dnt need file dialogs for the thing i was doing
but il use the ones in minigui when we come to saving and openign files
SUP
so i got syntax highlighting customizeable
you can even have specific highlighting for any language
the stirng parsing was surprisingly easy
i couldnt use arsd.ini
since it cant read keys that arent known
like the word you wana highlight arent known to me
so i cant get their values/colors with arsd.ini
so i parsed myself
d stirng processing is so goood
@everyone
s*** sorry for doing supereveryone
it autocompleated
dont ping people too much please
ok
i odnt know how to fix these issues
please ping me if you know how
til then ima go work on my window manager DXWM
just use links for codeberg
create a new branch and publish your code there
paste links could not work for everyone
cause my git aint workig nright
then I would say you need to fix this first - before writing any code 🙂
then ima try fix that first before i go work on my wm while i wait for help lol
i decided to take break for 10 min and try fixing pdce bugs, i fixed al lthe men ubugs
only ones remaining are scrol lbugs
@radiant tangle how do i fix the scrolling thing
you basically want to take out the scroll adjustment stuff from the draw function so it ignores the scroll position
prolly has to override paintContent and copy/paste some stuff. ill play with it ater
ok
so i think you already overrode paintContent in the code
y
wierd tho why does the scroll bug stil lhappen
like this is probably cause we onnly shift stuff around, but teh limited size box still exists
is there a way to make the box get bigger
like while running
just wait a min
ok
ok this should do it
first override the methods in TExtDisplayHelper that do scrolling:
override void adjustScrollbarSizes() {
// pretend the scroll doesn't matter
this.smw.setTotalArea(1, 1);
this.smw.setViewableArea(1, 1);
}
override void scrollForCaret() {
// do nothing
}
then in the draw function you need to trick the parent class into thinking it has basically infinite size before you call:
// save old size and pretend the widget has infinite size temporarily
auto tmp = this.width;
auto tmp2 = this.height;
this.width = 2_000_000_000;
this.height = 2_000_000_000;
auto result = super.paintContent(painter, Rectangle(bounds.upperLeft, Size(this.width, this.height)));
// restore the old size before returning
this.width = tmp;
this.height = tmp2;
then finally when you go to draw your cursor, override minigui's normal clip so your rectangle is always drawn (i think this is working around a bug inside but meh)
painter.fillColor = Color(0, 0, 0, 0);
painter.outlineColor = fg;
// trick it into thinking you have infinite space again
painter.screenPainter.setClipRectangle(Rectangle(Point(0, 0), Size(2_000_000_000, 2_000_000_000)));
painter.drawRectangle(block);
basically just lying to the library the whole time lol
ok thx
it is hard to click and drag rn cuz the click logic doesn't understand the camera offset. could adjust that too
im not a mouse person lol but ye later
so btw
the editor is technically complete