From 83996ab9c3be89392d1914faa0c874d49bfd4c1c Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sun, 9 Feb 2025 19:08:40 +0200 Subject: Added background darkening when opening popups (certain things currently don't get darkened) --- internal/client/ui/auth/auth.go | 6 +++++ internal/client/ui/colors/colors.go | 30 +++++++++++++++++++++ internal/client/ui/core/core.go | 52 +++++++++++++++++++++---------------- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/internal/client/ui/auth/auth.go b/internal/client/ui/auth/auth.go index 32fb232..25c773e 100644 --- a/internal/client/ui/auth/auth.go +++ b/internal/client/ui/auth/auth.go @@ -180,6 +180,10 @@ func (m Model) Init() tea.Cmd { } func (m Model) View() string { + if m.popup != nil { + colors.Darken() + } + var builder strings.Builder var title string @@ -260,6 +264,8 @@ func (m Model) View() string { ) if m.popup != nil { + colors.Restore() + popup := m.popup.View() x := (ui.Width - lipgloss.Width(popup)) / 2 y := (ui.Height - lipgloss.Height(popup)) / 2 diff --git a/internal/client/ui/colors/colors.go b/internal/client/ui/colors/colors.go index 6ab3590..2c11f72 100644 --- a/internal/client/ui/colors/colors.go +++ b/internal/client/ui/colors/colors.go @@ -250,3 +250,33 @@ func IsHex(color string) bool { re := regexp.MustCompile(`^#[0-9A-Fa-f]{6}$`) return re.MatchString(color) } + +func ToHexRGB(r, g, b uint8) string { + return fmt.Sprintf("#%02X%02X%02X", r, g, b) +} + +func Darken() { + Save() + + colors := Get() + for i, color := range colors { + colors[i] = DarkenColor(color, 0.5) + } + + Load(colors) +} + +func DarkenColor(color lipgloss.Color, factor float64) lipgloss.Color { + r, g, b, _ := color.RGBA() + + r8 := uint8(r >> 8) + g8 := uint8(g >> 8) + b8 := uint8(b >> 8) + + // Apply darkening factor (clamping to avoid underflow) + darken := func(c uint8) uint8 { + return uint8(float64(c) * factor) + } + + return lipgloss.Color(ToHexRGB(darken(r8), darken(g8), darken(b8))) +} diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go index 80f5d7a..2122fd0 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -15,6 +15,7 @@ import ( "github.com/charmbracelet/lipgloss" "github.com/kyren223/eko/internal/client/gateway" "github.com/kyren223/eko/internal/client/ui" + "github.com/kyren223/eko/internal/client/ui/colors" "github.com/kyren223/eko/internal/client/ui/core/banreason" "github.com/kyren223/eko/internal/client/ui/core/banview" "github.com/kyren223/eko/internal/client/ui/core/chat" @@ -126,6 +127,10 @@ func (m Model) View() string { return m.loading.View() } + if m.HasPopup() { + colors.Darken() + } + networkList := m.networkList.View() var leftSidebar string if m.networkList.Index() == networklist.SignalsIndex { @@ -143,30 +148,31 @@ func (m Model) View() string { result, ) - var popup string - if m.helpPopup != nil { - popup = m.helpPopup.View() - } else if m.userSettingsPopup != nil { - popup = m.userSettingsPopup.View() - } else if m.networkCreationPopup != nil { - popup = m.networkCreationPopup.View() - } else if m.networkUpdatePopup != nil { - popup = m.networkUpdatePopup.View() - } else if m.frequencyCreationPopup != nil { - popup = m.frequencyCreationPopup.View() - } else if m.frequencyUpdatePopup != nil { - popup = m.frequencyUpdatePopup.View() - } else if m.networkJoinPopup != nil { - popup = m.networkJoinPopup.View() - } else if m.banReasonPopup != nil { - popup = m.banReasonPopup.View() - } else if m.banViewPopup != nil { - popup = m.banViewPopup.View() - } else if m.signalAddPopup != nil { - popup = m.signalAddPopup.View() - } + if m.HasPopup() { + colors.Restore() + var popup string + if m.helpPopup != nil { + popup = m.helpPopup.View() + } else if m.userSettingsPopup != nil { + popup = m.userSettingsPopup.View() + } else if m.networkCreationPopup != nil { + popup = m.networkCreationPopup.View() + } else if m.networkUpdatePopup != nil { + popup = m.networkUpdatePopup.View() + } else if m.frequencyCreationPopup != nil { + popup = m.frequencyCreationPopup.View() + } else if m.frequencyUpdatePopup != nil { + popup = m.frequencyUpdatePopup.View() + } else if m.networkJoinPopup != nil { + popup = m.networkJoinPopup.View() + } else if m.banReasonPopup != nil { + popup = m.banReasonPopup.View() + } else if m.banViewPopup != nil { + popup = m.banViewPopup.View() + } else if m.signalAddPopup != nil { + popup = m.signalAddPopup.View() + } - if popup != "" { x := (ui.Width - lipgloss.Width(popup)) / 2 y := (ui.Height - lipgloss.Height(popup)) / 2 result = ui.PlaceOverlay(x, y, popup, result) -- cgit v1.3.1