Skip to content

Commit

Permalink
WIP: implement text selection across multiple labels
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 23, 2024
1 parent a9c7768 commit 95aae8b
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 91 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 @@ -1610,6 +1610,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 @@ -2346,6 +2348,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 95aae8b

Please sign in to comment.