emilk / emilk/egui

DragValue loses adjustability when placed inside a rect/child_ui

Open
#1,992 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

I'm building a custom widget and want to include a DragValue inside. When I place it after my widget it works, but when I place it in a child_ui inside my widget it can't be dragged/text entered, only the hover-effect seems to be fine. I have a red triangle (a set point) that can be dragged and adjusted, but I want the position to be also adjustable by a `DragValue`.
widget_gauge

Code structure:
```
pub fn gauge_ui(...) -> egui::Response {

let desired_size = egui::vec2(size as f32, size as f32);
let (rect, mut response) = ui.allocate_exact_size(desired_size, egui::Sense::click_and_drag());
if ui.is_rect_visible(rect) {
let visuals = ui.style().interact(&response);
let rect = rect.expand(visuals.expansion);

// draw the cool shapes

if response.dragged() {
let pos = response.interact_pointer_pos();
match pos {
None => {}
Some(p) => {
// update position of triangle
}
}
response.mark_changed(); // report back that the value changed
}
let mut c_ui = ui.child_ui(rect,Layout::default());
c_ui.add(egui::DragValue::new(set)
.min_decimals(1)
.max_decimals(1)
.suffix(suffix));
ui.add(egui::DragValue::new(set)
.min_decimals(1)
.max_decimals(1)
.suffix(suffix));
}
response
}
```
When called by `c_ui` the DragValue will be inside the widget and not controllable, when called by `ui` it will be placed after my widget. What can be done to make the DragValue adjustable inside the other rect?
I'm fairly new to egui, but I really like it so far! Big kudos to everyone involved!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the gauge_ui snippet and reproduce the difference between adding DragValue through c_ui and directly through ui. Read the egui child_ui and DragValue interaction behavior, especially how input regions overlap. Done means the DragValue inside the child rect accepts both dragging and text entry without breaking the surrounding widget.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.