GithubHelp home page GithubHelp logo

Comments (3)

jglatre avatar jglatre commented on July 21, 2024

Looking source code of OverlayService I see you are applying dpToPx to parameters of resizeOverlay buy not applying it to parameters of showOverlay. I hope that will be a hint.

from flutter_overlay_window.

rorystephenson avatar rorystephenson commented on July 21, 2024

The initial width/height does not take in to account the display metrics whilst resizeOverlay does. A workaround is to apply the display metrics yourself when setting the initial width/height by multiplying your desired size by MediaQuery.devicePixelRatioOf(context). The result is not exactly identical as there seems to be a rounding difference but it should be within 1px.

EDIT: The rounding difference is avoidable. The resizeOverlay method applies the display metrics and then truncates (drops the decimal) the resulting width/height since it needs to be specified as an int. My setting of the initial width/height was rounding up to make sure I have at least as much space as I ask for. Two options to get a more consistent size:

  1. When applying the device pixel ratio to the original width/height, round down. This can result in a slightly lower size than desired.
  2. When calling resizeOverlay we can round up the width/height so that when it is multiplied by the device pixel ratio and then truncated it will be at least as large as our desired width/height. Unfortunately since the arguments to resizeOverlay are ints we cannot totally avoid unnecessary rounding up (without modifying the package). Here is an example method:
  static Future<bool?> resizeOverlay(BuildContext context, Size size) {
    final devicePixelRatio = MediaQuery.devicePixelRatioOf(context);

    final adjustedWidth =
        (((size.width * devicePixelRatio).ceilToDouble()) / devicePixelRatio)
            .ceil();
    final adjustedHeight =
        (((size.height * devicePixelRatio).ceilToDouble()) / devicePixelRatio)
            .ceil();

    return FlutterOverlayWindow.resizeOverlay(adjustedWidth, adjustedHeight);
  }

from flutter_overlay_window.

Ahmadu-Suleiman avatar Ahmadu-Suleiman commented on July 21, 2024

Why was resizeOverlay written that way, seems unnecessary to me. Can someone explain pls?

from flutter_overlay_window.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.