Skip to content

Commit

Permalink
Standardized on Position instead of Location
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Aug 31, 2023
1 parent a33e1e6 commit 76181ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions crates/gooey-core/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl WindowBuilder {
self
}

pub fn location(mut self, location: Point<Px>) -> Self {
self.attributes.location = Some(location);
pub fn position(mut self, position: Point<Px>) -> Self {
self.attributes.position = Some(position);
self
}

Expand Down Expand Up @@ -54,7 +54,7 @@ pub struct WindowAttributes {
pub inner_size: Option<Size<UPx>>,
pub min_inner_size: Option<Size<UPx>>,
pub max_inner_size: Option<Size<UPx>>,
pub location: Option<Point<Px>>,
pub position: Option<Point<Px>>,
pub resizable: bool,
pub enabled_buttons: WindowButtons,
pub title: String,
Expand All @@ -78,7 +78,7 @@ impl Default for WindowAttributes {
inner_size: None,
min_inner_size: None,
max_inner_size: None,
location: None,
position: None,
resizable: true,
enabled_buttons: WindowButtons::all(),
title: "Gooey".to_owned(),
Expand Down Expand Up @@ -150,7 +150,7 @@ pub struct NewWindow<Widget> {

pub struct Window {
pub inner_size: Dynamic<Size<UPx>>,
pub location: Dynamic<Point<Px>>,
pub position: Dynamic<Point<Px>>,
pub title: Dynamic<String>,
}

Expand All @@ -159,7 +159,7 @@ impl Window {
pub fn new(attrs: WindowAttributes, cx: &Context) -> Self {
Self {
inner_size: cx.new_dynamic(attrs.inner_size.unwrap_or_default()),
location: cx.new_dynamic(attrs.location.unwrap_or_default()),
position: cx.new_dynamic(attrs.position.unwrap_or_default()),
title: cx.new_dynamic(attrs.title),
}
}
Expand Down
18 changes: 9 additions & 9 deletions crates/gooey-kludgine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
#[derive(Debug)]
pub enum SurfaceEvent {
WindowTitleChanged,
WindowLocationChanged,
WindowPositionChanged,
WindowSizeChanged,
Invalidate,
// InvalidateRect(Rect<UPx>),
Expand Down Expand Up @@ -143,11 +143,11 @@ impl gooey_raster::SurfaceHandle for Handle {
}

fn window_position_set(&self) {
todo!()
let _result = self.0.send(SurfaceEvent::WindowPositionChanged);
}

fn window_size_set(&self) {
todo!()
let _result = self.0.send(SurfaceEvent::WindowSizeChanged);
}
// fn invalidate_rect(&self, rect: Rect<UPx>) {
// let _result = self.0.send(SurfaceEvent::InvalidateRect(rect));
Expand All @@ -170,7 +170,7 @@ where
let context = Context::root(RasterizedApp::<Kludgine>::new(handle.clone()), &runtime);
let running_window = Window {
inner_size: context.new_dynamic(window.inner_size()),
location: context.new_dynamic(window.location()),
position: context.new_dynamic(window.location()),
title: context.new_dynamic(window.title()),
};
let root = (window_init.init)(&context, &running_window).into_new(&context);
Expand Down Expand Up @@ -222,7 +222,7 @@ where
) -> kludgine::app::WindowAttributes<SurfaceEvent> {
let WindowAttributes {
inner_size,
location,
position,
resizable,
title,
window_level,
Expand All @@ -246,7 +246,7 @@ where
inner_size.height.0,
))
}),
location: location.map(|position| {
location: position.map(|position| {
winit::dpi::Position::Physical(PhysicalPosition::new(position.x.0, position.y.0))
}),
resizable: *resizable,
Expand Down Expand Up @@ -278,9 +278,9 @@ where
SurfaceEvent::WindowTitleChanged => {
self.window.title.map_ref(|title| window.set_title(title));
}
SurfaceEvent::WindowLocationChanged => {
if let Some(location) = self.window.location.get() {
window.set_location(location);
SurfaceEvent::WindowPositionChanged => {
if let Some(position) = self.window.position.get() {
window.set_location(position);
}
}
SurfaceEvent::WindowSizeChanged => {
Expand Down
2 changes: 1 addition & 1 deletion crates/gooey-widgets/src/flex/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl WidgetRasterizer for FlexRasterizer {
.make_size(layout.size, self.flex.other),
)
.into_signed();
let relative = event.position.map(|location| location - rect.origin);
let relative = event.position.map(|position| position - rect.origin);
if relative.map_or(false, |relative| {
relative.x >= 0
&& relative.y >= 0
Expand Down

0 comments on commit 76181ca

Please sign in to comment.