mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
fix: make the login screen layout adapt to resizes
This commit is contained in:
@@ -78,6 +78,7 @@ func (s State) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
Width(msg.Width).
|
Width(msg.Width).
|
||||||
Height(msg.Height)
|
Height(msg.Height)
|
||||||
|
|
||||||
|
s.UI.Login.SetSize(msg.Width, msg.Height)
|
||||||
s.UI.MainScreen.SetSize(msg.Width, msg.Height)
|
s.UI.MainScreen.SetSize(msg.Width, msg.Height)
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
|
|||||||
+21
-9
@@ -31,15 +31,21 @@ type State struct {
|
|||||||
FocusIndex int
|
FocusIndex int
|
||||||
Inputs []textinput.Model
|
Inputs []textinput.Model
|
||||||
TLS bool
|
TLS bool
|
||||||
|
DialogStyle lipgloss.Style
|
||||||
|
WelcomeMsgStyle lipgloss.Style
|
||||||
|
Style lipgloss.Style
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogin() State {
|
func NewLogin() State {
|
||||||
ls := State{
|
state := State{
|
||||||
Inputs: make([]textinput.Model, 5),
|
Inputs: make([]textinput.Model, 5),
|
||||||
|
DialogStyle: DialogStyle.Copy(),
|
||||||
|
WelcomeMsgStyle: WelcomeMsgStyle.Copy(),
|
||||||
|
Style: ui.MainStyle.Copy(),
|
||||||
}
|
}
|
||||||
|
|
||||||
var t textinput.Model
|
var t textinput.Model
|
||||||
for i := range ls.Inputs {
|
for i := range state.Inputs {
|
||||||
t = textinput.New()
|
t = textinput.New()
|
||||||
t.CursorStyle = ui.CursorStyle
|
t.CursorStyle = ui.CursorStyle
|
||||||
t.Prompt = "| "
|
t.Prompt = "| "
|
||||||
@@ -66,10 +72,10 @@ func NewLogin() State {
|
|||||||
t.EchoCharacter = '•'
|
t.EchoCharacter = '•'
|
||||||
}
|
}
|
||||||
|
|
||||||
ls.Inputs[i] = t
|
state.Inputs[i] = t
|
||||||
}
|
}
|
||||||
|
|
||||||
return ls
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
||||||
@@ -78,7 +84,7 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
|||||||
key := msg.String()
|
key := msg.String()
|
||||||
switch key {
|
switch key {
|
||||||
case " ", "enter":
|
case " ", "enter":
|
||||||
// run the newClient cmd when pressing "enter" while focused on the connect button
|
// run the Connect cmd when pressing "enter" while focused on the connect button
|
||||||
if key == "enter" && s.FocusIndex == len(s.Inputs)+1 {
|
if key == "enter" && s.FocusIndex == len(s.Inputs)+1 {
|
||||||
return s, cmds.Connect
|
return s, cmds.Connect
|
||||||
}
|
}
|
||||||
@@ -134,6 +140,14 @@ func (s *State) updateInputs(msg tea.Msg) tea.Cmd {
|
|||||||
return tea.Batch(cmds...)
|
return tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *State) SetSize(width, height int) {
|
||||||
|
s.DialogStyle = s.DialogStyle.Copy().Width(width - s.DialogStyle.GetHorizontalFrameSize())
|
||||||
|
s.DialogStyle = s.DialogStyle.Copy().Height(height*5/10 - s.DialogStyle.GetVerticalFrameSize())
|
||||||
|
|
||||||
|
s.WelcomeMsgStyle = s.WelcomeMsgStyle.Copy().Width(width)
|
||||||
|
s.WelcomeMsgStyle = s.WelcomeMsgStyle.Copy().Height(height * 5 / 10)
|
||||||
|
}
|
||||||
|
|
||||||
func (s State) View() string {
|
func (s State) View() string {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
|
|
||||||
@@ -167,9 +181,7 @@ func (s State) View() string {
|
|||||||
}
|
}
|
||||||
fmt.Fprintf(&sb, "\n%s\n", *button)
|
fmt.Fprintf(&sb, "\n%s\n", *button)
|
||||||
|
|
||||||
screen := lipgloss.JoinVertical(0, WelcomeMsgStyle.Render(WelcomeMsg), ui.DialogStyle.Render(sb.String()))
|
screen := lipgloss.JoinVertical(lipgloss.Center, s.WelcomeMsgStyle.Render(WelcomeMsg), s.DialogStyle.Render(sb.String()))
|
||||||
|
|
||||||
final := lipgloss.Place(ui.MainStyle.GetWidth(), ui.MainStyle.GetHeight(), lipgloss.Center, lipgloss.Top, screen)
|
return ui.MainStyle.Render(screen)
|
||||||
|
|
||||||
return ui.MainStyle.Render(final)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-7
@@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
package login
|
package login
|
||||||
|
|
||||||
import "github.com/charmbracelet/lipgloss"
|
import (
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
)
|
||||||
|
|
||||||
const WelcomeMsg = `
|
const WelcomeMsg = `
|
||||||
|
|
||||||
@@ -33,19 +35,15 @@ const WelcomeMsg = `
|
|||||||
`
|
`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
WelcomeMsgStyle = lipgloss.NewStyle().
|
|
||||||
Padding(0, 5).
|
|
||||||
MarginBottom(5)
|
|
||||||
|
|
||||||
FocusedButton = lipgloss.NewStyle().
|
FocusedButton = lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color("105")).
|
Background(lipgloss.Color("105")).
|
||||||
Foreground(lipgloss.Color("255")).
|
Foreground(lipgloss.Color("#000")).
|
||||||
MarginTop(1).
|
MarginTop(1).
|
||||||
Padding(0, 2).
|
Padding(0, 2).
|
||||||
Align(lipgloss.Center).
|
Align(lipgloss.Center).
|
||||||
Render("Connect")
|
Render("Connect")
|
||||||
BlurredButton = lipgloss.NewStyle().
|
BlurredButton = lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color("#809070")).
|
Background(lipgloss.Color("#505050")).
|
||||||
Foreground(lipgloss.Color("#EEEEEE")).
|
Foreground(lipgloss.Color("#EEEEEE")).
|
||||||
MarginTop(1).
|
MarginTop(1).
|
||||||
Padding(0, 2).
|
Padding(0, 2).
|
||||||
@@ -71,4 +69,10 @@ var (
|
|||||||
Foreground(lipgloss.Color("#EEEEEE")).
|
Foreground(lipgloss.Color("#EEEEEE")).
|
||||||
MarginTop(1).
|
MarginTop(1).
|
||||||
Render("[x] Enable TLS")
|
Render("[x] Enable TLS")
|
||||||
|
|
||||||
|
DialogStyle = lipgloss.NewStyle().
|
||||||
|
Align(lipgloss.Center)
|
||||||
|
|
||||||
|
WelcomeMsgStyle = lipgloss.NewStyle().
|
||||||
|
Align(lipgloss.Center)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,13 +23,6 @@ var (
|
|||||||
Width(0).
|
Width(0).
|
||||||
Height(0)
|
Height(0)
|
||||||
|
|
||||||
DialogStyle = lipgloss.NewStyle().
|
|
||||||
Border(lipgloss.RoundedBorder(), true).
|
|
||||||
Align(lipgloss.Center).
|
|
||||||
Width(50).
|
|
||||||
Padding(3, 6).
|
|
||||||
BorderForeground(lipgloss.Color("105"))
|
|
||||||
|
|
||||||
CursorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("105"))
|
CursorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("105"))
|
||||||
FocusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("105"))
|
FocusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("105"))
|
||||||
NoStyle = lipgloss.NewStyle()
|
NoStyle = lipgloss.NewStyle()
|
||||||
|
|||||||
Reference in New Issue
Block a user