Allow horizontal scroll to fit cursor, related to #59
This commit is contained in:
parent
102a3f1d2d
commit
68dd4c3758
4 changed files with 36 additions and 33 deletions
40
Cargo.lock
generated
40
Cargo.lock
generated
|
|
@ -1100,7 +1100,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config"
|
name = "cosmic-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomicwrites",
|
"atomicwrites",
|
||||||
"cosmic-config-derive",
|
"cosmic-config-derive",
|
||||||
|
|
@ -1119,7 +1119,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config-derive"
|
name = "cosmic-config-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
|
@ -1158,7 +1158,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-files"
|
name = "cosmic-files"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/cosmic-files.git#ac2e129e4dd436e9d38a0a4da6ce8f1d89c5fd3f"
|
source = "git+https://github.com/pop-os/cosmic-files.git#7a3f9d56666a203b02f217cde6f464f0db422e93"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
|
@ -1202,7 +1202,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-text"
|
name = "cosmic-text"
|
||||||
version = "0.11.2"
|
version = "0.11.2"
|
||||||
source = "git+https://github.com/pop-os/cosmic-text.git#2f5f2c63dabc0173adaa95d619a777454a3c39af"
|
source = "git+https://github.com/pop-os/cosmic-text.git#b0a70c70ffba883ac6ff022b535db195712f552f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"cosmic_undo_2",
|
"cosmic_undo_2",
|
||||||
|
|
@ -1227,7 +1227,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-theme"
|
name = "cosmic-theme"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"almost",
|
"almost",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
|
|
@ -2612,7 +2612,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced"
|
name = "iced"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dnd",
|
"dnd",
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
|
|
@ -2630,7 +2630,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_accessibility"
|
name = "iced_accessibility"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"accesskit_winit",
|
"accesskit_winit",
|
||||||
|
|
@ -2639,7 +2639,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"dnd",
|
"dnd",
|
||||||
|
|
@ -2659,7 +2659,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_futures"
|
name = "iced_futures"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2672,7 +2672,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_graphics"
|
name = "iced_graphics"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2696,7 +2696,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_renderer"
|
name = "iced_renderer"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_tiny_skia",
|
"iced_tiny_skia",
|
||||||
|
|
@ -2708,7 +2708,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_runtime"
|
name = "iced_runtime"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dnd",
|
"dnd",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2720,7 +2720,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_style"
|
name = "iced_style"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
@ -2730,7 +2730,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_tiny_skia"
|
name = "iced_tiny_skia"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cosmic-text",
|
"cosmic-text",
|
||||||
|
|
@ -2747,7 +2747,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_wgpu"
|
name = "iced_wgpu"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2773,7 +2773,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_widget"
|
name = "iced_widget"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dnd",
|
"dnd",
|
||||||
"iced_renderer",
|
"iced_renderer",
|
||||||
|
|
@ -2789,7 +2789,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_winit"
|
name = "iced_winit"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dnd",
|
"dnd",
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
|
|
@ -3148,7 +3148,7 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcosmic"
|
name = "libcosmic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#b937a30050a3012dc774478e344130df16db800b"
|
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"apply",
|
"apply",
|
||||||
"ashpd",
|
"ashpd",
|
||||||
|
|
@ -5308,9 +5308,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.37.0"
|
version = "1.38.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
|
checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
use cosmic::widget::menu::key_bind::KeyBind;
|
use cosmic::widget::menu::key_bind::KeyBind;
|
||||||
use cosmic::widget::menu::{items as menu_items, root as menu_root, Item as MenuItem};
|
use cosmic::widget::menu::{items as menu_items, root as menu_root, Item as MenuItem};
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::{widget::column, widget::horizontal_rule, Alignment, Background, Length},
|
iced::{widget::column, widget::horizontal_rule, Background, Length},
|
||||||
iced_core::Border,
|
iced_core::Border,
|
||||||
theme,
|
theme,
|
||||||
widget::{
|
widget::{
|
||||||
|
|
|
||||||
|
|
@ -569,7 +569,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw editor
|
// Draw editor
|
||||||
|
let scroll_x = editor.with_buffer(|buffer| buffer.scroll().horizontal as i32);
|
||||||
editor.draw(font_system.raw(), &mut swash_cache, |x, y, w, h, color| {
|
editor.draw(font_system.raw(), &mut swash_cache, |x, y, w, h, color| {
|
||||||
|
if x < scroll_x {
|
||||||
|
//TODO: modify width?
|
||||||
|
return;
|
||||||
|
}
|
||||||
draw_rect(
|
draw_rect(
|
||||||
pixels,
|
pixels,
|
||||||
Canvas {
|
Canvas {
|
||||||
|
|
@ -581,7 +586,7 @@ where
|
||||||
h: h as i32,
|
h: h as i32,
|
||||||
},
|
},
|
||||||
Offset {
|
Offset {
|
||||||
x: editor_offset_x + x,
|
x: editor_offset_x + x - scroll_x,
|
||||||
y,
|
y,
|
||||||
},
|
},
|
||||||
color,
|
color,
|
||||||
|
|
@ -921,12 +926,11 @@ where
|
||||||
&& x_logical < (scrollbar_rect.x + scrollbar_rect.width)
|
&& x_logical < (scrollbar_rect.x + scrollbar_rect.width)
|
||||||
{
|
{
|
||||||
editor.with_buffer_mut(|buffer| {
|
editor.with_buffer_mut(|buffer| {
|
||||||
|
let mut scroll = buffer.scroll();
|
||||||
let scroll_line =
|
let scroll_line =
|
||||||
((y / buffer.size().1) * buffer.lines.len() as f32) as i32;
|
((y / buffer.size().1) * buffer.lines.len() as f32) as i32;
|
||||||
buffer.set_scroll(Scroll::new(
|
scroll.line = scroll_line.try_into().unwrap_or_default();
|
||||||
scroll_line.try_into().unwrap_or_default(),
|
buffer.set_scroll(scroll);
|
||||||
0,
|
|
||||||
));
|
|
||||||
state.dragging = Some(Dragging::Scrollbar {
|
state.dragging = Some(Dragging::Scrollbar {
|
||||||
start_y: y,
|
start_y: y,
|
||||||
start_scroll: buffer.scroll(),
|
start_scroll: buffer.scroll(),
|
||||||
|
|
@ -973,15 +977,14 @@ where
|
||||||
start_scroll,
|
start_scroll,
|
||||||
} => {
|
} => {
|
||||||
editor.with_buffer_mut(|buffer| {
|
editor.with_buffer_mut(|buffer| {
|
||||||
|
let mut scroll = buffer.scroll();
|
||||||
let scroll_offset = (((y - start_y) / buffer.size().1)
|
let scroll_offset = (((y - start_y) / buffer.size().1)
|
||||||
* buffer.lines.len() as f32)
|
* buffer.lines.len() as f32)
|
||||||
as i32;
|
as i32;
|
||||||
buffer.set_scroll(Scroll::new(
|
scroll.line = (start_scroll.line as i32 + scroll_offset)
|
||||||
(start_scroll.line as i32 + scroll_offset)
|
.try_into()
|
||||||
.try_into()
|
.unwrap_or_default();
|
||||||
.unwrap_or_default(),
|
buffer.set_scroll(scroll);
|
||||||
0,
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue