Guide가이드
Modifier chainsModifier 체인
Kotlin extension functions, as Python methods.Kotlin 확장 함수를 파이썬 메서드로.
implemented구현
Chains, snake_case method names, overload dispatch, Dp as a number, and starting a chain or passing Modifier from the class object (Modifier.padding(16), Card(modifier=Modifier)) are implemented and pass against the binder's adaptation layer (python-multiplatform #324 or later). See the empty Modifier below.
체인, snake_case 메서드 이름, 오버로드 디스패치, 숫자로 쓰는 Dp, 그리고 클래스 객체에서 체인을 시작하거나 Modifier 를 인자로 넘기는 표기(Modifier.padding(16), Card(modifier=Modifier))는 모두 구현되어 바인더의 적응 계층(python-multiplatform #324 이후)에서 통과합니다. 아래 빈 Modifier 를 보세요.
Chaining체이닝
from pythonx.compose.ui import Modifier
m = Modifier.padding(16).size(24).fill_max_width()
Each link returns a new receiver; nothing is mutated. Method names are snake_case (fill_max_width reaches fillMaxWidth): the binder serves the snake_case spelling on its proxies since python-multiplatform #131, while its proxy class keeps Kotlin names in dir(). A name that is not bound raises AttributeError naming the type it looked on.
각 단계는 새 수신 객체를 돌려주며, 아무것도 변경하지 않습니다. 메서드 이름은 snake_case 입니다(fill_max_width 가 fillMaxWidth 에 닿음): python-multiplatform #131 부터 바인더가 프록시에서 snake_case 표기를 제공하고, 바인더의 프록시 클래스 자체는 dir() 에 Kotlin 이름을 유지합니다. 바인딩되지 않은 이름은 어느 타입에서 찾았는지 밝히는 AttributeError 를 냅니다.
Overloads오버로드
Compose declares several padding functions. A call picks one by keyword names, then argument count, then declared type; if none matches, the error lists the candidates.
Compose 는 padding 함수를 여러 개 선언합니다. 호출은 키워드 이름, 인자 개수, 선언 타입 순으로 하나를 고르며, 맞는 것이 없으면 후보를 나열한 오류를 냅니다.
m.padding(16) # all sides
m.padding(horizontal=8, vertical=4) # selected by keyword names
m.padding(1, 2, 3, 4) # selected by argument count
m.padding__Dp(16) # explicit overload: no dispatch
Keywords: method or module function키워드: 메서드와 모듈 함수
The binder maps keywords as well as names (python-multiplatform #131), so a method takes snake_case keywords exactly as the same extension does when called as a module function; inspect.signature shows them. Kotlin's own spelling still works at run time, the type stubs offer only the Pythonic one, and the mapping needs python-multiplatform #131 or later (on an older binder a method's keywords are Kotlin's):
바인더(python-multiplatform #131)는 이름뿐 아니라 키워드도 대응시키므로, 메서드는 같은 확장 함수를 모듈 함수로 부를 때와 똑같이 snake_case 키워드를 받고, inspect.signature 도 그 이름을 보여 줍니다. Kotlin 이름도 실행 시에는 그대로 통하고 타입 스텁은 Pythonic 이름만 제시하며, 이 대응에는 python-multiplatform #131 이상이 필요합니다(오래된 바인더에서는 메서드의 키워드가 Kotlin 이름입니다):
import inspect
import pythonx.compose.layout as layout
values = layout.padding_values_of(8)
m.padding(padding_values=values) # method: snake_case keyword
m.padding(paddingValues=values) # Kotlin spelling still accepted at run time
layout.padding(m, padding_values=values) # module function: snake_case keyword
inspect.signature(layout.padding__PaddingValues)
# (receiver, padding_values)
Numbers and value classes숫자와 값 클래스
Dp takes a raw number because the manifest allows it; a plain Float parameter is just a float; a packed value class such as TextUnit refuses a raw number and says why.
Dp 는 매니페스트가 허용하므로 숫자를 받습니다. 평범한 Float 매개변수는 그냥 float 이고, TextUnit 같은 묶인 값 클래스는 숫자를 거절하며 이유를 밝힙니다.
m.padding(16) # Dp from a number
m.z_index(1.5) # a plain Float
m.padding_from_baseline(16) # TypeError: TextUnit would be reinterpreted
The empty Modifier빈 Modifier
In Kotlin, Modifier as an expression is the companion object Modifier.Companion. Since python-multiplatform #324, a public companion object is bound as Owner.Companion on the proxy class and register_empty accepts the class and a Python callable. pythonx.compose registers register_empty(Modifier, lambda: Modifier.Companion) by default, and pythonx.compose.ui.modifier.install() registers the same default (#138):
Kotlin 에서 식으로 쓰인 Modifier 는 동반 객체 Modifier.Companion 입니다. python-multiplatform #324 부터 공개 동반 객체가 프록시 클래스의 Owner.Companion 값으로 바인딩되고 register_empty 가 클래스와 파이썬 callable 도 받습니다. pythonx.compose 는 기본적으로 register_empty(Modifier, lambda: Modifier.Companion) 을 등록하며, pythonx.compose.ui.modifier.install() 도 같은 기본값을 등록합니다(#138):
from pythonx.compose.ui import Modifier
from pythonx.compose.material3 import Card, Spacer, Text
m = Modifier.padding(16).size(24) # starts from Modifier.Companion
Card(modifier=Modifier, content=lambda s: Text("hi"))
Spacer(modifier=Modifier)
Both the class-object chain (Modifier.padding(16)) and passing the class object itself anywhere a Modifier parameter is expected (Card(modifier=Modifier), Spacer(modifier=Modifier)) evaluate Modifier.Companion (python-multiplatform #308, #324; #134, #138). pythonx.compose.ui.modifier.install(empty_factory) still accepts an explicit Kotlin function name or callable when a test or host overrides the default.
클래스 객체에서 시작하는 체인(Modifier.padding(16))과 Modifier 매개변수가 기대되는 자리에 클래스 객체 자체를 넘기는 표기(Card(modifier=Modifier), Spacer(modifier=Modifier)) 모두 Modifier.Companion 을 평가합니다(python-multiplatform #308, #324; #134, #138). 테스트나 호스트가 기본값을 덮어쓸 때에는 pythonx.compose.ui.modifier.install(empty_factory) 에 명시적 Kotlin 함수 이름이나 callable 을 넘길 수 있습니다.