Code Monkey home page Code Monkey logo

v9's Introduction

v9

v9 Android build status

v9 is an Android library that provides the ability to dynamically resize Path objects as you would 9-patch bitmaps. In the example below, the chat bubble is dynamically resized while preserving the corners:

v9-demo.mov

Each slice of the original path (indicated by the shaded areas in the example above) defines a horizontal or vertical region of the path that needs to be stretched. A path can be resized using multiple slices:

Screen.Recording.2022-08-26.at.2.42.35.PM.mov

When multiple slices are used, the amount of stretch applied is proportional to the size of each slice. This behavior is used in the example above to keep the dark bars centered vertically and to spaced them equally horizontally, thus properly preserving details inside the path.

v9 is compatible with API 21+.

Maven

repositories {
    // ...
    mavenCentral()
}

dependencies {
    implementation 'dev.romainguy:v9:0.1.0'
}

How to use

Slicing a Path gives you a PathResizer. The easiest way to slice is to use a single vertical and a single horizontal slice:

val pathResizer = path.slice(Slices(9.0f, 7.0f, 15.0f, 13.0f))

This syntax follows the rectangle convention on Android of passing the top, left, right, and bottom coordinates: there's a vertical slice from 9.0 to 15.0 and a horizontal slice from 7.0 to 13.0.

You can also explicitly declare a list of slices:

val pathResizer = path.slice(
    Slices(
        listOf(Slice(9.0f, 10.0f), Slice(14.0f, 15.0f)),
        listOf(Slice(5.0f, 6.0f),  Slice(18.0f, 19.0f))
    )
)

Once you have a PathResizer, you can call the resize() method to create a new path derived from the original, at the desired size:

val resizedPath = pathResizer.resize(width, height)

For performance considerations, you can pass an existing path to resize(). This path will be rewound and returned:

val resizedPath = pathResizer.resize(width, height, destinationpath)
// resizedPath === destinationpath

License

Please see LICENSE.

v9's People

Contributors

romainguy avatar

Watchers

 avatar

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.