GithubHelp home page GithubHelp logo

alienhoboken / electron-viewport Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 4 KB

Helps emulate and scale viewports in Electron

License: MIT License

JavaScript 100.00%
electron viewport window device-emulation emulation browserwindow viewport-size scale electron-viewport scale-viewports

electron-viewport's Introduction

npm npm npm

electron-viewport

electron-viewport helps emulate and scale viewports. Viewport can emulate a device viewport, such as emulating a phone device or 4k display, and can scale a window (maintaining aspect ratio) to fit on screen.

Installation

npm install --save electron-viewport

Instance Properties

viewport.width

Width of the viewport to be represented

viewport.height

Height of the viewport to be represented

viewport.emulate

Boolean indicating whether or not to emulate the given viewport size or simply scale to fit on current display.

viewport.opts

Options passed to BrowserWindow on creation

Instance Methods

viewport.getWindow(width, height[, emulate][, options])

  • width Integer - The width of the viewport to be represented
  • height Integer - The height of the viewport to be represented
  • emulate Boolean (optional) - Whether or not to use device emulation, simulating the actual viewport size given. If false, then the viewport it simply scaled while maintaining aspect ratio. Default is false
  • options Object (optional) - Options to be passed to the BrowserWindow on creation

Creates and returns a BrowserWindow, enabling emulation on it if necessary.

Examples

Getting scaled width and height

var { width, height } = require('electron-viewport')(width, height)

Simply returns scaled dimensions so you may create your own window.

Creating a scaled window

var viewport = require('electron-viewport')(width, height)
var mainWindow = viewport.getWindow()

Creates a scaled BrowserWindow which fits on screen, with the width and height specified.

Scaled window with device emulation

var viewport = require('electron-viewport')(deviceWidth, deviceHeight, true)
var mainWindow = viewport.getWindow()

Creates a scaled BrowserWindow which fits on screen, with device emulation enabled for the passed width and height.

Scaled window with options passed to BrowserWindow

var options = { frame: false } //specify your BrowserWindow options here, just an example
var viewport = require('electron-viewport')(width, height, options)
var mainWindow = viewport.getWindow()

Creates a scaled BrowserWindow which fits on screen, with the given BrowserWindow options being passed

Scaled window with options and device emulation

var options = { frame: false } //specify your BrowserWindow options here, just an example
var viewport = require('electron-viewport')(width, height, true, options)
var mainWindow = viewport.getWindow()

electron-viewport's People

Contributors

alienhoboken avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

electron-viewport's Issues

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.