add offset / scrolling + clipboard support
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use app::App;
|
||||
use arboard::Clipboard;
|
||||
use cosmic_text::Family;
|
||||
use render::Renderer;
|
||||
use ui::prelude::*;
|
||||
@@ -22,6 +23,7 @@ pub struct Client {
|
||||
ui: Ui,
|
||||
info: WidgetId<Text>,
|
||||
focus: Option<WidgetId<TextEdit>>,
|
||||
clipboard: Clipboard,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Clone)]
|
||||
@@ -127,6 +129,15 @@ impl Client {
|
||||
.add_static(&mut ui);
|
||||
|
||||
let texts = Span::empty(Dir::DOWN).add_static(&mut ui);
|
||||
let msg_area = (
|
||||
Rect::new(Color::SKY),
|
||||
texts
|
||||
.offset(UiVec2::ZERO)
|
||||
.edit_on(Sense::Scroll, |w, data| {
|
||||
w.amt += UiVec2::abs(data.scroll_delta * 50.0);
|
||||
}),
|
||||
)
|
||||
.stack();
|
||||
let add_text = text_edit("add")
|
||||
.text_align(Align::Left)
|
||||
.size(30)
|
||||
@@ -151,7 +162,7 @@ impl Client {
|
||||
})
|
||||
.add(&mut ui);
|
||||
let text_edit_scroll = (
|
||||
(Rect::new(Color::SKY), texts).stack(),
|
||||
msg_area,
|
||||
(
|
||||
Rect::new(Color::WHITE.darker(0.9)),
|
||||
(
|
||||
@@ -217,6 +228,7 @@ impl Client {
|
||||
ui,
|
||||
info,
|
||||
focus: None,
|
||||
clipboard: Clipboard::new().unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,14 +261,20 @@ impl Client {
|
||||
if let Some(sel) = &self.focus
|
||||
&& event.state.is_pressed()
|
||||
{
|
||||
match self.ui.text(sel).apply_event(&event, &self.input.modifiers) {
|
||||
let mut text = self.ui.text(sel);
|
||||
match text.apply_event(&event, &self.input.modifiers) {
|
||||
TextInputResult::Unfocus => {
|
||||
self.focus = None;
|
||||
}
|
||||
TextInputResult::Submit => {
|
||||
self.run_event(&sel.clone(), Submit, ());
|
||||
}
|
||||
_ => (),
|
||||
TextInputResult::Paste => {
|
||||
if let Ok(t) = self.clipboard.get_text() {
|
||||
text.insert(&t);
|
||||
}
|
||||
}
|
||||
TextInputResult::Unused | TextInputResult::Used => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user