Make Margin
pub and move to style.rs (#1236)
This commit is contained in:
parent
b2323bd13e
commit
2f042ababd
3 changed files with 46 additions and 46 deletions
|
@ -1,51 +1,8 @@
|
||||||
//! Frame container
|
//! Frame container
|
||||||
|
|
||||||
use crate::{layers::ShapeIdx, *};
|
use crate::{layers::ShapeIdx, style::Margin, *};
|
||||||
use epaint::*;
|
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<Vec2> for Margin {
|
|
||||||
fn from(v: Vec2) -> Self {
|
|
||||||
Self::symmetric(v.x, v.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Color and margin of a rectangular background of a [`Ui`].
|
/// Color and margin of a rectangular background of a [`Ui`].
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||||
#[must_use = "You should call .show()"]
|
#[must_use = "You should call .show()"]
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub use {
|
||||||
area::Area,
|
area::Area,
|
||||||
collapsing_header::{CollapsingHeader, CollapsingResponse},
|
collapsing_header::{CollapsingHeader, CollapsingResponse},
|
||||||
combo_box::*,
|
combo_box::*,
|
||||||
frame::{Frame, Margin},
|
frame::Frame,
|
||||||
panel::{CentralPanel, SidePanel, TopBottomPanel},
|
panel::{CentralPanel, SidePanel, TopBottomPanel},
|
||||||
popup::*,
|
popup::*,
|
||||||
resize::Resize,
|
resize::Resize,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#![allow(clippy::if_same_then_else)]
|
#![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 epaint::{mutex::Arc, Rounding, Shadow, Stroke};
|
||||||
use std::collections::BTreeMap;
|
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<Vec2> for Margin {
|
||||||
|
fn from(v: Vec2) -> Self {
|
||||||
|
Self::symmetric(v.x, v.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// How and when interaction happens.
|
/// How and when interaction happens.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
|
Loading…
Reference in a new issue