Skip to content

Commit

Permalink
refactor: simplify how size is adjusted from ABM_QUERYPOS
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Nov 13, 2024
1 parent 4721924 commit e6818e1
Showing 1 changed file with 15 additions and 37 deletions.
52 changes: 15 additions & 37 deletions packages/desktop/src/common/windows/app_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,48 +54,26 @@ pub fn create_app_bar(

let adjusted_position = PhysicalPosition::new(data.rc.left, data.rc.top);

// Size has changed if the edge that is not being docked to has been
// adjusted.
let adjusted_size = match edge {
DockEdge::Top => PhysicalSize::new(
size.width
- (rect.right - data.rc.right)
- (rect.left - data.rc.left),
size.height - (rect.bottom - data.rc.bottom),
),
DockEdge::Bottom => PhysicalSize::new(
size.width
- (rect.right - data.rc.right)
- (rect.left - data.rc.left),
size.height - (rect.top - data.rc.top),
),
DockEdge::Left => PhysicalSize::new(
size.width - (rect.right - data.rc.right),
size.height
- (rect.bottom - data.rc.bottom)
- (rect.top - data.rc.top),
),
DockEdge::Right => PhysicalSize::new(
size.width - (rect.left - data.rc.left),
size.height
- (rect.bottom - data.rc.bottom)
- (rect.top - data.rc.top),
),
let width_delta = match edge {
DockEdge::Left => rect.right - data.rc.right,
DockEdge::Right => rect.left - data.rc.left,
_ => (rect.right - data.rc.right) - (rect.left - data.rc.left),
};

info!("asdf {:?}", data.rc);
info!(
"Adjusting app bar position from {:?} to {:?}.",
position, adjusted_position
);
let height_delta = match edge {
DockEdge::Top => rect.bottom - data.rc.bottom,
DockEdge::Bottom => rect.top - data.rc.top,
_ => (rect.bottom - data.rc.bottom) - (rect.top - data.rc.top),
};

info!(
"Adjusting app bar size from {:?} to {:?}.",
size, adjusted_size
// Size has changed if the edge that is not being docked has been
// adjusted by ABM_QUERYPOS. For example, if the top edge is docked, then
// diffs in the left and right edges are the size changes.
let adjusted_size = PhysicalSize::new(
size.width - width_delta,
size.height - height_delta,
);

// Update the rect with the adjusted position while keeping the original
// size.
data.rc = RECT {
left: adjusted_position.x,
top: adjusted_position.y,
Expand Down

0 comments on commit e6818e1

Please sign in to comment.