From e000798c0e84b1ee6502756a4c06e872a3e28200 Mon Sep 17 00:00:00 2001 From: 4JX <79868816+4JX@users.noreply.github.com> Date: Wed, 9 Feb 2022 18:49:06 +0100 Subject: [PATCH] Fix `Margin` not being accessible --- egui/src/containers/frame.rs | 45 +----------------------------------- egui/src/containers/mod.rs | 2 +- egui/src/style.rs | 45 +++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/egui/src/containers/frame.rs b/egui/src/containers/frame.rs index 044b96a9a97..9e7cd949852 100644 --- a/egui/src/containers/frame.rs +++ b/egui/src/containers/frame.rs @@ -1,51 +1,8 @@ //! Frame container -use crate::{layers::ShapeIdx, *}; +use crate::{layers::ShapeIdx, style::Margin, *}; use epaint::*; -#[derive(Clone, Copy, Debug, Default, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -pub struct Margin { - pub left: f32, - pub right: f32, - pub top: f32, - pub bottom: f32, -} - -impl Margin { - #[inline] - pub fn same(margin: f32) -> Self { - Self { - left: margin, - right: margin, - top: margin, - bottom: margin, - } - } - - /// Margins with the same size on opposing sides - #[inline] - pub fn symmetric(x: f32, y: f32) -> Self { - Self { - left: x, - right: x, - top: y, - bottom: y, - } - } - - /// Total margins on both sides - pub fn sum(&self) -> Vec2 { - Vec2::new(self.left + self.right, self.top + self.bottom) - } -} - -impl From for Margin { - fn from(v: Vec2) -> Self { - Self::symmetric(v.x, v.y) - } -} - /// Color and margin of a rectangular background of a [`Ui`]. #[derive(Clone, Copy, Debug, Default, PartialEq)] #[must_use = "You should call .show()"] diff --git a/egui/src/containers/mod.rs b/egui/src/containers/mod.rs index cc457a511a5..f151b8e9edd 100644 --- a/egui/src/containers/mod.rs +++ b/egui/src/containers/mod.rs @@ -16,7 +16,7 @@ pub use { area::Area, collapsing_header::{CollapsingHeader, CollapsingResponse}, combo_box::*, - frame::{Frame, Margin}, + frame::Frame, panel::{CentralPanel, SidePanel, TopBottomPanel}, popup::*, resize::Resize, diff --git a/egui/src/style.rs b/egui/src/style.rs index d13548a6b1e..7469c561ad4 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -2,7 +2,7 @@ #![allow(clippy::if_same_then_else)] -use crate::{color::*, emath::*, FontFamily, FontId, Margin, Response, RichText, WidgetText}; +use crate::{color::*, emath::*, FontFamily, FontId, Response, RichText, WidgetText}; use epaint::{mutex::Arc, Rounding, Shadow, Stroke}; use std::collections::BTreeMap; @@ -277,6 +277,49 @@ impl Spacing { } } +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +pub struct Margin { + pub left: f32, + pub right: f32, + pub top: f32, + pub bottom: f32, +} + +impl Margin { + #[inline] + pub fn same(margin: f32) -> Self { + Self { + left: margin, + right: margin, + top: margin, + bottom: margin, + } + } + + /// Margins with the same size on opposing sides + #[inline] + pub fn symmetric(x: f32, y: f32) -> Self { + Self { + left: x, + right: x, + top: y, + bottom: y, + } + } + + /// Total margins on both sides + pub fn sum(&self) -> Vec2 { + Vec2::new(self.left + self.right, self.top + self.bottom) + } +} + +impl From for Margin { + fn from(v: Vec2) -> Self { + Self::symmetric(v.x, v.y) + } +} + /// How and when interaction happens. #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]