From 7d833d5386cf526dc6bcc7c2f4baf0d729c295bd Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 11 Jun 2020 10:22:03 -0700 Subject: [PATCH] Fix important_area for ShadowView and PaddedView --- CHANGELOG.md | 8 ++++++++ cursive-core/src/views/dialog.rs | 2 ++ cursive-core/src/views/padded_view.rs | 8 +++++++- cursive-core/src/views/shadow_view.rs | 11 ++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b48ade..db56e3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## (Next version) cursive-core=0.1.1 + +### Bugfixes + +- More hygienic `wrap_impl!` macro using fully-qualified paths. +- Fixed `LinearLayout` giving children incorrect sizes. +- More accurate "important area" for `ShadowView` and `PaddedView`. + ## 0.15.0 ### Breaking changes diff --git a/cursive-core/src/views/dialog.rs b/cursive-core/src/views/dialog.rs index eada861..9b5cddf 100644 --- a/cursive-core/src/views/dialog.rs +++ b/cursive-core/src/views/dialog.rs @@ -754,6 +754,8 @@ impl View for Dialog { } fn important_area(&self, _: Vec2) -> Rect { + // Only the content is important. + // TODO: if a button is focused, return the button position instead. self.content.important_area(self.content.size) + self.borders.top_left() + self.padding.top_left() diff --git a/cursive-core/src/views/padded_view.rs b/cursive-core/src/views/padded_view.rs index 55b28b1..dddbe13 100644 --- a/cursive-core/src/views/padded_view.rs +++ b/cursive-core/src/views/padded_view.rs @@ -1,4 +1,5 @@ use crate::event::{Event, EventResult}; +use crate::rect::Rect; use crate::view::{Margins, View, ViewWrapper}; use crate::Printer; use crate::Vec2; @@ -43,7 +44,7 @@ impl PaddedView { /// Sets the margins for this view. pub fn set_margins(&mut self, margins: Margins) { - // TODO: invalidate? + // TODO: invalidate? wrap_needs_relayout? self.margins = margins; } @@ -74,4 +75,9 @@ impl ViewWrapper for PaddedView { let printer = &printer.offset(top_left).shrinked(bot_right); self.view.draw(printer); } + + fn wrap_important_area(&self, view_size: Vec2) -> Rect { + let inner_size = view_size.saturating_sub(self.margins.combined()); + self.view.important_area(inner_size) + self.margins.top_left() + } } diff --git a/cursive-core/src/views/shadow_view.rs b/cursive-core/src/views/shadow_view.rs index 950a31c..c5cb569 100644 --- a/cursive-core/src/views/shadow_view.rs +++ b/cursive-core/src/views/shadow_view.rs @@ -1,4 +1,5 @@ use crate::event::{Event, EventResult}; +use crate::rect::Rect; use crate::theme::ColorStyle; use crate::view::{View, ViewWrapper}; use crate::Printer; @@ -11,7 +12,7 @@ pub struct ShadowView { view: T, top_padding: bool, left_padding: bool, - // TODO: invalidate if we change the padding? + // TODO: invalidate if we change the padding? wrap_needs_relayout? } impl ShadowView { @@ -24,7 +25,9 @@ impl ShadowView { } } + /// Return the total padding for this view (include both sides) fn padding(&self) -> Vec2 { + // We always need (1, 1) for the shadow. self.top_left_padding() + (1, 1) } @@ -100,4 +103,10 @@ impl ViewWrapper for ShadowView { let printer = printer.shrinked((1, 1)); self.view.draw(&printer); } + + fn wrap_important_area(&self, view_size: Vec2) -> Rect { + self.view + .important_area(view_size.saturating_sub(self.padding())) + + self.top_left_padding() + } }