Ferreteria/v0.6/clade/IO/O/Data/Element

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | IO‎ | O‎ | Data
Jump to navigation Jump to search
clade: IO\O\Data\Element
Clade Family
StandardBase Element
Clade Aliases
Alias Clade
Base* [c,i] Aux\StandardBase
QObj* [c,i] Data\Mem\QVar\Obj
RootClass IO\O\Data\Element\Root\Default
ListIface IO\O\Data\Element\Branch\List
SelfIface IO\O\Data\Element
TableIface IO\O\Data\Element\Branch\grid\Table
Subpages

History

  • 2024-10-17 created for more generalized handling of layout elements
  • 2024-10-20 moved from [WF]IO\O\Screen\Layout -> [WF]IO\O\Layout\base
  • 2024-10-21 moved from [WF]IO\O\Layout\base -> [WF]IO\O\Layout (*almost* full-circle)
  • 2024-12-13 added xStandardBase as parent
  • 2025-02-04 mucking around trying to implement different list formats, probably doing it wrong
  • 2025-03-31 adding SetValue()/GetValue(), which might have been implemented earlier in a Data trait that I removed for some reason?
  • 2026-01-15 added ShowIt(); should Render() be removed?

Code

interface iElement extends BaseIface {
    function AddElement(self $o);
    function Render() : string;
    function ShowIt();
}
abstract class caElement extends BaseClass implements SelfIface {

    // ++ SETUP ++ //

    // pointer to parent/container:
    private $oHold = NULL;
    protected function OHolder(?SelfIface $o=NULL) : SelfIface { return is_null($o) ? ($this->oHold ?? ($this->oHold = $this->OHoldNew())) : ($this->oHold = $o); }
    private function OHoldNew() : SelfIface { return new RootClass; }

    // -- SETUP -- //
    // ++ OUTPUT ++ //

    public function ShowIt() { echo $this->Render(); }

    protected function RenderIntro() : string { return ''; }
    protected function RenderOutro() : string { return ''; }
    protected function RenderSelf() : string {
        $ar = $this->Elements();
        $sOut = '';
        foreach ($ar as $oElem) {
            $sOut .= $oElem->Render();
        }
        return $sOut;
    }

    public function Render() : string {
        return $this->RenderIntro()
            .$this->RenderSelf()
            .$this->RenderOutro();
    }

    // -- OUTPUT -- //
    // ++ DATA ++ //

    private $arElem = [];
    public function AddElement(iElement $o) { $this->arElem[] = $o; }
    protected function Elements() : array { return $this->arElem; }

    // -- DATA -- //
    // ++ OBJECTS ++ //

    public function NewList() : ListIface {
        $o = new ($this->ListClass())($this);
        $this->AddElement($o);
        return $o;
    }

    public function NewTable() : TableIface {
        $o = new ($this->TableClass())($this);
        $this->AddElement($o);
        return $o;
    }

    // -- OBJECTS -- //
}