Expand clip_rects slightly to allow widgets just on the border
This commit is contained in:
parent
104f2191a0
commit
9b404159c5
2 changed files with 8 additions and 12 deletions
|
@ -7,7 +7,8 @@ This is the core library crate Emigui. It is fully platform independent without
|
|||
* [x] Button
|
||||
* [x] Checkbox
|
||||
* [x] Radiobutton
|
||||
* [x] Slider
|
||||
* [x] Horizontal slider
|
||||
* [ ] Vertical slider
|
||||
* [x] Collapsing header region
|
||||
* [x] Tooltip
|
||||
* [x] Movable/resizable windows
|
||||
|
@ -32,16 +33,7 @@ Add extremely quick animations for some things, maybe 2-3 frames. For instance:
|
|||
* [x] Separate Region::clip_rect from Region::rect
|
||||
* [x] Use clip rectangles when painting
|
||||
* [ ] Use clip rectangles when interacting
|
||||
|
||||
When drawing children, they are drawn just on the edge of the clip rect.
|
||||
This means e.g. the leftmost side of a button or slider handle is clipped.
|
||||
We can fix this in three ways:
|
||||
|
||||
* A) Each component minds its bounds, so button offset their position by their outline width + one pixel for AA
|
||||
* B) Each region enlarges the clip_rect slightly to handle inner children
|
||||
* C) Each region shrinks its rect slightly so children move further in in child regions (creates unintentional indentation. ugh)
|
||||
|
||||
I think A) is the correct solution, but might be tedious to get right for every component. For instance, the outline may grow on mouse-over, but we don't want to move the component as a consequence.
|
||||
* [x] Adjust clip rects so edges of child widgets aren't clipped
|
||||
|
||||
### Other
|
||||
* [ ] Generalize Layout so we can create grid layouts etc
|
||||
|
|
|
@ -71,12 +71,16 @@ impl Region {
|
|||
}
|
||||
|
||||
pub fn child_region(&self, child_rect: Rect) -> Self {
|
||||
// Allow child widgets to be just on the border and still have an outline with some thickness
|
||||
const CLIP_RECT_MARGIN: f32 = 3.0;
|
||||
Region {
|
||||
ctx: self.ctx.clone(),
|
||||
layer: self.layer,
|
||||
style: self.style,
|
||||
id: self.id,
|
||||
clip_rect: self.clip_rect.intersect(child_rect),
|
||||
clip_rect: self
|
||||
.clip_rect
|
||||
.intersect(child_rect.expand(CLIP_RECT_MARGIN)),
|
||||
desired_rect: child_rect,
|
||||
cursor: child_rect.min(),
|
||||
bounding_size: vec2(0.0, 0.0),
|
||||
|
|
Loading…
Reference in a new issue