Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #249 from lvcabral/fix/centered-title-shift-left-o…
Browse files Browse the repository at this point in the history
…n-resize

Fixed: Title moves to the left after resizing #246
  • Loading branch information
AlexTorresDev authored Dec 19, 2023
2 parents 89bcaf0 + 6ba6f9b commit 338f1b6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/titlebar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ export class CustomTitlebar extends ThemeBar {
}
}

private canCenterTitle() {
const menuBarContainerMargin = 20
const menuSpaceLimit = window.innerWidth / 2 - this.menuBarContainer.getBoundingClientRect().right - menuBarContainerMargin
return (this.title.getBoundingClientRect().width / 2 <= menuSpaceLimit)
}

/// Public methods

/**
Expand Down Expand Up @@ -540,13 +546,15 @@ export class CustomTitlebar extends ThemeBar {

if (menuPosition !== 'bottom') {
addDisposableListener(window, 'resize', () => {
if (window.innerWidth >= 1188) {
if (this.canCenterTitle()) {
addClass(this.title, 'cet-title-center')
} else {
removeClass(this.title, 'cet-title-center')
}
})
addClass(this.title, 'cet-title-center')
if (this.canCenterTitle()) {
addClass(this.title, 'cet-title-center')
}
}

if (!isMacintosh && order === 'first-buttons') {
Expand Down

0 comments on commit 338f1b6

Please sign in to comment.