Skip to content

Commit

Permalink
[awm2] Window frame uses interior mutability
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Nov 27, 2022
1 parent 8139a62 commit 3de4ba8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 4 additions & 0 deletions rust_programs/agx_definitions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ impl Rect {
}
}

pub fn replace_origin(&self, new_origin: Point) -> Self {
Self::from_parts(new_origin, self.size)
}

pub fn from_parts(origin: Point, size: Size) -> Self {
Rect { origin, size }
}
Expand Down
30 changes: 16 additions & 14 deletions rust_programs/awm2/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ trait DesktopElement {
}

pub struct Window {
pub frame: Rect,
pub frame: RefCell<Rect>,
drawable_rects: RefCell<Vec<Rect>>,
pub owner_service: String,
layer: RefCell<SingleFramebufferLayer>,
Expand All @@ -75,17 +75,21 @@ impl Window {
fn new(owner_service: &str, frame: Rect, window_layer: SingleFramebufferLayer) -> Self {
let total_size = Self::total_size_for_content_size(window_layer.size());
Self {
frame,
frame: RefCell::new(frame),
drawable_rects: RefCell::new(vec![]),
owner_service: owner_service.to_string(),
layer: RefCell::new(SingleFramebufferLayer::new(total_size)),
content_layer: RefCell::new(window_layer),
}
}

fn set_frame(&self, frame: Rect) {
*self.frame.borrow_mut() = frame
}

fn redraw_title_bar(&self) {
let title_bar_slice = self.layer.borrow_mut().get_slice(Rect::with_size(Size::new(
self.frame.width(),
self.frame().width(),
Self::TITLE_BAR_HEIGHT as isize,
)));
title_bar_slice.fill(Color::dark_gray());
Expand All @@ -110,13 +114,18 @@ impl Window {

impl Display for Window {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "<Window \"{}\" @ {}>", self.owner_service, self.frame)
write!(
f,
"<Window \"{}\" @ {}>",
self.owner_service,
self.frame.borrow()
)
}
}

impl DesktopElement for Window {
fn frame(&self) -> Rect {
self.frame
*self.frame.borrow()
}

fn name(&self) -> String {
Expand All @@ -134,7 +143,7 @@ impl DesktopElement for Window {
fn get_slice(&self) -> Box<dyn LikeLayerSlice> {
self.layer
.borrow_mut()
.get_slice(Rect::with_size(self.frame.size))
.get_slice(Rect::with_size(self.frame().size))
}
}

Expand Down Expand Up @@ -407,13 +416,6 @@ impl Desktop {
.get_slice(Rect::with_size(self.desktop_frame.size)),
self.desktop_frame,
);
/*
Self::copy_rect(
&mut *self.screen_buffer_layer.get_slice(self.desktop_frame),
&mut *self.video_memory_layer.get_slice(self.desktop_frame),
mouse_rect,
);
*/
}

pub fn draw_frame_composited(&mut self) {
Expand Down Expand Up @@ -505,7 +507,7 @@ impl Desktop {

for (occluding_elem_idx, occluding_elem) in a.iter().enumerate().rev() {
//println!("\toccluding_elem_idx {occluding_elem_idx}");
if !elem.frame.intersects_with(occluding_elem.frame) {
if !elem.frame().intersects_with(occluding_elem.frame()) {
continue;
}
//println!("\tOccluding {} by view with frame {}", elem.frame(), occluding_elem.frame());
Expand Down
1 change: 1 addition & 0 deletions rust_programs/libgui/src/window_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl LikeLayerSlice for PixelLayerSlice {
}

fn blit2(&self, source_layer: &Box<dyn LikeLayerSlice>) {
// TODO(PT): Share this implementation with LayerSlice?
assert!(self.frame().size == source_layer.frame().size);

let bpp = 4;
Expand Down

0 comments on commit 3de4ba8

Please sign in to comment.