Skip to content

Commit 2f042ab

Browse files
authored
Make Margin pub and move to style.rs (#1236)
1 parent b2323bd commit 2f042ab

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

egui/src/containers/frame.rs

+1-44
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,8 @@
11
//! Frame container
22
3-
use crate::{layers::ShapeIdx, *};
3+
use crate::{layers::ShapeIdx, style::Margin, *};
44
use epaint::*;
55

6-
#[derive(Clone, Copy, Debug, Default, PartialEq)]
7-
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
8-
pub struct Margin {
9-
pub left: f32,
10-
pub right: f32,
11-
pub top: f32,
12-
pub bottom: f32,
13-
}
14-
15-
impl Margin {
16-
#[inline]
17-
pub fn same(margin: f32) -> Self {
18-
Self {
19-
left: margin,
20-
right: margin,
21-
top: margin,
22-
bottom: margin,
23-
}
24-
}
25-
26-
/// Margins with the same size on opposing sides
27-
#[inline]
28-
pub fn symmetric(x: f32, y: f32) -> Self {
29-
Self {
30-
left: x,
31-
right: x,
32-
top: y,
33-
bottom: y,
34-
}
35-
}
36-
37-
/// Total margins on both sides
38-
pub fn sum(&self) -> Vec2 {
39-
Vec2::new(self.left + self.right, self.top + self.bottom)
40-
}
41-
}
42-
43-
impl From<Vec2> for Margin {
44-
fn from(v: Vec2) -> Self {
45-
Self::symmetric(v.x, v.y)
46-
}
47-
}
48-
496
/// Color and margin of a rectangular background of a [`Ui`].
507
#[derive(Clone, Copy, Debug, Default, PartialEq)]
518
#[must_use = "You should call .show()"]

egui/src/containers/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use {
1616
area::Area,
1717
collapsing_header::{CollapsingHeader, CollapsingResponse},
1818
combo_box::*,
19-
frame::{Frame, Margin},
19+
frame::Frame,
2020
panel::{CentralPanel, SidePanel, TopBottomPanel},
2121
popup::*,
2222
resize::Resize,

egui/src/style.rs

+44-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![allow(clippy::if_same_then_else)]
44

5-
use crate::{color::*, emath::*, FontFamily, FontId, Margin, Response, RichText, WidgetText};
5+
use crate::{color::*, emath::*, FontFamily, FontId, Response, RichText, WidgetText};
66
use epaint::{mutex::Arc, Rounding, Shadow, Stroke};
77
use std::collections::BTreeMap;
88

@@ -277,6 +277,49 @@ impl Spacing {
277277
}
278278
}
279279

280+
#[derive(Clone, Copy, Debug, Default, PartialEq)]
281+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
282+
pub struct Margin {
283+
pub left: f32,
284+
pub right: f32,
285+
pub top: f32,
286+
pub bottom: f32,
287+
}
288+
289+
impl Margin {
290+
#[inline]
291+
pub fn same(margin: f32) -> Self {
292+
Self {
293+
left: margin,
294+
right: margin,
295+
top: margin,
296+
bottom: margin,
297+
}
298+
}
299+
300+
/// Margins with the same size on opposing sides
301+
#[inline]
302+
pub fn symmetric(x: f32, y: f32) -> Self {
303+
Self {
304+
left: x,
305+
right: x,
306+
top: y,
307+
bottom: y,
308+
}
309+
}
310+
311+
/// Total margins on both sides
312+
pub fn sum(&self) -> Vec2 {
313+
Vec2::new(self.left + self.right, self.top + self.bottom)
314+
}
315+
}
316+
317+
impl From<Vec2> for Margin {
318+
fn from(v: Vec2) -> Self {
319+
Self::symmetric(v.x, v.y)
320+
}
321+
}
322+
280323
/// How and when interaction happens.
281324
#[derive(Clone, Debug, PartialEq)]
282325
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]

0 commit comments

Comments
 (0)