Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desktop/internal/i18n/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var english = Messages{
App: appMessages(English),
Welcome: welcomeMessages(English),
Title: titleMessages(English),
Window: windowMessages(English),
Tools: toolMessages(English),
Dock: dockMessages(English),
Panel: panelMessages(English),
Expand Down
10 changes: 10 additions & 0 deletions desktop/internal/i18n/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Messages struct {
App AppMessages
Welcome WelcomeMessages
Title TitleMessages
Window WindowMessages
Tools ToolMessages
Dock DockMessages
Panel PanelMessages
Expand Down Expand Up @@ -60,6 +61,15 @@ type WelcomeMessages struct {
Missing string
}

// WindowMessages names the minimize, maximize, restore and close buttons that Viva draws
// in the title bar on Windows and Linux. Assistive technology reads them.
type WindowMessages struct {
Minimize string
Maximize string
Restore string
Close string
}

// TitleMessages are the workbench title bar's words.
type TitleMessages struct {
ProjectMenu string
Expand Down
8 changes: 8 additions & 0 deletions desktop/internal/i18n/shared.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions desktop/internal/i18n/window_messages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package i18n

// windowMessages reads the names of the window buttons from the shared catalog.
func windowMessages(language Language) WindowMessages {
return WindowMessages{
Minimize: Shared(language, "window.minimize"),
Maximize: Shared(language, "window.maximize"),
Restore: Shared(language, "window.restore"),
Close: Shared(language, "window.close"),
}
}
1 change: 1 addition & 0 deletions desktop/internal/i18n/zh.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var chinese = Messages{
App: appMessages(Chinese),
Welcome: welcomeMessages(Chinese),
Title: titleMessages(Chinese),
Window: windowMessages(Chinese),
Tools: toolMessages(Chinese),
Dock: dockMessages(Chinese),
Panel: panelMessages(Chinese),
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/logwindow/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/1lck/Lithe-IDEA/desktop/internal/icons"
"github.com/1lck/Lithe-IDEA/desktop/internal/sysinfo"
"github.com/1lck/Lithe-IDEA/desktop/internal/windowcontrols"
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/components"
"github.com/vivaui/viva/gfx"
Expand Down Expand Up @@ -281,6 +282,7 @@ func (w *window) config() app.Config {
MinHeight: 500,
WindowMode: app.WindowCustomTitlebar,
TitlebarHeight: titleHeight,
WindowControls: func() app.WindowControlsStyle { return windowcontrols.Style(w.pal.tx, w.ctrl.text()) },
Tree: &tree,
Paint: w.paint,
OnKey: w.onKey,
Expand Down
39 changes: 39 additions & 0 deletions desktop/internal/logwindow/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/ui"
)

Expand Down Expand Up @@ -35,3 +36,41 @@ func TestOpenWindowRepaintsWhenLanguageAndAppearanceChange(t *testing.T) {
t.Fatal("the open log window did not repaint with the new appearance")
}
}

// TestWindowControlsFollowTheTitleBar covers the buttons Viva draws in the custom title bar on
// Windows and Linux: unstyled, they took Viva's ink for its default dark clear color and were
// white on the light title bar. They must take the ink of the title bar and the language of
// the window, and follow both when they change.
func TestWindowControlsFollowTheTitleBar(t *testing.T) {
fixture := newExportFixture(t)
var current atomic.Pointer[i18n.Messages]
var dark atomic.Bool
current.Store(i18n.For(i18n.English))
controller := NewController(WindowOptions{Text: current.Load, Dark: dark.Load})
w := &window{ctrl: controller, model: fixture.model, filterRevision: -1, anchors: map[menuKind]ui.Box{}}
controller.current = w
config := w.config()
if config.WindowControls == nil {
t.Fatal("the log window leaves its window buttons to Viva's default ink")
}
driver, err := app.NewDriver(config, nil)
if err != nil {
t.Fatal(err)
}
t.Cleanup(driver.Close)
check := func(look string, ink gfx.Color, minimize string) {
t.Helper()
style := config.WindowControls()
if style.Foreground != ink || style.Minimize != minimize {
t.Fatalf("%s look: glyph color %v and minimize name %q, want %v and %q", look, style.Foreground, style.Minimize, ink, minimize)
}
}
check("light", lightPalette().tx, "Minimize")
current.Store(i18n.For(i18n.Chinese))
dark.Store(true)
controller.Invalidate()
if err := driver.Pump(); err != nil {
t.Fatal(err)
}
check("dark", darkPalette().tx, "最小化")
}
32 changes: 32 additions & 0 deletions desktop/internal/settingswindow/general_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,35 @@ func TestGeneralNarrowWindowKeepsSystemAppearanceVisible(t *testing.T) {
}
t.Fatalf("system appearance label %q is missing", want)
}

// TestWindowControlsFollowTheTitleBar covers the buttons Viva draws in the custom title bar on
// Windows and Linux: unstyled, they took Viva's ink for its default dark clear color and were
// white on the light title bar. They must take the ink of the title bar and the language of
// the client, and follow the look when it changes.
func TestWindowControlsFollowTheTitleBar(t *testing.T) {
w := newWindow(NewController(Options{Text: func() *i18n.Messages { return i18n.For(i18n.Chinese) }}),
Values{Language: "zh-Hans", Theme: themeLight})
config := w.config()
if config.WindowControls == nil {
t.Fatal("the settings window leaves its window buttons to Viva's default ink")
}
driver, err := app.NewDriver(config, nil)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { w.market.close(); driver.Close() })
check := func(look string, ink gfx.Color) {
t.Helper()
style := config.WindowControls()
if style.Foreground != ink || style.Minimize != "最小化" {
t.Fatalf("%s look: glyph color %v and minimize name %q, want %v and %q", look, style.Foreground, style.Minimize, ink, "最小化")
}
}
check("light", lightPalette().text)
w.sess.values.Theme = themeDark
w.inv.Invalidate()
if err := driver.Pump(); err != nil {
t.Fatal(err)
}
check("dark", darkPalette().text)
}
2 changes: 2 additions & 0 deletions desktop/internal/settingswindow/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/1lck/Lithe-IDEA/desktop/internal/icons"
"github.com/1lck/Lithe-IDEA/desktop/internal/splitpane"
"github.com/1lck/Lithe-IDEA/desktop/internal/windowcontrols"
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/components"
"github.com/vivaui/viva/gfx"
Expand Down Expand Up @@ -200,6 +201,7 @@ func (w *window) config() app.Config {
MinHeight: windowMinHeight,
WindowMode: app.WindowCustomTitlebar,
TitlebarHeight: titleHeight,
WindowControls: func() app.WindowControlsStyle { return windowcontrols.Style(w.pal.text, w.ctrl.text()) },
Tree: &tree,
Paint: w.paint,
OnKey: w.onKey,
Expand Down
42 changes: 42 additions & 0 deletions desktop/internal/windowcontrols/style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Package windowcontrols styles the minimize, maximize and close buttons that Viva draws in
// a custom title bar on Windows and Linux (macOS keeps its own traffic lights).
//
// Without a style Viva takes the glyph color from the window's clear color, which is dark
// by default and is not the color of the title bar the buttons stand on: in the light look
// the glyphs were white on a light title bar and could not be seen. Every window of the
// client therefore styles its buttons from the ink of its own title bar.
package windowcontrols

import (
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/gfx"
)

const (
// hoverAlpha and pressedAlpha are the opacity of the ink behind a button under the
// pointer and while it is held down: the tints Viva itself uses, taken from the
// title bar's ink instead of the clear color.
hoverAlpha = 0.10
pressedAlpha = 0.18
)

// Style is the buttons' style on a title bar whose text is ink: the glyphs in ink, the
// hover and press tints ink at low opacity, and the names in the user's language. The
// close button keeps Viva's red. A zero ink (a window that has not painted yet) leaves
// the colors to Viva.
func Style(ink gfx.Color, text *i18n.Messages) app.WindowControlsStyle {
var style app.WindowControlsStyle
if ink != (gfx.Color{}) {
style.Foreground = ink
style.Hover = ink.WithAlpha(hoverAlpha)
style.Pressed = ink.WithAlpha(pressedAlpha)
}
if text != nil {
style.Minimize = text.Window.Minimize
style.Maximize = text.Window.Maximize
style.Restore = text.Window.Restore
style.CloseName = text.Window.Close
}
return style
}
51 changes: 51 additions & 0 deletions desktop/internal/windowcontrols/style_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package windowcontrols

import (
"testing"

"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/gfx"
)

// TestStyleDrawsTheButtonsInTheTitleBarInk covers the light look: Viva takes the default
// glyph color from the clear color, which is dark, so the glyphs came out white on the
// light title bar. The buttons must take the title bar's ink, and their tints with it.
func TestStyleDrawsTheButtonsInTheTitleBarInk(t *testing.T) {
ink := gfx.RGB24(0x1F2328)
style := Style(ink, i18n.For(i18n.English))
if style.Foreground != ink {
t.Fatalf("glyph color = %v, want the title bar's ink %v", style.Foreground, ink)
}
if style.Hover != ink.WithAlpha(hoverAlpha) || style.Pressed != ink.WithAlpha(pressedAlpha) {
t.Fatalf("hover and press tints = %v and %v, want the ink at %v and %v", style.Hover, style.Pressed, hoverAlpha, pressedAlpha)
}
if style.Close != (gfx.Color{}) || style.CloseForeground != (gfx.Color{}) {
t.Fatalf("close button colors = %v and %v, want them left to Viva's red", style.Close, style.CloseForeground)
}
}

func TestStyleNamesTheButtonsInTheUsersLanguage(t *testing.T) {
for _, test := range []struct {
language i18n.Language
want [4]string
}{
{i18n.English, [4]string{"Minimize", "Maximize", "Restore", "Close"}},
{i18n.Chinese, [4]string{"最小化", "最大化", "还原", "关闭"}},
} {
style := Style(gfx.RGB24(0x1F2328), i18n.For(test.language))
got := [4]string{style.Minimize, style.Maximize, style.Restore, style.CloseName}
if got != test.want {
t.Fatalf("language %s: button names = %q, want %q", test.language.Code(), got, test.want)
}
}
}

// TestStyleLeavesToVivaWhatItIsNotGiven covers a window asked for its style before its first
// paint, when it has no ink and no catalog yet: Viva's defaults must stand, not black glyphs
// on black tints or nameless buttons.
func TestStyleLeavesToVivaWhatItIsNotGiven(t *testing.T) {
if style := Style(gfx.Color{}, nil); style != (app.WindowControlsStyle{}) {
t.Fatalf("style without ink or catalog = %+v, want the zero style", style)
}
}
2 changes: 2 additions & 0 deletions desktop/internal/workbench/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice"
"github.com/1lck/Lithe-IDEA/desktop/internal/settingswindow"
"github.com/1lck/Lithe-IDEA/desktop/internal/store"
"github.com/1lck/Lithe-IDEA/desktop/internal/windowcontrols"
"github.com/vivaui/viva/app"
"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/ui"
Expand Down Expand Up @@ -403,6 +404,7 @@ func (a *App) Config() app.Config {
MinHeight: 600,
WindowMode: app.WindowCustomTitlebar,
TitlebarHeight: titleBarHeight,
WindowControls: func() app.WindowControlsStyle { return windowcontrols.Style(a.colors.Text, a.text) },
Tree: &tree,
Paint: a.paint,
OnPointer: a.onPointer,
Expand Down
34 changes: 31 additions & 3 deletions desktop/internal/workbench/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ func (k *testKernel) ReduceChromeLayout(ctx context.Context, catalog []core.Chro

// harness is a window driven without a screen.
type harness struct {
t testing.TB
app *App
t testing.TB
app *App
// config is the configuration the driver runs, so a test reads the callbacks the
// window was opened with instead of building a second configuration.
config app.Config
driver *app.Driver
store *store.Store
}
Expand Down Expand Up @@ -78,7 +81,8 @@ func newHarnessWithLanguages(t testing.TB, kernel Kernel, languages []string) *h
return start.Add(h.driver.Now())
},
})
driver, err := app.NewDriver(h.app.Config(), nil)
h.config = h.app.Config()
driver, err := app.NewDriver(h.config, nil)
if err != nil {
t.Fatalf("NewDriver: %v", err)
}
Expand Down Expand Up @@ -802,6 +806,30 @@ func TestMarketplaceWidthPersistsWithOtherSettings(t *testing.T) {
}
}

