Skip to content

Commit

Permalink
Removing hit_test from Space
Browse files Browse the repository at this point in the history
Refs #201
  • Loading branch information
ecton committed Nov 5, 2024
1 parent 804fbbf commit 7da3f9f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Checkable::to_checkbox`
- `Dynamic::new_radio`
- `Dynamic::new_checkbox`
- `Space` no longer implements hit_test. If you need an area to intercept mouse
events, wrap the `Space` in a `Custom` widget:

```rust
Custom::new(Space::colored(Color::RED)).on_hit_test(|_, _| true)
```

### Changed

Expand Down
6 changes: 4 additions & 2 deletions src/widgets/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use figures::{IntoSigned, IntoUnsigned, Point, Rect, Size, Zero};
use intentional::Assert;

use super::super::widget::MountedWidget;
use super::Space;
use super::{Custom, Space};
use crate::animation::{AnimationHandle, AnimationTarget, IntoAnimate, Spawn, ZeroToOne};
use crate::context::{AsEventContext, EventContext, GraphicsContext, LayoutContext, Trackable};
use crate::styles::components::{EasingIn, ScrimColor};
Expand Down Expand Up @@ -1011,7 +1011,9 @@ impl WrapperWidget for ModalLayer {

for to_present in modal.iter().skip(self.presented.len()) {
self.focus_top_layer = true;
layer_widgets.push(Space::colored(context.get(&ScrimColor)));
layer_widgets.push(
Custom::new(Space::colored(context.get(&ScrimColor))).on_hit_test(|_, _| true),
);
self.presented.push(to_present.clone());
layer_widgets.push(to_present.clone().centered());
}
Expand Down
20 changes: 1 addition & 19 deletions src/widgets/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use kludgine::Color;

use crate::context::{GraphicsContext, LayoutContext};
use crate::styles::components::PrimaryColor;
use crate::styles::{Component, DynamicComponent, IntoDynamicComponentValue};
use crate::styles::{DynamicComponent, IntoDynamicComponentValue};
use crate::value::{IntoValue, Value};
use crate::widget::Widget;
use crate::ConstraintLimit;
Expand Down Expand Up @@ -76,24 +76,6 @@ impl Widget for Space {
) -> Size<UPx> {
available_space.map(ConstraintLimit::min)
}

fn hit_test(
&mut self,
_location: figures::Point<figures::units::Px>,
context: &mut crate::context::EventContext<'_>,
) -> bool {
let color = match self.color.get() {
ColorSource::Color(color) => color,
ColorSource::Dynamic(dynamic_component) => {
if let Some(Component::Color(color)) = dynamic_component.resolve(context) {
color
} else {
return false;
}
}
};
color.alpha() > 0
}
}

#[derive(Debug, PartialEq, Clone)]
Expand Down

0 comments on commit 7da3f9f

Please sign in to comment.