All Projects → drewhamilton → InlineDimens

drewhamilton / InlineDimens

Licence: Apache-2.0 license
Android dimension types as inline classes with easy conversions.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to InlineDimens

RouteConverter
The popular GPS conversion and editing tool
Stars: ✭ 123 (+127.78%)
Mutual labels:  conversion
omnic
Stateless microservice for on-the-fly thumbs and conversions of a wide variety of file types, utilizing conversion graph.
Stars: ✭ 17 (-68.52%)
Mutual labels:  conversion
dicomifier
A medical image converter
Stars: ✭ 22 (-59.26%)
Mutual labels:  conversion
aspose-words-cloud-node
Node.Js library for communicating with the Aspose.Words Cloud API
Stars: ✭ 20 (-62.96%)
Mutual labels:  conversion
dimcli
Python client and CLI for scientometrics and research analytics using the Dimensions API.
Stars: ✭ 32 (-40.74%)
Mutual labels:  dimensions
G711
PCM to G711 Fast Conversions
Stars: ✭ 39 (-27.78%)
Mutual labels:  conversion
xmind2testlink
Convert xmind to test link xml files, support xmind pro and xmind zen.
Stars: ✭ 99 (+83.33%)
Mutual labels:  conversion
bidscoin
BIDScoin converts your source-level neuroimaging data to BIDS
Stars: ✭ 75 (+38.89%)
Mutual labels:  conversion
bidskit
Utility functions for working with DICOM and BIDS neuroimaging data
Stars: ✭ 52 (-3.7%)
Mutual labels:  conversion
Html2Pdf
Convert Html to Pdf in Android
Stars: ✭ 25 (-53.7%)
Mutual labels:  conversion
ReSampler
High quality command-line audio sample rate converter
Stars: ✭ 120 (+122.22%)
Mutual labels:  conversion
xsampa
X-SAMPA to IPA converter
Stars: ✭ 20 (-62.96%)
Mutual labels:  conversion
pngquant
A Python Wrapper of Pngquant
Stars: ✭ 27 (-50%)
Mutual labels:  conversion
pesa
A JS money lib whose precision goes up to 11 (and beyond).
Stars: ✭ 38 (-29.63%)
Mutual labels:  conversion
retropixels
A cross platform tool to convert images to c64 format.
Stars: ✭ 78 (+44.44%)
Mutual labels:  conversion
ledger2beancount
Ledger to Beancount text-based converter
Stars: ✭ 63 (+16.67%)
Mutual labels:  conversion
CryptionTool
一个CTF+渗透测试工具框架,集成常见加解密,密码、编码转换,端口扫描,字符处理等功能
Stars: ✭ 62 (+14.81%)
Mutual labels:  conversion
physikal
Mirror of Gitlab Repository
Stars: ✭ 33 (-38.89%)
Mutual labels:  conversion
mtgsqlive
MTGJSON build scripts to generate alternative data formats
Stars: ✭ 40 (-25.93%)
Mutual labels:  conversion
tensorflow-tensorrt
Tensorflow to TensorRT Model Converter
Stars: ✭ 30 (-44.44%)
Mutual labels:  conversion

Inline Dimens

Never confuse px, dp, and sp at runtime again. Inline Dimens offers a separate inline class for each dimen type, ensuring compile-time unit confidence without any runtime cost. Extension functions provide the ability to interact with the Android framework directly with these unit-safe types, and to convert between them easily.

Download

Maven Central

Inline Dimens is available on Maven Central. It is experimental, and the API may undergo breaking changes before version 1.0.0.

To use Inline Dimens, include the following in your Gradle dependencies:

implementation "dev.drewhamilton.inlinedimens:inlinedimens:$version"

Usage

Ensure inline classes are enabled in your build.gradle file:

android {
    // ...
    kotlinOptions {
        // ...
        freeCompilerArgs += ["-XXLanguage:+InlineClasses"]
    }
}

Then, work directly with unit-safe types in your code. For example, get a TextView's text size in the unit of your choice:

val scaledTextSize = textView.textSizeSp

And convert between different units at will:

val textSizePx = scaledTextSize.toPx()

Note: Inline classes don't play nicely with Java source code, so this library is unusable in Java source.

License

Copyright 2019 Drew Hamilton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].