gabrielrcouto / php-gui

Extensionless PHP Graphic User Interface library
2.24k stars 175 forks source link

Set default value for Select #169

Open Cavaldier opened 5 years ago

Cavaldier commented 5 years ago

I want to set and display default value for select but i dont see any function for Select to set that. It issue or can be that in future? Someone can help?

WinterSilence commented 5 years ago

@Cavaldier u can extend any class. also u can set/get any other properties/classes from Lazarus elements/classes:

<?php

namespace Gui\Components;

/**
 * It is a visual component for spin input.
 *
 * @author WinterSilence
 * @since 0.1
 */
class SpinEdit extends VisualObject
{
    /**
     * @var string $lazarusClass The name of Lazarus class
     */
    protected $lazarusClass = 'TSpinEdit';

    /**
     * 
     * 
     * @return int
     */
    public function getValue()
    {
        return $this->get('Value');
    }

    /**
     * Sets the value.
     *
     * @param int $value
     * @return $this
     */
    public function setValue($value)
    {
        $this->set('Value', (int) $value);
        return $this;
    }
    /**
     * Get the maximal valueallowed for the spin edit.
     *
     * @return int
     */
    public function getMax()
    {
        return $this->get('MaxValue');
    }

    /**
     * 
     *
     * @param int $value
     * @return $this
     */
    public function setMax($value)
    {
        $this->set('MaxValue', (int) $value);
        return $this;
    }

    /**
     * Get the minimal valueallowed for the spin edit.
     *
     * @return int
     */
    public function getMin()
    {
        return $this->get('MinValue');
    }

    /**
     * Set the MinValue property equal to MaxValue to allow any number to be selected.
     *
     * @param int $value
     * @return $this
     */
    public function setMin($value)
    {
        $this->set('MinValue', (int) $value);
        return $this;
    }

    /**
     * The value by which the value of the control should be increased/decresed when 
     * the user clicks one of the arrows or one of the keyboard up/down arrows.
     *
     * @param int $value
     * @return $this
     */
    public function setIncrement($value)
    {
        $this->set('Increment', (int) $value);
        return $this;
    }
}

but need recompile /php-gui/lazarus/ before

Cavaldier commented 5 years ago

@WinterSilence ok, but i dont want to recompile all project. I using only netbeans and i cant recompile lazarus ;/ so that to set "default value" for select wont be created?

WinterSilence commented 5 years ago

@Cavaldier extends class https://github.com/gabrielrcouto/php-gui/blob/master/src/Components/Select.php

<?php
namespace Gui\Components;

class Select2 extends Select
{
    public function __construct(
        array $defaultAttributes = [],
        ContainerObjectInterface $parent = null,
        $application = null
    ) {
        parent::__construct($defaultAttributes, $parent, $application);
        // Select item with index 1 by default
        $this->set('itemIndex', 1);
    }
}
Cavaldier commented 5 years ago

But that only work on 0.1.1 version gui, how do it on 0.1? I got outdated library, but i dont want to upgrade to newest, because its too much work to refactor all in my project. My Select class extends Object, not VisualObject @WinterSilence

WinterSilence commented 5 years ago

@Cavaldier then its u problem, need write something like this.

Cavaldier commented 5 years ago

@WinterSilence can you tell me how i can show multiple application with diffrent items? Because when i adds items all goes to first window, not second(declared second new Application)

WinterSilence commented 5 years ago

@Cavaldier facepalm...