styling
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user