|
8 | 8 | *
|
9 | 9 | * @package PhpGui\Widget
|
10 | 10 | */
|
11 |
| -class Label extends AbstractWidget { |
12 |
| - public function __construct(string $parentId, array $options = []) { |
13 |
| - parent::__construct($parentId, $options); |
| 11 | +class Label extends AbstractWidget |
| 12 | +{ |
| 13 | + public function __construct(string $parentId, array $options = []) |
| 14 | + { |
| 15 | + parent::__construct($parentId, $options); |
14 | 16 | $this->create();
|
15 | 17 | }
|
16 | 18 |
|
17 |
| - protected function create(): void { |
| 19 | + protected function create(): void |
| 20 | + { |
18 | 21 | $text = $this->options['text'] ?? '';
|
19 |
| - $this->tcl->evalTcl("label .{$this->parentId}.{$this->id} -text \"{$text}\""); // Correct Tcl path |
| 22 | + $extra = $this->getOptionString(); |
| 23 | + $this->tcl->evalTcl("label .{$this->parentId}.{$this->id} -text \"{$text}\" {$extra}"); |
20 | 24 | }
|
21 | 25 |
|
22 |
| - public function setText(string $text): void { |
23 |
| - $this->tcl->evalTcl(".{$this->parentId}.{$this->id} configure -text \"{$text}\""); // Correct Tcl path |
| 26 | + protected function getOptionString(): string |
| 27 | + { |
| 28 | + $opts = ""; |
| 29 | + foreach ($this->options as $key => $value) { |
| 30 | + if ($key === 'text') continue; |
| 31 | + $opts .= " -$key \"$value\""; |
| 32 | + } |
| 33 | + return $opts; |
| 34 | + } |
| 35 | + |
| 36 | + public function setText(string $text): void |
| 37 | + { |
| 38 | + $this->tcl->evalTcl(".{$this->parentId}.{$this->id} configure -text \"{$text}\""); |
| 39 | + } |
| 40 | + |
| 41 | + public function setFont(string $font): void |
| 42 | + { |
| 43 | + $this->tcl->evalTcl(".{$this->parentId}.{$this->id} configure -font \"{$font}\""); |
| 44 | + } |
| 45 | + |
| 46 | + public function setForeground(string $color): void |
| 47 | + { |
| 48 | + $this->tcl->evalTcl(".{$this->parentId}.{$this->id} configure -fg \"{$color}\""); |
| 49 | + } |
| 50 | + |
| 51 | + public function setBackground(string $color): void |
| 52 | + { |
| 53 | + $this->tcl->evalTcl(".{$this->parentId}.{$this->id} configure -bg \"{$color}\""); |
| 54 | + } |
| 55 | + |
| 56 | + public function setState(string $state): void |
| 57 | + { |
| 58 | + $this->tcl->evalTcl(".{$this->parentId}.{$this->id} configure -state \"{$state}\""); |
24 | 59 | }
|
25 | 60 | }
|
0 commit comments