scorninpc / php-gtk3

GTK3 extension for PHP
https://andor.com.br/
GNU Lesser General Public License v3.0
118 stars 13 forks source link

PangoLayout_::xy_to_index implementation #143

Closed d47081 closed 3 months ago

d47081 commented 3 months ago

GTK documentation https://docs.gtk.org/Pango/method.Layout.xy_to_index.html

I have following draft:

Php::Value PangoLayout_::xy_to_index(Php::Parameters &parameters)
{
    gint x = (gint) parameters[0];
    gint y = (gint) parameters[1];

    gint* index_;
    gint* trailing;

    return pango_layout_xy_to_index(PANGO_LAYOUT(instance), x, y, index_, trailing);
}

This implementation process x and y arguments properly, but:

  1. how to return index_ and trailing values generated as php parameters?
  2. should I use int or gint there?
  3. this method return to php integer 0|1 not boolean as documented, how to make canonical boolean type return?

btw, app code fragment for tests where I'm trying to get link address on middle button click by this feature

$this->gtk->connect(
    'button-press-event',
    function(
        GtkLabel $label,
        GdkEvent $event
    ) {

        if ($event->button->button == 2) // @TODO Gdk::BUTTON_MIDDLE #141
        {
            $index = null;
            $trailing = null;

            $result = $label->get_layout()->xy_to_index(
                $event->button->x * Pango::SCALE,
                $event->button->y * Pango::SCALE,
                $index,
                $trailing
            );

            var_dump($result);
            var_dump($index);
            var_dump($trailing);

            // next operations with index received ...

        }

        return true;
    }
);
scorninpc commented 3 months ago
  1. you can return array with 2 indexs: indexand trailing
  2. if pango_layout_xy_to_index use int, so you need to use int too. but, gint is a int alias
  3. i think you can return the array if OK, and false if error
d47081 commented 3 months ago
  1. is it okay that function API will be changed of that? maybe you too don't know how to make it as linked argument back or that's just impossible with php-cpp
  2. yes looks like gint is int alias for Gtk environment, but I see different implementations in code and asking which of them is correct. will use gint so
  3. well, if I can return changed API, there is no problem with data types at all

sad we can't make it 1:1 compatible with gtk api.. and I can't find any similar method in code available.

p.s. just created question here https://github.com/CopernicaMarketingSoftware/PHP-CPP/issues/534

p.p.s. about boolean values found these constructions to operate: Php::Type::True, Php::Type::False

    Php::Value ret = pango_layout_xy_to_index(PANGO_LAYOUT(instance), x, y, index_, trailing);

    if(ret.type() == Php::Type::True) {
        return Php::Type::True;
    } else {
        return Php::Type::False;
    }
d47081 commented 3 months ago

Mostly done, see you there https://github.com/scorninpc/php-gtk3/pull/144

scorninpc commented 3 months ago

is it okay that function API will be changed of that? maybe you too don't know how to make it as linked argument back or that's just impossible with php-cpp

this is a pattern since php-gtk1, it's not ok use reference args with php

d47081 commented 3 months ago

Yes, finally got it