当前位置:网站首页>Idea has a new artifact, a set of code to adapt to multiple terminals!
Idea has a new artifact, a set of code to adapt to multiple terminals!
2022-06-30 12:30:00 【Migrant worker brother】
Click below “Java Programming duck ” Follow and mark the stars
More exciting First time direct
JetBrains New multi terminal based UI Debugging tools , A set of code to adapt to multiple terminals , It's really great , Let's share with you .
Preface
The tool is famous JetBrains The company's new , called :“Jetpack Compose for Web”, Officials say the project is based on Google modern UI tool kit Jetpack Compose, Support use Kotlin Write responsive Web UI.
Jetpack Compose Is a new tool for building native interfaces Android tool kit . It simplifies and speeds up Android Interface development on . Use less code 、 Powerful tools and intuitive Kotlin API, Quickly make the application vivid and exciting .

UI The code and preview are shown in the figure below :

According to introducing ,Jetpack Compose for Web Can simplify and accelerate Web Applied UI Development , The goal is to Web、 Desktop and Android APP Realization between UI Code sharing , A set of code to adapt to multiple terminals . Currently in the technology preview stage .
fun greet() = listOf("Hello", "Hallo", "Hola", "Servus").random()
renderComposable("greetingContainer") {
var greeting by remember { mutableStateOf(greet()) }
Button(attrs = { onClick { greeting = greet() } }) {
Text(greeting)
}
}
Result: ServusUse Compose for Web Build the user interface
With the help of Compose for Web, Developers use Kotlin And Application Jetpack Compose The concept and API by Web Build a responsive user interface , To express the state of the application 、 Behavior and logic .
Combinable DOM API
adopt DOM Elements and HTML Label expression design and layout
Use type safe HTML DSL structure UI Representation form
By using type safe CSS DSL Create style sheets to fully control the appearance of your application
adopt DOM Subtree and other JavaScript Library Integration
fun main() {
renderComposable("root") {
var platform by remember { mutableStateOf("a platform") }
P {
Text("Welcome to Compose for $platform! ")
Button(attrs = { onClick { platform = "Web" } }) {
Text("...for what?")
}
}
A("https://www.jetbrains.com/lp/compose-web") {
Text("Learn more!")
}
}
}
have Web Supported multi platform widgets
By using Kotlin Of Expect-actual Mechanism to provide platform specific implementation , Thus, it can be used and built in Android、 Desktop and Web Running on Compose The widget
A set of layout primitives in the experimental stage (layout primitives) and API, These primitives and API And Compose for Desktop/Android The functions of are similar
Sample code
Use Composable DOM Write a simple counter
fun main() {
val count = mutableStateOf(0)
renderComposable(rootElementId = "root") {
Button(attrs = {
onClick { count.value = count.value - 1 }
}) {
Text("-")
}
Span(style = { padding(15.px) }) { /* we use inline style here */
Text("${count.value}")
}
Button(attrs = {
onClick { count.value = count.value + 1 }
}) {
Text("+")
}
}
}Declare and use style sheets
object MyStyleSheet : StyleSheet() {
val container by style { /* define a class `container` */
border(1.px, LineStyle.Solid, Color.RGB(255, 0, 0))
}
}
@Composable
fun MyComponent() {
Div(attrs = {
classes(MyStyleSheet.container) /* use `container` class */
}) {
Text("Hello world!")
}
}
fun main() {
renderComposable(rootElementId = "root") {
Style(MyStyleSheet) /* mount the stylesheet */
MyComponent()
}
}Declaration and use CSS Variable
object MyVariables : CSSVariables {
val contentBackgroundColor by variable<Color>() /* declare a variable */
}
object MyStyleSheet: StyleSheet() {
val container by style {
MyVariables.contentBackgroundColor(Color("blue")) /* set its value */
}
val content by style {
backgroundColor(MyVariables.contentBackgroundColor.value()) /* use it */
}
}
@Composable
fun MyComponent() {
Div(attrs = {
classes(MyStyleSheet.container)
}) {
Span(attrs = {
classes(MyStyleSheet.content)
}) {
Text("Hello world!")
}
}
}END
After reading this article, there are gains ? Please forward to share with more people
Focus on 「Java Programming duck 」, promote Java Skill
Focus on Java Programming duck WeChat official account , The background to reply : Yard farm gift bag A copy of the latest technical data can be obtained . cover Java Frame learning 、 Architect learning, etc !
If the article helps , Looking at , Forward! .
Thank you for your support (*^__^*)边栏推荐
- lvgl 小部件样式篇
- SuperMap iClient3D for WebGL 加载TMS瓦片
- 立创 EDA #学习笔记10# | 常用连接器元器件识别 和 无源蜂鸣器驱动电路
- How do different types of variables compare with zero
- 通过EF Core框架根据SQL Server数据库表生成实体类
- SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries
- Joplin实现样式更改
- Subtrate 源码追新导读-5月上旬: XCM 正式启用
- Flutter 从零开始 006 单选开关和复选框
- 90. (cesium chapter) cesium high level listening events
猜你喜欢

SuperMap iDesktop 常见倾斜数据处理全流程解析

【LeetCode】15、三数之和

How to detect 3D line spectral confocal sensors in semiconductors

【目标跟踪】|pytracking 配置 win 编译prroi_pool.pyd

Talk about how to do hardware compatibility testing and quickly migrate to openeuler?

Swagger2自动生成APi文档
![Remove invalid parentheses [simulate stack with array]](/img/df/0a2ae5ae40adb833d52b2dddea291b.png)
Remove invalid parentheses [simulate stack with array]

Analysis of the whole process of common tilt data processing in SuperMap idesktop

Commands for redis basic operations

90. (cesium chapter) cesium high level listening events
随机推荐
Redis的配置文件及新数据类型
SuperMap iServer11i新功能----图例的发布和使用
Instructions for legend use in SuperMap iclient3d 11i for cesium 3D scene
1020. 飞地的数量
[bug solution] fiftyone reports attributeerror: module 'CV2' has no attribute 'GAPI_ wip_ gst_ Gstreamerpipeline 'error resolution
【BUG解决】fiftyone报AttributeError: module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipeline‘错误解决方法
Redis的基本操作的命令
STM32 移植 RT-Thread 标准版的 FinSH 组件
Use of redis in projects
Shutter start from zero 006 radio switches and checkboxes
Videos are stored in a folder every 100 frames, and pictures are transferred to videos after processing
Conference Preview - Huawei 2012 lab global software technology summit - European session
光谱共焦位移传感器的原理是什么?能应用那些领域?
Pinda general permission system (day 7~day 8)
SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries
SuperMap 3D SDKs_Unity插件开发——连接数据服务进行SQL查询
图解使用Navicat for MySQL创建存储过程
Lvgl widget styles
Flutter 从零开始 006 单选开关和复选框
【LeetCode】15、三数之和