TEXT SELECTION
This commit is contained in:
@@ -160,6 +160,11 @@ impl Client {
|
||||
}
|
||||
self.run_event(sel, Edited, ());
|
||||
}
|
||||
TextInputResult::Copy(text) => {
|
||||
if let Err(err) = self.clipboard.set_text(text) {
|
||||
eprintln!("failed to copy text to clipboard: {err}")
|
||||
}
|
||||
}
|
||||
TextInputResult::Used => {
|
||||
self.run_event(sel, Edited, ());
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn login_screen(client: &mut Client) -> WidgetId {
|
||||
.clone()
|
||||
.pad(10)
|
||||
.background(rect(Color::BLACK.brighter(0.1)).radius(15))
|
||||
.on(CursorSense::click(), focus_other(field))
|
||||
.attr::<Selector>(field)
|
||||
};
|
||||
|
||||
// I LAV NOT HAVING ERGONOMIC CLONES
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn msg_widget(msg: Msg) -> impl WidgetLike<FnTag> {
|
||||
.editable()
|
||||
.size(SIZE)
|
||||
.wrap(true)
|
||||
.id_on(CursorSense::click(), |i, c, d| focus(i.clone(), c, d));
|
||||
.attr::<Selectable>(());
|
||||
let header = text(msg.user).size(SIZE);
|
||||
(
|
||||
image(include_bytes!("../assets/sungals.png"))
|
||||
@@ -70,7 +70,7 @@ pub fn msg_panel(client: &mut Client, network: NetSender) -> impl WidgetFn<Sized
|
||||
client.ui[&msg_area].children.push(msg.any());
|
||||
})
|
||||
.pad(15)
|
||||
.on(CursorSense::click(), focus_other(send_text))
|
||||
.attr::<Selector>(send_text)
|
||||
.scroll()
|
||||
.masked()
|
||||
.background(rect(Color::BLACK.brighter(0.05)).radius(15))
|
||||
|
||||
@@ -9,8 +9,48 @@ pub fn error(ui: &mut Ui, msg: &str) -> WidgetId {
|
||||
.any()
|
||||
}
|
||||
|
||||
pub fn focus(id: WidgetId<TextEdit>, client: &mut Client, data: CursorData) {
|
||||
client.ui.text(&id).select(data.cursor, data.size);
|
||||
pub struct Selector;
|
||||
|
||||
impl<W: 'static> WidgetAttr<W> for Selector {
|
||||
type Input = WidgetId<TextEdit>;
|
||||
|
||||
fn run(ui: &mut Ui, container: &WidgetId<W>, id: Self::Input) {
|
||||
let container = container.clone();
|
||||
ui.register_event(
|
||||
&container.clone(),
|
||||
CursorSense::click_or_drag(),
|
||||
move |client: &mut Client, mut data| {
|
||||
let id_pos = client.ui.window_region(&id).unwrap().top_left;
|
||||
let container_pos = client.ui.window_region(&container).unwrap().top_left;
|
||||
data.cursor += container_pos - id_pos;
|
||||
select(id.clone(), client, data);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Selectable;
|
||||
|
||||
impl WidgetAttr<TextEdit> for Selectable {
|
||||
type Input = ();
|
||||
|
||||
fn run(ui: &mut Ui, id: &WidgetId<TextEdit>, _: Self::Input) {
|
||||
let id = id.clone();
|
||||
ui.register_event(
|
||||
&id.clone(),
|
||||
CursorSense::click_or_drag(),
|
||||
move |client: &mut Client, data| {
|
||||
select(id.clone(), client, data);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn select(id: WidgetId<TextEdit>, client: &mut Client, data: CursorData) {
|
||||
client
|
||||
.ui
|
||||
.text(&id)
|
||||
.select(data.cursor, data.size, data.sense.is_dragging());
|
||||
if let Some(region) = client.ui.window_region(&id) {
|
||||
client.handle.window.set_ime_allowed(true);
|
||||
client.handle.window.set_ime_cursor_area(
|
||||
@@ -21,13 +61,6 @@ pub fn focus(id: WidgetId<TextEdit>, client: &mut Client, data: CursorData) {
|
||||
client.focus = Some(id);
|
||||
}
|
||||
|
||||
pub fn focus_other(id: WidgetId<TextEdit>) -> impl Fn(&mut Client, CursorData) {
|
||||
move |client: &mut Client, data: CursorData| {
|
||||
focus(id.clone(), client, data);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hint(msg: impl Into<String>) -> TextBuilder {
|
||||
text(msg).size(20).color(Color::GRAY)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user