druid update

This commit is contained in:
Dongdong Zhou 2020-11-06 09:00:55 +00:00
parent 71cb0cd0af
commit 48eeebc266
11 changed files with 175 additions and 278 deletions

271
Cargo.lock generated
View File

@ -278,9 +278,6 @@ name = "cc"
version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c"
dependencies = [
"jobserver",
]
[[package]]
name = "cexpr"
@ -387,8 +384,8 @@ dependencies = [
"bitflags",
"block",
"cocoa-foundation",
"core-foundation",
"core-graphics",
"core-foundation 0.9.1",
"core-graphics 0.22.1",
"foreign-types",
"libc",
"objc",
@ -402,7 +399,7 @@ checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318"
dependencies = [
"bitflags",
"block",
"core-foundation",
"core-foundation 0.9.1",
"core-graphics-types",
"foreign-types",
"libc",
@ -442,22 +439,50 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2"
[[package]]
name = "core-foundation"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
dependencies = [
"core-foundation-sys 0.7.0",
"libc",
]
[[package]]
name = "core-foundation"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62"
dependencies = [
"core-foundation-sys",
"core-foundation-sys 0.8.1",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
[[package]]
name = "core-foundation-sys"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0af3b5e4601de3837c9332e29e0aae47a0d46ebfa246d12b82f564bac233393"
[[package]]
name = "core-graphics"
version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923"
dependencies = [
"bitflags",
"core-foundation 0.7.0",
"foreign-types",
"libc",
]
[[package]]
name = "core-graphics"
version = "0.22.1"
@ -465,7 +490,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc239bba52bab96649441699533a68de294a101533b0270b2d65aa402b29a7f9"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation 0.9.1",
"core-graphics-types",
"foreign-types",
"libc",
@ -478,7 +503,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation 0.9.1",
"foreign-types",
"libc",
]
[[package]]
name = "core-text"
version = "15.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "131b3fd1f8bd5db9f2b398fa4fdb6008c64afc04d447c306ac2c7e98fba2a61d"
dependencies = [
"core-foundation 0.7.0",
"core-graphics 0.19.2",
"foreign-types",
"libc",
]
@ -489,8 +526,8 @@ version = "19.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2c7f46e8b820fd5f4b28528104b28b0a91cbe9e9c5bde8017087fb44bc93a60"
dependencies = [
"core-foundation",
"core-graphics",
"core-foundation 0.9.1",
"core-graphics 0.22.1",
"foreign-types",
"libc",
]
@ -630,7 +667,6 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "druid"
version = "0.6.0"
source = "git+https://github.com/linebender/druid#705fc14b79c475845b1045dd38414a2134eef0b7"
dependencies = [
"console_log",
"druid-derive",
@ -652,7 +688,6 @@ dependencies = [
[[package]]
name = "druid-derive"
version = "0.3.1"
source = "git+https://github.com/linebender/druid#705fc14b79c475845b1045dd38414a2134eef0b7"
dependencies = [
"proc-macro2 1.0.23",
"quote 1.0.7",
@ -662,16 +697,17 @@ dependencies = [
[[package]]
name = "druid-shell"
version = "0.6.0"
source = "git+https://github.com/linebender/druid#705fc14b79c475845b1045dd38414a2134eef0b7"
dependencies = [
"anyhow",
"bitflags",
"block",
"cairo-rs",
"cfg-if 0.1.10",
"cocoa",
"core-graphics",
"core-graphics 0.22.1",
"foreign-types",
"gdk",
"gdk-pixbuf",
"gdk-sys",
"gio",
"glib",
@ -681,11 +717,12 @@ dependencies = [
"instant",
"js-sys",
"keyboard-types",
"kurbo",
"kurbo 0.7.0",
"lazy_static 1.4.0",
"log",
"objc",
"piet-common",
"scopeguard 1.1.0",
"time 0.2.22",
"wasm-bindgen",
"web-sys",
@ -802,18 +839,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "fontdb"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afa64e442fe4adbae6edd55ab3ebe905a858208db2aa12ab204e261890b69fd5"
dependencies = [
"log",
"memmap2",
"ttf-parser",
"uuid 0.8.1",
]
[[package]]
name = "foreign-types"
version = "0.3.2"
@ -831,9 +856,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "freetype"
version = "0.7.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bee38378a9e3db1cc693b4f88d166ae375338a0ff75cb8263e1c601d51f35dc6"
checksum = "b73222ab32d9ad65fe0e1c3258da8d614fd47cf19fce92b09eb520060c5c5ad5"
dependencies = [
"freetype-sys",
"libc",
@ -841,9 +866,9 @@ dependencies = [
[[package]]
name = "freetype-sys"
version = "0.13.1"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a37d4011c0cc628dfa766fcc195454f4b068d7afdc2adfd28861191d866e731a"
checksum = "d48ac0ce366dd47a115ec8e598d7c51b4a974fc52ded5e53a56b31f55f34f3ea"
dependencies = [
"cmake",
"libc",
@ -1083,17 +1108,6 @@ dependencies = [
"typenum",
]
[[package]]
name = "getrandom"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
dependencies = [
"cfg-if 0.1.10",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "gimli"
version = "0.22.0"
@ -1244,18 +1258,28 @@ dependencies = [
[[package]]
name = "harfbuzz-sys"
version = "0.5.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf8c27ca13930dc4ffe474880040fe9e0f03c2121600dc9c95423624cab3e467"
checksum = "845f3e65ec4e30b0b1b6e1c055900871f3776d3492cc76744e3fc5943a6129a9"
dependencies = [
"cc",
"core-graphics",
"core-text",
"core-graphics 0.19.2",
"core-text 15.0.0",
"foreign-types",
"freetype",
"pkg-config",
]
[[package]]
name = "harfbuzz_rs"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5bba81dd6b356135f0b31c42447e49d45116adc2e02910070947a322c423aa5"
dependencies = [
"bitflags",
"harfbuzz-sys",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
@ -1430,15 +1454,6 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "jobserver"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2"
dependencies = [
"libc",
]
[[package]]
name = "js-sys"
version = "0.3.45"
@ -1487,6 +1502,15 @@ dependencies = [
"arrayvec 0.5.1",
]
[[package]]
name = "kurbo"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ebfa590bba04e706e514c3285bb2c662610136fdbd58d7572d8afe0d22de1f0"
dependencies = [
"arrayvec 0.5.1",
]
[[package]]
name = "languageserver-types"
version = "0.54.0"
@ -1524,7 +1548,7 @@ dependencies = [
"toml",
"tree-sitter",
"tree-sitter-highlight",
"uuid 0.7.4",
"uuid",
"xi-core-lib",
"xi-rope",
"xi-rpc",
@ -1554,7 +1578,7 @@ dependencies = [
"toml",
"tree-sitter",
"tree-sitter-highlight",
"uuid 0.7.4",
"uuid",
"xi-core-lib",
"xi-rope",
"xi-rpc",
@ -2202,18 +2226,15 @@ checksum = "28b9b4df73455c861d7cbf8be42f01d3b373ed7f02e378d55fa84eafc6f638b1"
[[package]]
name = "piet"
version = "0.2.0-pre4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02ec0a227cffb4c468fb082e7e64491bbee586bd53f1ebcdb8de6bc3a3f4d119"
version = "0.2.0-pre6"
dependencies = [
"kurbo",
"kurbo 0.7.0",
"unic-bidi",
]
[[package]]
name = "piet-cairo"
version = "0.2.0-pre4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d7e3de2465c3f74e9e263940d46bd6ac8750fe54ae551852b2e7cc06e9cd20"
version = "0.2.0-pre6"
dependencies = [
"cairo-rs",
"piet",
@ -2223,14 +2244,12 @@ dependencies = [
[[package]]
name = "piet-common"
version = "0.2.0-pre4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0313f4b1aaa502096840cfc69f2486b2fb2cf54c55ea9d8683025d817a725365"
version = "0.2.0-pre6"
dependencies = [
"cairo-rs",
"cairo-sys-rs",
"cfg-if 0.1.10",
"core-graphics",
"cfg-if 1.0.0",
"core-graphics 0.22.1",
"piet",
"piet-cairo",
"piet-coregraphics",
@ -2242,24 +2261,19 @@ dependencies = [
[[package]]
name = "piet-coregraphics"
version = "0.2.0-pre4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16a4c56f36eab5364e4b15f519696e9c84c020ca687362a94d5d91d25ca30885"
version = "0.2.0-pre6"
dependencies = [
"core-foundation",
"core-foundation-sys",
"core-graphics",
"core-text",
"core-foundation 0.9.1",
"core-foundation-sys 0.8.1",
"core-graphics 0.22.1",
"core-text 19.1.0",
"foreign-types",
"piet",
"unic-bidi",
]
[[package]]
name = "piet-direct2d"
version = "0.2.0-pre4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba5ba077c472c0ea2ceafffbfae45b85e25e5111aef5c6bf7c2246c6db475f02"
version = "0.2.0-pre6"
dependencies = [
"associative-cache",
"dwrote",
@ -2271,9 +2285,7 @@ dependencies = [
[[package]]
name = "piet-web"
version = "0.2.0-pre4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f71e381210e85093f700e74b36836a49702945853721af2c0f0ff56b34beb89d"
version = "0.2.0-pre6"
dependencies = [
"js-sys",
"piet",
@ -2329,12 +2341,6 @@ dependencies = [
"xml-rs",
]
[[package]]
name = "ppv-lite86"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
[[package]]
name = "proc-macro-crate"
version = "0.1.5"
@ -2456,9 +2462,9 @@ checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
dependencies = [
"autocfg 0.1.7",
"libc",
"rand_chacha 0.1.1",
"rand_chacha",
"rand_core 0.4.2",
"rand_hc 0.1.0",
"rand_hc",
"rand_isaac",
"rand_jitter",
"rand_os",
@ -2467,19 +2473,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"libc",
"rand_chacha 0.2.2",
"rand_core 0.5.1",
"rand_hc 0.2.0",
]
[[package]]
name = "rand_chacha"
version = "0.1.1"
@ -2490,16 +2483,6 @@ dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core 0.5.1",
]
[[package]]
name = "rand_core"
version = "0.3.1"
@ -2515,15 +2498,6 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.1.0"
@ -2533,15 +2507,6 @@ dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rand_isaac"
version = "0.1.1"
@ -2663,9 +2628,9 @@ dependencies = [
[[package]]
name = "roxmltree"
version = "0.13.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17dfc6c39f846bfc7d2ec442ad12055d79608d501380789b965d22f9354451f2"
checksum = "d5001f134077069d87f77c8b9452b690df2445f7a43f1c7ca4a1af8dd505789d"
dependencies = [
"xmlparser",
]
@ -2691,16 +2656,6 @@ dependencies = [
"semver",
]
[[package]]
name = "rustybuzz"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "587e0c54f676a15df40c5fe5ea98da021000fe73762ace644d0ce4c5e3e80812"
dependencies = [
"bitflags",
"cc",
]
[[package]]
name = "ryu"
version = "1.0.5"
@ -3135,7 +3090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"wasi",
"winapi 0.3.9",
]
@ -3397,21 +3352,20 @@ dependencies = [
[[package]]
name = "usvg"
version = "0.11.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83ccafe45031f8b566d1603f2c03876c90111ffd53341b3423b545373572bfed"
checksum = "d681fd78e7926787a4e23c67beb18472525a10cb161d98e12f8a0a751f699ef8"
dependencies = [
"base64 0.12.3",
"data-url",
"flate2",
"fontdb",
"kurbo",
"harfbuzz_rs",
"kurbo 0.6.3",
"log",
"memmap2",
"pico-args",
"rctree",
"roxmltree",
"rustybuzz",
"simplecss",
"siphasher",
"svgtypes",
@ -3437,15 +3391,6 @@ dependencies = [
"rand 0.6.5",
]
[[package]]
name = "uuid"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
dependencies = [
"rand 0.7.3",
]
[[package]]
name = "vcpkg"
version = "0.2.10"
@ -3481,12 +3426,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"

View File

@ -24,7 +24,7 @@ xi-rpc = { path = "../xi-editor/rust/rpc/" }
fzyr = "0.1.2"
uuid = { version = "0.7.4", features = ["v4"] }
lsp-types = "0.61.0"
druid = { git = "https://github.com/linebender/druid", features = ["svg"] }
druid = { path = "../druid/druid", features = ["svg"] }
[build-dependencies]
cc = "*"

View File

@ -27,7 +27,7 @@ xi-rpc = { path = "../../xi-editor/rust/rpc/" }
fzyr = "0.1.2"
uuid = { version = "0.7.4", features = ["v4"] }
lsp-types = "0.82.0"
druid = { git = "https://github.com/linebender/druid", features = ["svg"] }
druid = { path = "../../druid/druid", features = ["svg"] }
[build-dependencies]
cc = "*"

View File

@ -196,7 +196,8 @@ fn paint_raw(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
);
}
let mut layout = TextLayout::new(item.item.label.as_str());
let mut layout =
TextLayout::<String>::from_text(item.item.label.as_str());
layout.set_font(LapceTheme::EDITOR_FONT);
layout.set_text_color(LapceTheme::EDITOR_FOREGROUND);
layout.rebuild_if_needed(&mut ctx.text(), env);

View File

@ -2131,7 +2131,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
);
let mut x = 10.0;
let mut text_layout = TextLayout::new(file_name.clone());
let mut text_layout = TextLayout::<String>::from_text(file_name.clone());
text_layout.set_font(
FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(13.0),
);
@ -2147,7 +2147,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
path.as_path()
};
let dir = dir.to_str().unwrap().to_string();
let mut text_layout = TextLayout::new(dir);
let mut text_layout = TextLayout::<String>::from_text(dir);
text_layout.set_font(
FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(13.0),
);
@ -2577,7 +2577,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
return;
}
let mut layout = TextLayout::new("W");
let mut layout = TextLayout::<String>::from_text("W");
layout.set_font(LapceTheme::EDITOR_FONT);
layout.rebuild_if_needed(&mut ctx.text(), env);
let width = layout.point_for_text_position(1).x;
@ -2621,7 +2621,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
.layout
.draw(ctx, Point::new(x, line_height * line as f64));
} else {
let mut layout = TextLayout::new(content.clone());
let mut layout = TextLayout::from_text(content.clone());
layout.set_font(LapceTheme::EDITOR_FONT);
layout.set_text_color(LapceTheme::EDITOR_FOREGROUND);
layout.rebuild_if_needed(&mut ctx.text(), env);
@ -2638,7 +2638,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
}
struct EditorTextLayout {
layout: TextLayout,
layout: TextLayout<String>,
text: String,
}
@ -2891,7 +2891,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
let buffer_id = buffer_id.unwrap();
let size = ctx.size();
let mut layout = TextLayout::new("W");
let mut layout = TextLayout::<String>::from_text("W");
layout.set_font(LapceTheme::EDITOR_FONT);
layout.rebuild_if_needed(&mut ctx.text(), env);
let width = layout.point_for_text_position(1).x;
@ -3039,7 +3039,9 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
== buffer.offset_of_position(&start)
{
let mut text_layout =
TextLayout::new(diagnositic.message.clone());
TextLayout::<String>::from_text(
diagnositic.message.clone(),
);
text_layout.set_font(
FontDescriptor::new(FontFamily::SYSTEM_UI)
.with_size(14.0),

View File

@ -243,7 +243,7 @@ fn paint(
);
}
let y = i as f64 * line_height;
let mut text_layout = TextLayout::new(
let mut text_layout = TextLayout::<String>::from_text(
item.path_buf.file_name().unwrap().to_str().unwrap(),
);
if item.path_buf.is_dir() {

View File

@ -1123,7 +1123,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
let line_height = env.get(LapceTheme::EDITOR_LINE_HEIGHT);
let text = palette.input.clone();
let cursor = palette.cursor;
let mut text_layout = TextLayout::new(text.as_ref());
let mut text_layout = TextLayout::<String>::from_text(&text);
text_layout.set_text_color(LapceTheme::EDITOR_FOREGROUND);
text_layout.rebuild_if_needed(ctx.text(), env);
let line = text_layout.cursor_line_for_text_position(cursor);

View File

@ -2,8 +2,9 @@
use druid::kurbo::{Point, Rect, Size, Vec2};
use druid::{
scroll_component::*, BoxConstraints, Data, Env, Event, EventCtx, LayoutCtx,
LifeCycle, LifeCycleCtx, PaintCtx, UpdateCtx, Widget, WidgetPod,
scroll_component::*, widget::ClipBox, widget::Scroll, BoxConstraints, Data, Env,
Event, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx, UpdateCtx,
Widget, WidgetPod,
};
use crate::command::{LapceUICommand, LAPCE_UI_COMMAND};
@ -28,9 +29,12 @@ enum ScrollDirection {
/// [`vertical`]: struct.Scroll.html#method.vertical
/// [`horizontal`]: struct.Scroll.html#method.horizontal
pub struct LapceScroll<T, W> {
child: WidgetPod<T, W>,
clip: ClipBox<T, W>,
//child: WidgetPod<T, W>,
scroll_component: ScrollComponent,
direction: ScrollDirection,
//direction: ScrollDirection,
//content_size: Size,
//scroll_offset: Vec2,
}
impl<T: Data, W: Widget<T>> LapceScroll<T, W> {
@ -41,59 +45,62 @@ impl<T: Data, W: Widget<T>> LapceScroll<T, W> {
/// [horizontal](#method.horizontal) methods to limit scrolling to a specific axis.
pub fn new(child: W) -> LapceScroll<T, W> {
LapceScroll {
child: WidgetPod::new(child),
clip: ClipBox::new(child),
scroll_component: ScrollComponent::new(),
direction: ScrollDirection::Bidirectional,
//direction: ScrollDirection::Bidirectional,
//content_size: Size::ZERO,
//scroll_offset: Vec2::ZERO,
}
}
/// Restrict scrolling to the vertical axis while locking child width.
pub fn vertical(mut self) -> Self {
self.direction = ScrollDirection::Vertical;
self.clip.set_constrain_vertical(false);
self.clip.set_constrain_horizontal(true);
self
}
/// Restrict scrolling to the horizontal axis while locking child height.
pub fn horizontal(mut self) -> Self {
self.direction = ScrollDirection::Horizontal;
self.clip.set_constrain_vertical(true);
self.clip.set_constrain_horizontal(false);
self
}
/// Returns a reference to the child widget.
pub fn child(&self) -> &W {
self.child.widget()
self.clip.child()
}
/// Returns a mutable reference to the child widget.
pub fn child_mut(&mut self) -> &mut W {
self.child.widget_mut()
self.clip.child_mut()
}
/// Returns the size of the child widget.
pub fn child_size(&self) -> Size {
self.scroll_component.content_size
self.clip.content_size()
}
/// Returns the current scroll offset.
pub fn offset(&self) -> Vec2 {
self.scroll_component.scroll_offset
self.clip.viewport_origin().to_vec2()
}
pub fn scroll(&mut self, x: f64, y: f64) {
let mut offset = self.offset();
offset.x = offset.x + x;
offset.y = offset.y + y;
if offset.y < 0.0 {
offset.y = 0.0;
}
self.scroll_component.scroll_offset = offset;
self.child.set_viewport_offset(offset);
self.clip.pan_by(Vec2::new(x, y));
//let mut offset = self.offset();
//offset.x = offset.x + x;
//offset.y = offset.y + y;
//if offset.y < 0.0 {
// offset.y = 0.0;
//}
//self.scroll_offset = offset;
//self.child.set_viewport_offset(offset);
}
pub fn scroll_to(&mut self, x: f64, y: f64) {
let offset = Vec2::new(x, y);
self.scroll_component.scroll_offset = offset;
self.child.set_viewport_offset(offset);
self.clip.pan_to(Point::new(x, y));
}
pub fn ensure_visible(
@ -103,12 +110,11 @@ pub fn ensure_visible(
margin: &(f64, f64),
) -> bool {
let mut new_offset = self.offset();
let content_size = self.scroll_component.content_size;
let content_size = self.child_size();
let (x_margin, y_margin) = margin;
new_offset.x = if new_offset.x < rect.x1 + x_margin - scroll_size.width
{
new_offset.x = if new_offset.x < rect.x1 + x_margin - scroll_size.width {
(rect.x1 + x_margin - scroll_size.width)
.min(content_size.width - scroll_size.width)
} else if new_offset.x > rect.x0 - x_margin {
@ -117,8 +123,7 @@ pub fn ensure_visible(
new_offset.x
};
new_offset.y = if new_offset.y < rect.y1 + y_margin - scroll_size.height
{
new_offset.y = if new_offset.y < rect.y1 + y_margin - scroll_size.height {
(rect.y1 + y_margin - scroll_size.height)
.min(content_size.height - scroll_size.height)
} else if new_offset.y > rect.y0 - y_margin {
@ -131,23 +136,16 @@ pub fn ensure_visible(
return false;
}
self.scroll_component.scroll_offset = new_offset;
self.child.set_viewport_offset(new_offset);
self.clip.pan_to(Point::new(new_offset.x, new_offset.y));
true
}
}
impl<T: Data, W: Widget<T>> Widget<T> for LapceScroll<T, W> {
fn event(
&mut self,
ctx: &mut EventCtx,
event: &Event,
data: &mut T,
env: &Env,
) {
fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) {
match event {
Event::Internal(_) => {
self.child.event(ctx, event, data, env);
self.clip.event(ctx, event, data, env);
}
Event::Command(cmd) => match cmd {
_ if cmd.is(LAPCE_UI_COMMAND) => {
@ -161,11 +159,7 @@ fn event(
println!("scroll request paint");
ctx.request_paint();
}
LapceUICommand::EnsureVisible((
rect,
margin,
position,
)) => {
LapceUICommand::EnsureVisible((rect, margin, position)) => {
if self.ensure_visible(ctx.size(), rect, margin) {
ctx.request_paint();
}
@ -180,10 +174,7 @@ fn event(
ctx.request_paint();
return;
}
_ => println!(
"scroll unprocessed ui command {:?}",
command
),
_ => println!("scroll unprocessed ui command {:?}", command),
}
}
_ => (),
@ -192,23 +183,17 @@ fn event(
};
// self.scroll_component.event(ctx, event, env);
if !ctx.is_handled() {
let viewport = Rect::from_origin_size(Point::ORIGIN, ctx.size());
let force_event = self.child.is_hot() || self.child.is_active();
let child_event = event.transform_scroll(
self.scroll_component.scroll_offset,
viewport,
force_event,
);
if let Some(child_event) = child_event {
self.child.event(ctx, &child_event, data, env);
};
self.clip.event(ctx, event, data, env);
}
self.scroll_component.handle_scroll(ctx, event, env);
// self.scroll_component.handle_scroll(
// self.child.viewport_offset(),
// ctx,
// event,
// env,
// );
// In order to ensure that invalidation regions are correctly propagated up the tree,
// we need to set the viewport offset on our child whenever we change our scroll offset.
self.child.set_viewport_offset(self.offset());
}
fn lifecycle(
@ -218,18 +203,12 @@ fn lifecycle(
data: &T,
env: &Env,
) {
self.clip.lifecycle(ctx, event, data, env);
self.scroll_component.lifecycle(ctx, event, env);
self.child.lifecycle(ctx, event, data, env);
}
fn update(
&mut self,
ctx: &mut UpdateCtx,
_old_data: &T,
data: &T,
env: &Env,
) {
self.child.update(ctx, data, env);
fn update(&mut self, ctx: &mut UpdateCtx, old_data: &T, data: &T, env: &Env) {
self.clip.update(ctx, old_data, data, env);
}
fn layout(
@ -241,30 +220,16 @@ fn layout(
) -> Size {
bc.debug_check("Scroll");
let max_bc = match self.direction {
ScrollDirection::Bidirectional => Size::new(INFINITY, INFINITY),
ScrollDirection::Vertical => Size::new(bc.max().width, INFINITY),
ScrollDirection::Horizontal => Size::new(INFINITY, bc.max().height),
};
let child_bc = BoxConstraints::new(bc.max(), max_bc);
let child_size = self.child.layout(ctx, &child_bc, data, env);
self.scroll_component.content_size = child_size;
self.child
.set_layout_rect(ctx, data, env, child_size.to_rect());
let old_size = self.clip.viewport().rect.size();
let child_size = self.clip.layout(ctx, &bc, data, env);
let self_size = bc.constrain(child_size);
let _ = self.scroll_component.scroll(Vec2::new(0.0, 0.0), self_size);
self.child.set_viewport_offset(self.offset());
self_size
}
fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
self.clip.paint(ctx, data, env);
self.scroll_component
.paint_content(ctx, env, |visible, ctx| {
ctx.with_child_ctx(visible, |ctx| {
self.child.paint_raw(ctx, data, env)
});
});
.draw_bars(ctx, &self.clip.viewport(), env);
}
}

View File

@ -85,7 +85,8 @@ fn paint(
}
}
let mut text_layout = TextLayout::new(format!("{} {}", errors, warnings));
let mut text_layout =
TextLayout::<String>::from_text(format!("{} {}", errors, warnings));
text_layout
.set_font(FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(13.0));
text_layout.set_text_color(LapceTheme::EDITOR_FOREGROUND);

View File

@ -408,7 +408,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceUIState, env: &Env) {
format!("{} [{}]", dir, host)
}
};
let mut text_layout = TextLayout::new(dir);
let mut text_layout = TextLayout::<String>::from_text(dir);
text_layout.set_font(
FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(13.0),
);

View File

@ -41,17 +41,6 @@ pub fn new() -> Delegate {
}
impl AppDelegate<LapceUIState> for Delegate {
fn command(
&mut self,
ctx: &mut DelegateCtx,
target: Target,
cmd: &Command,
data: &mut LapceUIState,
env: &Env,
) -> bool {
true
}
fn window_added(
&mut self,
id: WindowId,