Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/inspector/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn profile_view(profile: &Rc<Profile>) -> impl IntoView {
})
})
.collect();
frames.sort_by(|a, b| b.sum.cmp(&a.sum));
frames.sort_by_key(|frame| std::cmp::Reverse(frame.sum));
let frames: Rc<[_]> = frames.into();

let selected_frame = RwSignal::new(None);
Expand Down
40 changes: 18 additions & 22 deletions src/inspector/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,30 +729,26 @@ impl View for InspectorImageView {
return EventPropagation::Continue;
}
match key {
Key::Named(NamedKey::ArrowUp) => {
if !self.contain_ids.is_empty() {
self.contain_index = if self.contain_index == 0 {
self.contain_ids.len() - 1
} else {
self.contain_index - 1
};
if let Some(id) = self.contain_ids.get(self.contain_index).copied() {
cx.window_state.request_paint = true;
self.id.owning_id().request_paint();
update_select_view_id(id, &self.capture_view, false, self.datas);
return EventPropagation::Stop;
}
Key::Named(NamedKey::ArrowUp) if !self.contain_ids.is_empty() => {
self.contain_index = if self.contain_index == 0 {
self.contain_ids.len() - 1
} else {
self.contain_index - 1
};
if let Some(id) = self.contain_ids.get(self.contain_index).copied() {
cx.window_state.request_paint = true;
self.id.owning_id().request_paint();
update_select_view_id(id, &self.capture_view, false, self.datas);
return EventPropagation::Stop;
}
}
Key::Named(NamedKey::ArrowDown) => {
if !self.contain_ids.is_empty() {
self.contain_index = (self.contain_index + 1) % self.contain_ids.len();
if let Some(id) = self.contain_ids.get(self.contain_index).copied() {
cx.window_state.request_paint = true;
self.id.owning_id().request_paint();
update_select_view_id(id, &self.capture_view, false, self.datas);
return EventPropagation::Stop;
}
Key::Named(NamedKey::ArrowDown) if !self.contain_ids.is_empty() => {
self.contain_index = (self.contain_index + 1) % self.contain_ids.len();
if let Some(id) = self.contain_ids.get(self.contain_index).copied() {
cx.window_state.request_paint = true;
self.id.owning_id().request_paint();
update_select_view_id(id, &self.capture_view, false, self.datas);
return EventPropagation::Stop;
}
}
_ => {}
Expand Down
37 changes: 18 additions & 19 deletions src/views/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,29 +405,28 @@ impl View for Label {
cx.window_state.request_paint(self.id);
return EventPropagation::Continue;
}
Event::Pointer(PointerEvent::Down(PointerButtonEvent { state, pointer, .. })) => {
Event::Pointer(PointerEvent::Down(PointerButtonEvent { state, pointer, .. }))
if self.label_props.text_selectable()
&& state
.buttons
.contains(ui_events::pointer::PointerButton::Primary)
{
self.selection_state = self
.get_hit_point(state.logical_point())
.map(|cursor| SelectionState::Ready {
origin: state.logical_point(),
selection: self
.layout_data
.borrow()
.get_effective_text_layout()
.map(|layout| layout.collapsed_selection(cursor))
.expect("label text layout should be available on pointer down"),
})
.unwrap_or(SelectionState::None);
if let Some(pointer_id) = pointer.pointer_id {
cx.window_state.set_pointer_capture(pointer_id, self.id);
}
cx.window_state.request_paint(self.id);
.contains(ui_events::pointer::PointerButton::Primary) =>
{
self.selection_state = self
.get_hit_point(state.logical_point())
.map(|cursor| SelectionState::Ready {
origin: state.logical_point(),
selection: self
.layout_data
.borrow()
.get_effective_text_layout()
.map(|layout| layout.collapsed_selection(cursor))
.expect("label text layout should be available on pointer down"),
})
.unwrap_or(SelectionState::None);
if let Some(pointer_id) = pointer.pointer_id {
cx.window_state.set_pointer_capture(pointer_id, self.id);
}
cx.window_state.request_paint(self.id);
}
Event::Pointer(PointerEvent::Move(pu)) => {
if !self.label_props.text_selectable() {
Expand Down
82 changes: 37 additions & 45 deletions src/views/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,54 +1355,46 @@ impl View for TextInput {
Event::Ime(ImeEvent::DeleteSurrounding {
before_bytes,
after_bytes,
}) => {
if self.is_focused {
let selection = self.selection_byte_range();
if let Some(selection) = selection.as_ref() {
self.selection = None;
self.cursor_glyph_idx = selection.start;
}
self.buffer.update(|buf| {
if let Some(selection) = selection.clone() {
buf.replace_range(selection, "");
}
// If the index falls inside a character, delete that character too.
// This only happens on desynchronized input:
// 1. IME sends a request with index on code point boundary
// 2. Another source shifts text around
// 3. Request arrives.
// This situation is expected to be rare, so not trying to be too clever at handling it.
let before_start = buf[..self.cursor_glyph_idx]
.char_indices()
.rev()
.find(|(index, _)| self.cursor_glyph_idx - index >= *before_bytes)
.map(|(i, _)| i)
.unwrap_or(0);
let after_end = buf[self.cursor_glyph_idx..]
.char_indices()
.map(|(index, _)| index)
.find(|index| index >= after_bytes)
.map(|i| i + self.cursor_glyph_idx)
.unwrap_or(buf.len());
buf.replace_range(before_start..after_end, "");
self.cursor_glyph_idx = before_start;
});
true
} else {
false
}) if self.is_focused => {
let selection = self.selection_byte_range();
if let Some(selection) = selection.as_ref() {
self.selection = None;
self.cursor_glyph_idx = selection.start;
}
self.buffer.update(|buf| {
if let Some(selection) = selection.clone() {
buf.replace_range(selection, "");
}
// If the index falls inside a character, delete that character too.
// This only happens on desynchronized input:
// 1. IME sends a request with index on code point boundary
// 2. Another source shifts text around
// 3. Request arrives.
// This situation is expected to be rare, so not trying to be too clever at handling it.
let before_start = buf[..self.cursor_glyph_idx]
.char_indices()
.rev()
.find(|(index, _)| self.cursor_glyph_idx - index >= *before_bytes)
.map(|(i, _)| i)
.unwrap_or(0);
let after_end = buf[self.cursor_glyph_idx..]
.char_indices()
.map(|(index, _)| index)
.find(|index| index >= after_bytes)
.map(|i| i + self.cursor_glyph_idx)
.unwrap_or(buf.len());
buf.replace_range(before_start..after_end, "");
self.cursor_glyph_idx = before_start;
});
true
}
Event::Ime(ImeEvent::Commit(text)) => {
if self.is_focused {
self.buffer
.update(|buf| buf.insert_str(self.cursor_glyph_idx, text));
self.cursor_glyph_idx += text.len();
self.preedit = None;
Event::Ime(ImeEvent::Commit(text)) if self.is_focused => {
self.buffer
.update(|buf| buf.insert_str(self.cursor_glyph_idx, text));
self.cursor_glyph_idx += text.len();
self.preedit = None;

true
} else {
false
}
true
}

Event::Focus(focus) => {
Expand Down
8 changes: 3 additions & 5 deletions src/views/toggle_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,9 @@ impl Handle {
self.update_bounds(toggle_size, radius);
cx.window_state.request_paint(self.parent_id);
}
Event::Interaction(InteractionEvent::Click) => {
if !self.dragged {
*state = !*state;
self.snap(*state, toggle_size, radius, inset);
}
Event::Interaction(InteractionEvent::Click) if !self.dragged => {
*state = !*state;
self.snap(*state, toggle_size, radius, inset);
}

_ => {}
Expand Down
14 changes: 6 additions & 8 deletions src/views/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ impl View for Tooltip {
impl Tooltip {
fn handle_event(&mut self, cx: &mut EventCx) -> EventPropagation {
match &cx.event {
Event::Pointer(PointerEvent::Move(pu)) => {
if self.overlay.borrow().is_none() {
let id = self.id();
let token = exec_after(self.style.delay(), move |token| {
id.update_state(token);
});
self.hover_point = Some((pu.current.logical_point(), token));
}
Event::Pointer(PointerEvent::Move(pu)) if self.overlay.borrow().is_none() => {
let id = self.id();
let token = exec_after(self.style.delay(), move |token| {
id.update_state(token);
});
self.hover_point = Some((pu.current.logical_point(), token));
}
Event::Pointer(_) | Event::Key(_) => {
self.hover_point = None;
Expand Down
Loading