From 2692799e69eb7aa7d1e708d6b1db6b44a109c342 Mon Sep 17 00:00:00 2001 From: aOK Date: Sat, 17 Aug 2024 20:37:11 +0300 Subject: [PATCH] added web and mobile screen minimal support --- Cargo.lock | 287 +++++++++++++++++++++++++++++++++++----- Cargo.toml | 4 +- src/app.rs | 166 ++++++++++++----------- src/app_mobile.rs | 52 +------- src/app_ui.rs | 71 +++++++--- src/home/home_screen.rs | 27 ++-- src/shared/styles.rs | 28 ++++ src/shared/widgets.rs | 85 ++++++++++++ 8 files changed, 526 insertions(+), 194 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c66d55..e3ae095 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,30 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "arrayref" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "1.3.2" @@ -32,6 +56,52 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "data-url" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" + +[[package]] +name = "fdeflate" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f9bfee30e4dedf0ab8b422f03af778d9612b63f502710fc500a334ebe2de645" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "flate2" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f211bbe8e69bbd0cfdea405084f128ae8b4aaa6b0b522fc8f2b009084797920" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" + [[package]] name = "fxhash" version = "0.2.1" @@ -41,6 +111,28 @@ dependencies = [ "byteorder", ] +[[package]] +name = "imagesize" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d73f573d8e8d63e6d5020011d3255b28c3ba85d6cf870a07184ed23de9284" + +[[package]] +name = "kurbo" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e5aa9f0f96a938266bdb12928a67169e8d22c6a786fda8ed984b85e6ba93c3c" +dependencies = [ + "arrayvec", + "smallvec", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + [[package]] name = "makepad-android-state" version = "0.1.0" @@ -53,7 +145,6 @@ dependencies = [ [[package]] name = "makepad-derive-live" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-live-id", "makepad-micro-proc-macro", @@ -62,7 +153,6 @@ dependencies = [ [[package]] name = "makepad-derive-wasm-bridge" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-micro-proc-macro", ] @@ -70,7 +160,6 @@ dependencies = [ [[package]] name = "makepad-derive-widget" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-live-id", "makepad-micro-proc-macro", @@ -79,7 +168,6 @@ dependencies = [ [[package]] name = "makepad-draw" version = "0.6.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "ab_glyph_rasterizer", "fxhash", @@ -89,22 +177,21 @@ dependencies = [ "makepad-vector", "sdfer", "unicode-bidi", + "unicode-linebreak", + "unicode-segmentation", ] [[package]] name = "makepad-futures" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" [[package]] name = "makepad-futures-legacy" version = "0.7.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" [[package]] name = "makepad-html" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-live-id", ] @@ -112,7 +199,6 @@ dependencies = [ [[package]] name = "makepad-http" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" [[package]] name = "makepad-jni-sys" @@ -123,7 +209,6 @@ checksum = "9775cbec5fa0647500c3e5de7c850280a88335d1d2d770e5aa2332b801ba7064" [[package]] name = "makepad-live-compiler" version = "0.5.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-derive-live", "makepad-live-tokenizer", @@ -133,7 +218,6 @@ dependencies = [ [[package]] name = "makepad-live-id" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-live-id-macros", ] @@ -141,7 +225,6 @@ dependencies = [ [[package]] name = "makepad-live-id-macros" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-micro-proc-macro", ] @@ -149,7 +232,6 @@ dependencies = [ [[package]] name = "makepad-live-tokenizer" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-live-id", "makepad-math", @@ -159,7 +241,6 @@ dependencies = [ [[package]] name = "makepad-markdown" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-live-id", ] @@ -167,17 +248,14 @@ dependencies = [ [[package]] name = "makepad-math" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" [[package]] name = "makepad-micro-proc-macro" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" [[package]] name = "makepad-micro-serde" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-micro-serde-derive", ] @@ -185,7 +263,6 @@ dependencies = [ [[package]] name = "makepad-micro-serde-derive" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-micro-proc-macro", ] @@ -193,12 +270,10 @@ dependencies = [ [[package]] name = "makepad-objc-sys" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" [[package]] name = "makepad-platform" version = "0.6.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-android-state", "makepad-futures", @@ -216,7 +291,6 @@ dependencies = [ [[package]] name = "makepad-rustybuzz" version = "0.8.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -231,7 +305,6 @@ dependencies = [ [[package]] name = "makepad-shader-compiler" version = "0.5.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-live-compiler", ] @@ -239,15 +312,14 @@ dependencies = [ [[package]] name = "makepad-vector" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ + "resvg", "ttf-parser", ] [[package]] name = "makepad-wasm-bridge" version = "0.4.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-derive-wasm-bridge", "makepad-live-id", @@ -256,7 +328,6 @@ dependencies = [ [[package]] name = "makepad-widgets" version = "0.6.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-derive-widget", "makepad-draw", @@ -264,12 +335,12 @@ dependencies = [ "makepad-markdown", "makepad-zune-jpeg", "makepad-zune-png", + "unicode-segmentation", ] [[package]] name = "makepad-windows" version = "0.51.1" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "windows-core", "windows-targets", @@ -278,7 +349,6 @@ dependencies = [ [[package]] name = "makepad-zune-core" version = "0.2.14" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "bitflags 2.6.0", ] @@ -286,7 +356,6 @@ dependencies = [ [[package]] name = "makepad-zune-inflate" version = "0.2.54" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "simd-adler32", ] @@ -294,7 +363,6 @@ dependencies = [ [[package]] name = "makepad-zune-jpeg" version = "0.3.17" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-zune-core", ] @@ -302,12 +370,69 @@ dependencies = [ [[package]] name = "makepad-zune-png" version = "0.2.1" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "makepad-zune-core", "makepad-zune-inflate", ] +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", + "simd-adler32", +] + +[[package]] +name = "pico-args" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" + +[[package]] +name = "png" +version = "0.17.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide", +] + +[[package]] +name = "resvg" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "944d052815156ac8fa77eaac055220e95ba0b01fa8887108ca710c03805d9051" +dependencies = [ + "log", + "pico-args", + "rgb", + "svgtypes", + "tiny-skia", + "usvg", +] + +[[package]] +name = "rgb" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f86ae463694029097b846d8f99fd5536740602ae00022c0c50c5600720b2f71" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "roxmltree" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" + [[package]] name = "salamu" version = "0.6.0" @@ -327,16 +452,75 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "simplecss" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a11be7c62927d9427e9f40f3444d5499d868648e2edbc4e2116de69e7ec0e89d" +dependencies = [ + "log", +] + +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "strict-num" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" +dependencies = [ + "float-cmp", +] + +[[package]] +name = "svgtypes" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fae3064df9b89391c9a76a0425a69d124aee9c5c28455204709e72c39868a43c" +dependencies = [ + "kurbo", + "siphasher", +] + +[[package]] +name = "tiny-skia" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab" +dependencies = [ + "arrayref", + "arrayvec", + "bytemuck", + "cfg-if", + "log", + "png", + "tiny-skia-path", +] + +[[package]] +name = "tiny-skia-path" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93" +dependencies = [ + "arrayref", + "bytemuck", + "strict-num", +] + [[package]] name = "ttf-parser" -version = "0.19.0" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" +version = "0.21.1" [[package]] name = "unicode-bidi" @@ -356,6 +540,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc2520efa644f8268dce4dcd3050eaa7fc044fca03961e9998ac7e2e92b77cf1" +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + [[package]] name = "unicode-properties" version = "0.1.1" @@ -368,10 +558,37 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad8d71f5726e5f285a935e9fe8edfd53f0491eb6e9a5774097fdabee7cd8c9cd" +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "usvg" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84ea542ae85c715f07b082438a4231c3760539d902e11d093847a0b22963032" +dependencies = [ + "base64", + "data-url", + "flate2", + "imagesize", + "kurbo", + "log", + "pico-args", + "roxmltree", + "simplecss", + "siphasher", + "strict-num", + "svgtypes", + "tiny-skia-path", + "xmlwriter", +] + [[package]] name = "windows-core" version = "0.51.1" -source = "git+https://github.com/jmbejar/makepad?branch=moxin-release-v1#feaf1cdcc49e44cae9d3d3e202a20e44fca5e53d" dependencies = [ "windows-targets", ] @@ -432,3 +649,9 @@ name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "xmlwriter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" diff --git a/Cargo.toml b/Cargo.toml index 7f3cec7..44f5ddf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,5 @@ license = "MIT OR Apache-2.0" metadata.makepad-auto-version = "db3R5Gxh5Njhx8E-8kuZ2plQ1AI=" [dependencies] -# makepad-widgets = { path = "../makepad/widgets", version = "0.6.0" } -makepad-widgets = { git = "https://github.com/jmbejar/makepad", branch = "moxin-release-v1" } +makepad-widgets = { path = "../makepad/widgets", version = "0.6.0" } +# makepad-widgets = { git = "https://github.com/jmbejar/makepad", branch = "moxin-release-v1" } diff --git a/src/app.rs b/src/app.rs index e7cfff1..c9d0549 100644 --- a/src/app.rs +++ b/src/app.rs @@ -6,60 +6,16 @@ live_design! { import makepad_widgets::theme_desktop_dark::*; import makepad_draw::shader::std::*; - import crate::shared::styles::*; import crate::app_ui::AppUI; import crate::app_mobile::AppMobileUI; - import crate::shared::widgets::SidebarMenuButton; - ICON_DISCOVER = dep("crate://self/resources/icons/discover.svg") - ICON_CHAT = dep("crate://self/resources/icons/chat.svg") - ICON_MY_MODELS = dep("crate://self/resources/icons/my_models.svg") App = {{App}} { - // ui: { - // { - // window: {inner_size: vec2(800, 600)}, - // caption_bar = {visible: true, caption_label = {label = {text: "Serial"}}}, - // hide_caption_on_fullscreen: true, - // // body = {} - // body = {} - // } - // } - ui: { main_window = { window: {inner_size: vec2(800, 600)}, - // pass: {clear_color: #fff} - - // show_bg: true - // width: Fill, - // height: Fill - - // draw_bg: { - // // instance opacity: 1.0 - - // // fn pixel(self) -> vec4 { - // // let color = sample2d_rt(self.image, self.pos * self.scale + self.shift) + vec4(self.marked, 0.0, 0.0, 0.0); - // // return Pal::premul(vec4(color.xyz, color.w * self.opacity)) - // // } - - // // fn pixel(self) -> vec4 { // < --- Apply error: examples/simple/src/app.rs:21:20 - property: pixel target class not found - // // // 获取几何位置 - // // let st = vec2( - // // self.geom_pos.x, - // // self.geom_pos.y - // // ); - - // // // 计算颜色,基于 x 和 y 位置及时间 - // // let color = vec3(st.x, st.y, abs(sin(self.time))); - // // return vec4(color, 1.0); - // // } - // } - - // body = {} - body = { flow: Overlay width: Fill, @@ -68,34 +24,10 @@ live_design! { root = { width: Fill, height: Fill, - // navbar_menu = { - // width: 100, - // flow: Down, spacing: 20.0, - // padding: { top: 80 } - - // align: {x: 0.5, y: 0.0}, - - // show_bg: true, - // draw_bg: { - // color: (SIDEBAR_BG_COLOR), - // instance radius: 0.0, - // border_color: #EAECF0, - // border_width: 1.2, - // } - - // discover_tab = { - // animator: {selected = {default: on}} - // text: "Home", - // draw_icon: { - // svg_file: (ICON_DISCOVER), - // } - // } - // } - {} - // {} + mobile = {} + web = {} } } - } } } @@ -103,12 +35,19 @@ live_design! { app_main!(App); -#[derive(Live, LiveHook)] +enum ScreenSize { + Mobile, + Web, +} + +#[derive(Live)] pub struct App { #[live] ui: WidgetRef, // #[rust] // counter: usize, + #[rust] + screen_width: f64, } impl LiveRegister for App { @@ -121,21 +60,90 @@ impl LiveRegister for App { crate::shared::live_design(cx); } } +impl LiveHook for App { + fn after_new_from_doc(&mut self, cx: &mut Cx) { + let mobile_screen = self.ui.view(id!(mobile)); + let web_screen = self.ui.view(id!(web)); + if self.screen_width < 960_f64 { + log!("SCREEN_WIDTH ===> {}", self.screen_width); + web_screen.set_visible(false); + mobile_screen.set_visible_and_redraw(cx, true); + } else if self.screen_width > 960_f64 { + mobile_screen.set_visible(false); + web_screen.set_visible_and_redraw(cx, true); + } else { + log!("SCREEN_WIDTH ===> {}", self.screen_width); + } + } +} impl MatchEvent for App { - fn handle_actions(&mut self, _cx: &mut Cx, _actions: &Actions) { - // if self.ui.button(id!(button1)).clicked(&actions) { - // log!("Press button {}", self.counter); - // self.counter += 1; - // let label = self.ui.label(id!(label1)); - // label.set_text_and_redraw(cx, &format!("Counter: {}", self.counter)); - // //log!("TOTAL : {}",TrackingHeap.total()); - // } + fn handle_draw_2d(&mut self, cx: &mut Cx2d) { + let mobile_screen = self.ui.view(id!(mobile)); + let web_screen = self.ui.view(id!(web)); + + while let Some(next) = self.ui.draw(cx, &mut Scope::empty()).step() { + // if let Some(mut mobile_screen) = mobile_screen.has_widget(&next).borrow_mut() {} + if self.screen_width == 0_f64 { + continue; + } + if self.screen_width < 960_f64 { + web_screen.set_visible(false); + mobile_screen.set_visible_and_redraw(cx, true); + mobile_screen.draw_all(cx, &mut Scope::empty()); + } else if self.screen_width > 960_f64 { + mobile_screen.set_visible(false); + web_screen.set_visible_and_redraw(cx, true); + web_screen.draw_all(cx, &mut Scope::empty()); + } else { + log!("ESLE_SCREEN_WIDTH ===> {}", self.screen_width); + } + } + } + fn handle_actions(&mut self, cx: &mut Cx, actions: &Actions) { + for action in actions { + if let WindowAction::WindowGeomChange(ce) = action.as_widget_action().cast() { + self.screen_width = ce.new_geom.inner_size.x * ce.new_geom.dpi_factor; + let mobile_screen = self.ui.view(id!(mobile)); + let web_screen = self.ui.view(id!(web)); + if self.screen_width < 960_f64 { + // log!("SCREEN_WIDTH ===> {}", self.screen_width); + web_screen.set_visible(false); + mobile_screen.set_visible_and_redraw(cx, true); + } else if self.screen_width > 960_f64 { + // log!("SCREEN_WIDTH ===> {}", self.screen_width); + self.ui + .radio_button_set(ids!( + navbar_menu.home_screen_tab, + // sidebar_menu.chat_tab, + // sidebar_menu.my_models_tab, + )) + .selected_to_visible( + cx, + &self.ui, + actions, + ids!( + application_pages.home_screen_frame, + // application_pages.chat_frame, + // application_pages.my_models_frame, + ), + ); + mobile_screen.set_visible(false); + web_screen.set_visible_and_redraw(cx, true); + } else { + log!("ESLE_SCREEN_WIDTH ===> {}", self.screen_width); + // web_screen.set_visible_and_redraw(cx, true); + } + } + } } } impl AppMain for App { fn handle_event(&mut self, cx: &mut Cx, event: &Event) { + if self.match_event_with_draw_2d(cx, event).is_ok() { + return; + } self.match_event(cx, event); self.ui.handle_event(cx, event, &mut Scope::empty()); } diff --git a/src/app_mobile.rs b/src/app_mobile.rs index e92781c..6f57e5a 100644 --- a/src/app_mobile.rs +++ b/src/app_mobile.rs @@ -8,64 +8,24 @@ live_design! { import crate::shared::styles::*; import crate::shared::widgets::*; import crate::home::home_screen::HomeScreen; + import crate::home::app_menu::AppMenu; - FONT_SIZE_H2 = 9.5 - TEXT_BIG = 12.0 - TEXT_MONO = { - font_size: 10.0, - font: {path: dep("crate://makepad-widgets/resources/LiberationMono-Regular.ttf")} - } - H2_TEXT_BOLD = { - font_size: (FONT_SIZE_H2), - font: {path: dep("crate://makepad-widgets/resources/IBMPlexSans-SemiBold.ttf")} - } - - // COLOR_DOWN_2 = #x00000022 - COLOR_DOWN_2 = #xFFB084 - COLOR_DOWN_6 = #x000000CC - COLOR_OVERLAY_BG = #x4685ff - COLOR_HEADER_BG = #x4685ff// xFFB084 x4685ff - SIDEBAR_BG_COLOR = #F8F8F8 - SSPACING_0 = 0.0 - SSPACING_1 = 4.0 - DROPDOWN_WIDTH = 130.0 - SSPACING_2 = (SSPACING_1 * 2) - SPACING_0 = {top: (SSPACING_0), right: (SSPACING_0), bottom: (SSPACING_0), left: (SSPACING_0)} - SPACING_2 = {top: (SSPACING_2), right: (SSPACING_2), bottom: (SSPACING_2), left: (SSPACING_2)} - - // ICON_CLOSE_PANEL = dep("crate://self/resources/icons/close_left_panel.svg") - // ICON_OPEN_PANEL = dep("crate://self/resources/icons/open_left_panel.svg") - // FillerY = {width: Fill} AppMobileUI = { - - // debug: A - // flow: Down, - // padding: 0.0 - // spacing: 0, - // align: { - // x: 0.0, - // y: 0.0 - // }, + width: Fill, + height: Fill, + // padding: {top: 50, bottom: 48 } show_bg: false, - // draw_bg: { - // color: (SIDEBAR_BG_COLOR), - // } - flow: Down, spacing:10, align: { x: 0.5, y: 0.5 }, - { - width: Fill, - height: Fill, - flow: Down, - // debug: A - {} + { + app_menu = {} } } } diff --git a/src/app_ui.rs b/src/app_ui.rs index d5fbd02..0e18862 100644 --- a/src/app_ui.rs +++ b/src/app_ui.rs @@ -4,31 +4,58 @@ live_design! { import makepad_widgets::base::*; import makepad_widgets::theme_desktop_dark::*; + import crate::shared::styles::*; + import crate::home::home_screen::HomeScreen; + + import crate::shared::widgets::NavbarMenuButton; + + ICON_DISCOVER = dep("crate://self/resources/icons/discover.svg") + ICON_CHAT = dep("crate://self/resources/icons/chat.svg") + ICON_MY_MODELS = dep("crate://self/resources/icons/my_models.svg") + AppUI = { - flow: Down, - spacing:10, - align: { - x: 0.5, - y: 0.5 - }, - button1 =