// TestWindowControlsFollowTheTitleBar covers the buttons Viva draws in the custom title bar on
// Windows and Linux: unstyled, they took Viva's ink for its default dark clear color and were
// white on the light title bar. They must take the ink of the title bar and the language of
// the window, and follow both when they change.
func TestWindowControlsFollowTheTitleBar(t *testing.T) {
h := newHarness(t, &testKernel{Client: core.NewClient()})
if h.config.WindowControls == nil {
t.Fatal("the workbench leaves its window buttons to Viva's default ink")
}
check := func(look string, ink gfx.Color, minimize string) {
t.Helper()
style := h.config.WindowControls()
if style.Foreground != ink || style.Minimize != minimize {
t.Fatalf("%s look: glyph color %v and minimize name %q, want %v and %q", look, style.Foreground, style.Minimize, ink, minimize)
}
}
_, darkColors := darkLook()
check("dark", darkColors.Text, "最小化")
h.app.setLanguage("en")
h.app.setTheme(themeLight)
_, lightColors := lightLook()
check("light", lightColors.Text, "Minimize")
}

func TestSettingsChangesUpdateSharedStateAndPersist(t *testing.T) {
h := newHarness(t, &testKernel{Client: core.NewClient()})
h.app.setLanguage("en")
Expand Down
12 changes: 8 additions & 4 deletions shared/i18n/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -98031,14 +98031,16 @@
"id": "window.close",
"description": "Windows UI: window.close",
"platforms": [
"windows"
"windows",
"desktop"
]
},
{
"id": "window.maximize",
"description": "Windows UI: window.maximize",
"platforms": [
"windows"
"windows",
"desktop"
]
},
{
Expand All @@ -98052,14 +98054,16 @@
"id": "window.minimize",
"description": "Windows UI: window.minimize",
"platforms": [
"windows"
"windows",
"desktop"
]
},
{
"id": "window.restore",
"description": "Windows UI: window.restore",
"platforms": [
"windows"
"windows",
"desktop"
]
},
{
Expand Down
Loading
Loading