TEXT SELECTION
This commit is contained in:
2
iris
2
iris
Submodule iris updated: 246caffb34...1cec56e847
@@ -160,6 +160,11 @@ impl Client {
|
|||||||
}
|
}
|
||||||
self.run_event(sel, Edited, ());
|
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 => {
|
TextInputResult::Used => {
|
||||||
self.run_event(sel, Edited, ());
|
self.run_event(sel, Edited, ());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub fn login_screen(client: &mut Client) -> WidgetId {
|
|||||||
.clone()
|
.clone()
|
||||||
.pad(10)
|
.pad(10)
|
||||||
.background(rect(Color::BLACK.brighter(0.1)).radius(15))
|
.background(rect(Color::BLACK.brighter(0.1)).radius(15))
|
||||||
.on(CursorSense::click(), focus_other(field))
|
.attr::<Selector>(field)
|
||||||
};
|
};
|
||||||
|
|
||||||
// I LAV NOT HAVING ERGONOMIC CLONES
|
// I LAV NOT HAVING ERGONOMIC CLONES
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pub fn msg_widget(msg: Msg) -> impl WidgetLike<FnTag> {
|
|||||||
.editable()
|
.editable()
|
||||||
.size(SIZE)
|
.size(SIZE)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
.id_on(CursorSense::click(), |i, c, d| focus(i.clone(), c, d));
|
.attr::<Selectable>(());
|
||||||
let header = text(msg.user).size(SIZE);
|
let header = text(msg.user).size(SIZE);
|
||||||
(
|
(
|
||||||
image(include_bytes!("../assets/sungals.png"))
|
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());
|
client.ui[&msg_area].children.push(msg.any());
|
||||||
})
|
})
|
||||||
.pad(15)
|
.pad(15)
|
||||||
.on(CursorSense::click(), focus_other(send_text))
|
.attr::<Selector>(send_text)
|
||||||
.scroll()
|
.scroll()
|
||||||
.masked()
|
.masked()
|
||||||
.background(rect(Color::BLACK.brighter(0.05)).radius(15))
|
.background(rect(Color::BLACK.brighter(0.05)).radius(15))
|
||||||
|
|||||||
@@ -9,8 +9,48 @@ pub fn error(ui: &mut Ui, msg: &str) -> WidgetId {
|
|||||||
.any()
|
.any()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focus(id: WidgetId<TextEdit>, client: &mut Client, data: CursorData) {
|
pub struct Selector;
|
||||||
client.ui.text(&id).select(data.cursor, data.size);
|
|
||||||
|
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) {
|
if let Some(region) = client.ui.window_region(&id) {
|
||||||
client.handle.window.set_ime_allowed(true);
|
client.handle.window.set_ime_allowed(true);
|
||||||
client.handle.window.set_ime_cursor_area(
|
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);
|
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 {
|
pub fn hint(msg: impl Into<String>) -> TextBuilder {
|
||||||
text(msg).size(20).color(Color::GRAY)
|
text(msg).size(20).color(Color::GRAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user