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

Add property to access the main window's width and height #6885

Open
PanCakeConnaisseur opened this issue Nov 24, 2024 · 4 comments
Open

Add property to access the main window's width and height #6885

PanCakeConnaisseur opened this issue Nov 24, 2024 · 4 comments
Labels
enhancement New feature or request need triaging Issue that the owner of the area still need to triage

Comments

@PanCakeConnaisseur
Copy link

PanCakeConnaisseur commented Nov 24, 2024

Feature Description

Please add a global way to access the main window's width and height. AFAIU root only accesses the main components width/height and therefore the main windows's dimensions are not accessible from within a nested component. I imageine, that this would be useful for many scenarios but for me it would be useful to prevent elements from moving out of the window, such as in tooltips.

By main window I mean the thing that windows decorators are applied onto and which can be moved around, minimized, maximized, etc.

Example

component ToolTipArea inherits Window {
  in property <string> text;
  Rectangle {
    // The expression of `x` needs to know how wide the main window is to not
    // let the rectangle leave the main window. `root` here refers to
    // ToolTipArea, but I would like to have the value of MainWindow.width in
    // the variable `mainwindow-width`
    x: max(-parent.absolute-position.x, min(ta.mouse-x + root.x-offset, - parent.absolute-position.x + mainwindow-width - self.width));
    Text {
      text <=> root.text;
    }
  }
  ta := TouchArea {
    HorizontalLayout {
        @children
    }
}
}

component MainWindow inherits Window {
  ToolTipArea {
    text : "This is additional information"
  }
}

Product Impact

No response

@PanCakeConnaisseur PanCakeConnaisseur added enhancement New feature or request need triaging Issue that the owner of the area still need to triage labels Nov 24, 2024
@PanCakeConnaisseur PanCakeConnaisseur changed the title Add property to access the window width and height Add property to access the main window's width and height Nov 24, 2024
@Vadoola
Copy link

Vadoola commented Nov 25, 2024

Perhaps not for a more complicated example, but for the one you presented couldn't you do something like below:

component ToolTipArea inherits Window {
  in property <string> text;
  in property <int> parent-width;
  in property <int> parent-height;
  Rectangle {
    x: max(-parent.absolute-position.x, min(ta.mouse-x + root.x-offset, - parent.absolute-position.x + parent-width - self.width));
    Text {
      text <=> root.text;
    }
  }
  ta := TouchArea {
    HorizontalLayout {
        @children
    }
}
}

component MainWindow inherits Window {
  ToolTipArea {
    text : "This is additional information"
    parent-width = parent.width;
    parent-height = parent.height;
  }
}

@PanCakeConnaisseur
Copy link
Author

PanCakeConnaisseur commented Nov 25, 2024

@Vadoola, this is the workaround I am using right now. The suggested feature would make it possible to avoid this boilerplate code.

@ogoffart
Copy link
Member

Another workaround would be to use a global and use changed event to keep it in sync.

global Helper {
    in property<length> win-height;
}

export component MainWindow inherits Window {
    changed height => {
      Helper.win-height = self.height;
    } 
}

Given all the workarounds, i'm not sure it makes sense to add this feature in Slint.

@PanCakeConnaisseur
Copy link
Author

IMHO this is a fundamental property that should be built-in and not rely on workarounds or helpers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request need triaging Issue that the owner of the area still need to triage
Projects
None yet
Development

No branches or pull requests

3 participants