nkh / P5-App-Asciio

Plain ASCII diagram
https://nkh.github.io/P5-App-Asciio/
54 stars 4 forks source link

Add Canvas overlay #64

Closed nkh closed 1 year ago

nkh commented 1 year ago

Canvas calls a function to get a list of positions to overlay with a single character.

nkh commented 1 year ago

@qindapao

I've added an overlay branch.

https://github.com/nkh/P5-App-Asciio/branches

The documentation to use it is in the developer's documentation.

You can write a callback that will be called after all the elements are drawn. You can then make your computation but instead for adding filler elements you return a list of fillers characters, and their coordinates, and Asciio will draw them.

qindapao commented 1 year ago

@nkh

Ok, I'll try it when I have time.

qindapao commented 1 year ago

'set overlays' => [ '0A0-o', sub { $_[0]->set_overlayssub(sub { [0, 0, 'O'], [1, 0, 'K'] }) ; $[0]->update_display ; } ],

@nkh

How can I set my own sub here? Can you give me an example? I wrote several kinds on the company computer, but none of them were correct.

qindapao commented 1 year ago

My sub is here, App:Asciio::Cross::create_cross_coordinates

qindapao commented 1 year ago

'set overlays' => [ '0A0-o', sub { $[0]->set_overlays_sub(sub {\&App:Asciio::Cross::create_cross_coordinates}) ; $[0]->update_display ; } ],

not right

'set overlays' => [ '0A0-o', sub { $[0]->set_overlays_sub(\&App:Asciio::Cross::create_cross_coordinates) ; $[0]->update_display ; } ],

also not right

I still don't understand perl deeply.

nkh commented 1 year ago
'set overlays' => # the name of the binding
    [ # binding array contains information about the binding
    '0A0-o', # the shortcut for the binding
    sub # the function that is called when the shortcut is pressed
        {
        # $_, you must use the underscore, is the first argument, $asciio
        $_[0]->set_overlays_sub # call the set_overlays_sub in the $asciio object
                        (
                       \&App:Asciio::Cross::create_cross_coordinates # a reference to a sub called when overlays are needed
                        )  ;
        $[0]->update_display ; # update the display after the shortcut is pressed, might not be needed for you
        }
 ], 
qindapao commented 1 year ago

@nkh

Still not working,submit a report

Undefind subroutine &App::Asciio::Cross::create_cross_coordinates called at /usr/local/share/perl5/site_perl/5.32/App/Asciio.pm line 927

I have defined the function, and it is no problem to call it forcibly.I submit a debug branch in the evening, and you can help me look at it again.

nkh commented 1 year ago

Did you write this in the file where you define the bindings? at the top.

use App::Asciio::Cross ;
qindapao commented 1 year ago

'set overlays' => [ '0A0-o', sub { $[0]->set_overlays_sub(\&App:Asciio::Cross::create_cross_coordinates) ; $[0]->update_display ; } ], not working

but

'set overlays' => [ '0A0-o', sub { $[0]->set_overlays_sub(\&App:Asciio::Actions::ElementsManipulation::create_cross_coordinates) ; $[0]->update_display ; } ], working

i do not know why.

use App::Asciio::Cross ; This is written

qindapao commented 1 year ago

Cross is part of the Asciio package.ElementsManipulation Not part of the Asciio package.I only know this.

qindapao commented 1 year ago

I know why,

'set overlays' => [ '0A0-o', sub { $[0]->set_overlays_sub(\&App:Asciio::create_cross_coordinates) ; $[0]->update_display ; } ], working

Cross It's a sub-package

nkh commented 1 year ago

The error is in Cross.pm

At the top you have: package App::Asciio ;

It doesn't matter what file code is in, if you say it's package App::Asciio then it's that package.

That needs to be changed to App:Asciio::Cross.

it worked in App:Asciio::Actions::ElementsManipulation because that one is actually part of App::Asciio since moving elements is a base functionality, even if we put it in another file.

nkh commented 1 year ago

hmm, we'll need to thin about Toolfunc.pm (which is a weird name) and Cross.pm, not sure they should be in or out of the Asciio namespace.

Toolfunc has these functions:

44  sub set_double_width_qr_and_markup_mode
 52  sub usc_length
 65  sub make_vertical_text
103  sub new_box
121  sub new_wirl_arrow
139  sub add_connection
182  sub move_named_connector
229  sub optimize_connections
237  sub get_canonizer
248  sub register_hooks

it's a little bit of a mix, and move_named_connector is not used at all.

but let's forget about it right now, I'll write a ticket we can take when we have time.

qindapao commented 1 year ago

That was a major operation,How about we stabilize the current function and then deal with it?

I've run it, and the effect is very good. It seems that the filler can be completely killed.

However, there is an obvious performance degradation. I don't know whether it comes from the calculation coordinate part or the drawing part. I'll take time to look at the time-consuming distribution.

nkh commented 1 year ago

It should be faster not slower

The computation is the same, except if you changed it.

we replace the creation of all the fillers with a single callback.

The only thing I can think of is that before it wasn't called at every update and now it is.

Commit and I'll look at it.

qindapao commented 1 year ago

I can start writing code that removes the cross mode.Then use overlay. It should start on Wednesday night. It should be easy, just handle the function of exporting to ascii.

nkh commented 1 year ago

Commit what you have, even slow, I'm curious.

Do you want me to write the function exporting to ascii?

qindapao commented 1 year ago

@nkh

I'm still in the company, just leave this part to me.I will deal with it when I have time, and I am very happy to make the cross model truly integrated.

nkh commented 1 year ago

It's all yours :)

There may be a way I can generate data you can use more efficiently but we can look at that later.

nkh commented 1 year ago

merged in 9b2e337

@qindapao discussion continues in #62