#Rewriting pdce

1 messages · Page 1 of 1 (latest)

pearl geyser
#

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

#

@gritty turret

pearl geyser
#

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

sturdy pine
#

Ooo

pearl geyser
#

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?

sturdy pine
#

I assume this is supposed to be OS-agnostic?

#

I would play around with Mingui if so

pearl geyser
#

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

radiant tangle
#

minigui builds its (custom) text edit out of it and you can do other things too

radiant tangle
pearl geyser
#

like as in the mai nppoint of pdce is that your view shifts with your cursor

#

like a dinamic movement effect

pearl geyser
radiant tangle
#

there like a video demo?

#

cuz im thinking you could do a normal algorithm but apply after effects to it

#

like a matrix transform

pearl geyser
#

this is a old demo vid

radiant tangle
#

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

pearl geyser
#

yea

radiant tangle
#

im seeing if i can redirect drawing to an image w/o changing the lib now. i think i can

pearl geyser
#

why into an image tho

radiant tangle
#

cuz then you can transform and blit the image to the screen

pearl geyser
#

oooo

#

true

radiant tangle
#

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...

pearl geyser
#

i have to go in like 10 mins tho

radiant tangle
#

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

pearl geyser
#

yea

#

il be back tomorrow

#

for me so like 7 hours or so

#

doesnt have to be done now

radiant tangle
#

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

pearl geyser
#

yea

radiant tangle
#
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

pearl geyser
#

il go sleep now

#

il test it tomorow

radiant tangle
#

k. lemme know

pearl geyser
#

@radiant tangle im back

pearl geyser
#

@everyone

#

PDCE rewrite demo:

radiant tangle
#

nice. i think i saw you hit a scroll edge there in the video ll

pearl geyser
#

o btw

#

is there a way to color words / characters differently

#

for syntax highlighting

#

@radiant tangle

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

pearl geyser
radiant tangle
#

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

pearl geyser
#

yes

radiant tangle
#

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

pearl geyser
#

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

radiant tangle
#

that's the default implementation of drawTextSegment

pearl geyser
#

oooo

radiant tangle
#

check class TextDisplayHelper

#

void drawTextSegment(MyTextStyle myStyle, WidgetPainter painter, Point upperLeft, scope const(char)[] text) {
painter.setFont(myStyle.font);
painter.drawText(upperLeft, text);
}

pearl geyser
#

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

radiant tangle
#

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

pearl geyser
#

o okkkk

radiant tangle
#

but TextDisplayHelper is the main one for you to edit cuz it is text display you want to customize

radiant tangle
pearl geyser
radiant tangle
#

yeah

pearl geyser
#

o ok

pearl geyser
#

i got coloring but like it always colors ful lline

#

is there a hacky way to fix thta

radiant tangle
#

did you change teh color back after the segment?

#

paste the function in here

pearl geyser
#

ts is ful lcode

#

@radiant tangle

radiant tangle
#

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

radiant tangle
#

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

pearl geyser
#

i got it to do multiple words on one line

radiant tangle
#

awesome

pearl geyser
#

can we have redo?

#

cause we have undo

radiant tangle
#

it is binded to ctrl+R or right click, redo by default

#

method TextDisplayHelper.redo

pearl geyser
#

o ok

pearl geyser
#

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

gritty turret
#

ini should be fine

pearl geyser
#

ok

gritty turret
#

@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

pearl geyser
#

i understood the problem

#

and decided to reduce pain levels by doing it differently

radiant tangle
#

minigui has built in file dialogs too fyi

pearl geyser
#

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

pearl geyser
#

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

gritty turret
#

dont ping people too much please

pearl geyser
#

ok

pearl geyser
#

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

gritty turret
#

create a new branch and publish your code there

#

paste links could not work for everyone

pearl geyser
#

ok

#

i cant put it in repo now tho

pearl geyser
gritty turret
pearl geyser
pearl geyser
#

only ones remaining are scrol lbugs

pearl geyser
#

@radiant tangle how do i fix the scrolling thing

radiant tangle
#

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

pearl geyser
#

ok

radiant tangle
#

so i think you already overrode paintContent in the code

pearl geyser
#

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

pearl geyser
#

like while running

radiant tangle
#

just wait a min

pearl geyser
#

ok

radiant tangle
#

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

pearl geyser
#

ok thx

pearl geyser
#

works nice

#

ima do git thing

#

so the new version is in the repo

sturdy pine
#

I will have to look at this editor tbh

radiant tangle
#

it is hard to click and drag rn cuz the click logic doesn't understand the camera offset. could adjust that too

pearl geyser
#

so btw

#

the editor is technically complete