This commit is contained in:
2024-09-26 17:49:03 +02:00
parent 8f375efe41
commit 179de20dba
9 changed files with 253 additions and 127 deletions
+21 -10
View File
@@ -4,16 +4,18 @@ import (
"fmt"
"strings"
"github.com/orus-dev/osui/colors"
"golang.org/x/term"
)
type ComponentData struct {
X uint16
Y uint16
Width int
Height int
IsActive bool
Screen *Screen
X uint16
Y uint16
Width int
Height int
DefaultColor string
IsActive bool
Screen *Screen
}
type Component interface {
@@ -23,7 +25,8 @@ type Component interface {
}
type Screen struct {
component Component
component Component
CustomRender func()
}
func NewScreen(c Component) *Screen {
@@ -33,6 +36,10 @@ func NewScreen(c Component) *Screen {
}
func (s *Screen) Render() error {
if s.CustomRender != nil {
s.CustomRender()
return nil
}
Clear()
width, height, err := term.GetSize(0)
if err != nil {
@@ -40,10 +47,15 @@ func (s *Screen) Render() error {
}
frame := NewFrame(width, height)
data := s.component.GetComponentData()
data.Width = width
data.Height = height
if data.Height == 0 {
data.Height = height
}
if data.Width == 0 {
data.Width = width
}
data.Screen = s
data.IsActive = true
data.DefaultColor = colors.Reset
RenderOnFrame(s.component, &frame)
fmt.Print(strings.Join(frame, "\n"))
return nil
@@ -51,7 +63,6 @@ func (s *Screen) Render() error {
func (s *Screen) Run() {
s.component.GetComponentData().Screen = s
s.component.Update("OSUI:RENDER")
for {
s.Render()
k, _ := ReadKey()