Работа над отображением объектов, работа со стилями, работа с позиционированиме, изменение таблицы переменных

This commit is contained in:
XeRo 2026-01-14 18:08:43 +05:00
parent ada7db46cf
commit 2e8eee135e
7 changed files with 477 additions and 431 deletions

View file

@ -73,113 +73,89 @@ func (m *ModalModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
func (m *ModalModel) View() string {
contentWidth := ui.ContentWidth(m.width)
modalWidth := min(contentWidth-10, ui.ModalMaxHeight)
if modalWidth < 60 {
modalWidth = 60
}
content := lipgloss.NewStyle().
Width(modalWidth-8).
Padding(1, 3).
Render(m.message)
containerWidth, containerHeight, _, _ := ui.ContentSizes(m.width, m.height)
modalWidth := min(containerWidth, ui.ModalMaxWidth)
modalHeight := min(containerHeight, ui.ModalMaxHeight)
message := lipgloss.NewStyle().Render(m.message)
var buttons []string
for i, btn := range m.buttons {
for i, button := range m.buttons {
style := ui.ModalButtonNormal
if i == m.focus {
style = ui.ModalButtonFocused
}
buttons = append(buttons, style.Render(btn.Text))
buttons = append(buttons, style.Render(button.Text))
}
buttonRow := lipgloss.JoinHorizontal(lipgloss.Center, buttons...)
modalBody := lipgloss.JoinVertical(lipgloss.Center, message, "", buttonRow)
body := lipgloss.JoinVertical(lipgloss.Center, content, "\n\n", buttonRow)
var borderColor lipgloss.Color
var modalTitleStyle lipgloss.Style
// Бордер и цвет в зависимости от типа
var modalStyle lipgloss.Style
var titleStyle lipgloss.Style
switch m.modalType {
case types.ModalError:
modalStyle = ui.ModalBorderError
titleStyle = ui.ModalTitleError
borderColor = ui.ColorError
modalTitleStyle = ui.ModalTitleError
case types.ModalWarning, types.ModalConfirm:
modalStyle = ui.ModalBorderWarning
titleStyle = ui.ModalTitleWarning
borderColor = ui.ColorWarning
modalTitleStyle = ui.ModalTitleWarning
default:
modalStyle = ui.ModalBorderInfo
titleStyle = ui.ModalTitleDefault
borderColor = ui.ColorAccent
modalTitleStyle = ui.ModalTitleDefault
}
modal := lipgloss.NewStyle().
Width(modalWidth).
Padding(2, 4).
Border(lipgloss.DoubleBorder()).
BorderForeground(modalStyle.GetBorderBottomForeground()).
Render(body)
if m.title != "" {
title := titleStyle.Width(modalWidth).Align(lipgloss.Center).Render(m.title)
modal = lipgloss.JoinVertical(lipgloss.Center, title, modal)
}
return lipgloss.Place(m.width, m.height,
lipgloss.Center, lipgloss.Center,
modal,
lipgloss.WithWhitespaceChars("."),
lipgloss.WithWhitespaceForeground(ui.ColorGrey))
//modalWidth := min(m.width-20, ui.ModalMaxHeight)
//if modalWidth < 60 {
// modalWidth = 60
//}
//var borderColor lipgloss.Color
//var titleStyle lipgloss.Style
//
//switch m.modalType {
//case types.ModalError:
// borderColor = ui.ColorRed
// titleStyle = lipgloss.NewStyle().Foreground(ui.ColorRed).Bold(true)
// modalStyle = ui.ModalBorderError
// modalTitleStyle = ui.ModalTitleError
//case types.ModalWarning, types.ModalConfirm:
// borderColor = ui.ColorPurple
// titleStyle = lipgloss.NewStyle().Foreground(ui.ColorPurple).Bold(true)
// modalStyle = ui.ModalBorderWarning
// modalTitleStyle = ui.ModalTitleWarning
//default:
// borderColor = ui.ColorBlue
// titleStyle = lipgloss.NewStyle().Foreground(ui.ColorBlue).Bold(true)
// modalStyle = ui.ModalBorderInfo
// modalTitleStyle = ui.ModalTitleDefault
//}
//content := lipgloss.NewStyle().Width(m.width-10).Padding(1, 2).Render(m.message)
//var buttons []string
//for i, btn := range m.buttons {
// style := lipgloss.NewStyle().
// Padding(0, 2).
// Border(lipgloss.RoundedBorder()).
// BorderForeground(ui.ColorGrey)
// if i == m.focus {
// style = style.Foreground(ui.ColorRed).BorderForeground(ui.ColorRed).Bold(true)
// } else {
// style = style.Foreground(ui.ColorGreenCyan)
// }
// buttons = append(buttons, style.Render(btn.Text))
//}
//buttonShow := lipgloss.JoinHorizontal(lipgloss.Center, buttons...)
//body := lipgloss.JoinVertical(lipgloss.Center, content, "\n", buttonShow)
//
//modal := lipgloss.NewStyle().
// Width(modalWidth).
// Padding(1, 3).
// Border(lipgloss.DoubleBorder()).
// BorderForeground(borderColor).
// Render(body)
//
//if m.title != "" {
// title := titleStyle.Width(modalWidth - 6).Render(m.title)
// modal = lipgloss.JoinVertical(lipgloss.Center, title, modal)
//}
//
//return lipgloss.Place(m.width, m.height,
// lipgloss.Center, lipgloss.Center,
// modal,
// lipgloss.WithWhitespaceChars("."),
// lipgloss.WithWhitespaceForeground(ui.ColorPurple),
//)
var modalView string
symbolToRepeat := "*"
if m.title != "" {
modalView = ui.ModalContainer.
Width(modalWidth).
Height(modalHeight).
Align(lipgloss.Center, lipgloss.Center).
Border(lipgloss.DoubleBorder()).
BorderForeground(borderColor).
Render(modalBody)
//modalView = ui.ModalContainer.
// Width(modalWidth).
// Height(modalHeight).
// BorderForeground(borderColor).
// Render(modalBody)
//repeatCount := modalWidth - utf8.RuneCountInString(m.title)
//if repeatCount < 0 {
// repeatCount = 0
//}
//symbolFill := strings.Repeat(symbolToRepeat, repeatCount/2)
//modalView = lipgloss.JoinVertical(lipgloss.Center, modalTitleStyle.Render(symbolFill+m.title+symbolFill), modalView)
modalView = lipgloss.JoinVertical(lipgloss.Center, modalTitleStyle.Render(m.title), modalView)
} else {
modalView = ui.ModalContainer.
Width(modalWidth).
Height(modalHeight).
BorderStyle(lipgloss.ASCIIBorder()).
BorderForeground(borderColor).
Render(modalBody)
//modalView = modalStyle.
// Width(modalWidth).
// Height(modalHeight).
// Padding(1, 3).
// Border(lipgloss.DoubleBorder()).
// Render(modalBody)
}
return lipgloss.Place(m.width, m.height,
lipgloss.Center, lipgloss.Center,
modalView,
lipgloss.WithWhitespaceChars(symbolToRepeat),
lipgloss.WithWhitespaceForeground(ui.ColorGrey))
}