Skip to content

Commit

Permalink
Implement text selection across multiple labels
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 24, 2024
1 parent b132f1a commit bbd9335
Show file tree
Hide file tree
Showing 10 changed files with 600 additions and 95 deletions.
13 changes: 12 additions & 1 deletion crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ impl Context {
/// ```
pub fn begin_frame(&self, new_input: RawInput) {
crate::profile_function!();

crate::text_selection::LabelSelectionState::begin_frame(self);
self.write(|ctx| ctx.begin_frame_mut(new_input));
}
}
Expand Down Expand Up @@ -1616,6 +1616,8 @@ impl Context {
crate::gui_zoom::zoom_with_keyboard(self);
}

crate::text_selection::LabelSelectionState::end_frame(self);

let debug_texts = self.write(|ctx| std::mem::take(&mut ctx.debug_texts));
if !debug_texts.is_empty() {
// Show debug-text next to the cursor.
Expand Down Expand Up @@ -2352,6 +2354,15 @@ impl Context {
let font_image_size = self.fonts(|f| f.font_image_size());
crate::introspection::font_texture_ui(ui, font_image_size);
});

CollapsingHeader::new("Label text selection state")
.default_open(false)
.show(ui, |ui| {
ui.label(format!(
"{:#?}",
crate::text_selection::LabelSelectionState::load(ui.ctx())
));
});
}

/// Show stats about the allocated textures.
Expand Down
1 change: 1 addition & 0 deletions crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ impl PointerState {
}

/// Was any pointer button pressed (`!down -> down`) this frame?
///
/// This can sometimes return `true` even if `any_down() == false`
/// because a press can be shorted than one frame.
pub fn any_pressed(&self) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions crates/egui/src/text_selection/cursor_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ impl CCursorRange {
}

#[inline]
pub fn two(min: CCursor, max: CCursor) -> Self {
pub fn two(min: impl Into<CCursor>, max: impl Into<CCursor>) -> Self {
Self {
primary: max,
secondary: min,
primary: max.into(),
secondary: min.into(),
}
}

Expand Down
Loading

0 comments on commit bbd9335

Please sign in to comment.