Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setSize need reset the position #349

Open
binvb opened this issue Jul 8, 2021 · 4 comments
Open

setSize need reset the position #349

binvb opened this issue Jul 8, 2021 · 4 comments

Comments

@binvb
Copy link
Contributor

binvb commented Jul 8, 2021

Description

when i use mb.window.setSize(150, height) change the size, it need to reset the position

Steps to Reproduce the Problem

  1. traySide is 'bottom'
  2. focus in mb window
  3. mb.window.setSize(150, height)
  4. part of mb window is over hidden

Expected Behaviour

reset the position when setSize()

Actual Behaviour

Specifications

  • Menubar version: 9.0.5
  • Platform: windows
  • Electron version: (Run electron -v or node_modules/.bin/electron -v to get it)

Other information

@binvb
Copy link
Contributor Author

binvb commented Jul 8, 2021

solution:

    TrayWindow.window.setSize(150, height)
    TrayWindow.showWindow()

use showWindow reset position

@binvb
Copy link
Contributor Author

binvb commented Jul 8, 2021

but still need to work out, here are some solution:
1 expose the position reset function;
2 take over the setSize function(setBounds either);
3 listening 'resize', and reset the position

@vicke4
Copy link
Contributor

vicke4 commented Jul 9, 2021

I'm doing it manually for my app. Before setting the size, you can position the window using setBounds method. When the height is changed, you can do this,

import { taskbarLocation } from 'menubar';
import { is } from 'electron-util';

import { menubar } from './main'; 

const [x, y] = menubar.window?.getPosition();
const newHeight = 400;
const newWidth = 200;
const barLocation = taskbarLocation(menubar.tray);
const [width, height] = menubar.window?.getSize() || [];

// mac will always be on top so we don't have to do anything for mac
if (is.windows || is.linux) {
    let newX, newY;
    
    const [x, y] = menubar.window?.getPosition() || [];
    newX = x;
    newY = y;

    // Workaround for the window positioning issue
    if (barLocation !== 'top') {
      if (!newHeight) newY = y;
      else newY = y - (newHeight - height);
    }

    menubar.window?.setBounds({
      x: newX,
      y: newY,
      width: newWidth || width,
      height: h || height,
    });  
}

menubar.window?.setSize(newWidth || width, newHeight || height, true);

@binvb
Copy link
Contributor Author

binvb commented Jul 10, 2021

I'm doing it manually for my app. Before setting the size, you can position the window using setBounds method. When the height is changed, you can do this,

import { taskbarLocation } from 'menubar';
import { is } from 'electron-util';

import { menubar } from './main'; 

const [x, y] = menubar.window?.getPosition();
const newHeight = 400;
const newWidth = 200;
const barLocation = taskbarLocation(menubar.tray);
const [width, height] = menubar.window?.getSize() || [];

// mac will always be on top so we don't have to do anything for mac
if (is.windows || is.linux) {
    let newX, newY;
    
    const [x, y] = menubar.window?.getPosition() || [];
    newX = x;
    newY = y;

    // Workaround for the window positioning issue
    if (barLocation !== 'top') {
      if (!newHeight) newY = y;
      else newY = y - (newHeight - height);
    }

    menubar.window?.setBounds({
      x: newX,
      y: newY,
      width: newWidth || width,
      height: h || height,
    });  
}

menubar.window?.setSize(newWidth || width, newHeight || height, true);

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants