Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\forms;
- use php\gui\framework\AbstractForm;
- use php\gui\event\UXEvent;
- use php\gui\event\UXWindowEvent;
- use php\gui\event\UXMouseEvent;
- use php\gui\UXLabel;
- use php\gui\graphic\UXColor;
- use php\gui\layout\UXVBox;
- use php\gui\layout\UXHBox;
- use php\gui\UXImageView;
- use php\gui\UXImage;
- use php\io\File;
- use php\lib\Str;
- class MainForm extends AbstractForm
- {
- public $arr = [];
- /**
- * @event show
- **/
- function doShow(UXWindowEvent $event = null)
- {
- $this->list->setCellFactory(function($cell, $item) {
- if ($item) {
- $cell->text = null;
- $titleName = new UXLabel($item->title);
- $titleName->css('font-weight', 'bold');
- $titleDescription = new UXLabel($item->description);
- $titleDescription->css('text-fill', 'gray');
- $title = new UXVBox([$titleName, $titleDescription]);
- $title->spacing = 0;
- $line = new UXHBox([$item->graphic, $title]);
- $line->spacing = 7;
- $line->padding = 5;
- $cell->text = null;
- $cell->graphic = $line;
- }
- });
- }
- /**
- * @event button.action
- **/
- function doButtonAction(UXEvent $event = null)
- {
- $this->list->items->clear();
- $this->arr = null;
- $dir = new File($this->edit->text);
- $files = $dir->find(function(File $file, $name) {
- $this->arr[] = $name;
- });
- foreach ($this->arr as $v) {
- if (Str::endsWith($v, '.png')) {
- $img = 'png.png';
- } elseif (Str::endsWith($v, '.jpg')) {
- $img = 'jpg.png';
- } elseif (Str::endsWith($v, '.gif')) {
- $img = 'gif.png';
- }
- $View = new UXImageView();
- $View->image = new UXImage('res://.data/img/'. $img);
- $item = new \stdClass();
- $item->title = $v;
- $item->description = 'File '. Str::sub($v, Str::pos($v, '.'));
- $item->graphic = $View;
- $this->list->items->add($item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement