1
0
Fork 0

[Feat] supports for allows users can custom min_width of snapshots

main
Mist 2024-05-07 16:35:21 +08:00 committed by The Mist
parent 8f9e6fa5aa
commit 19dd1d4817
6 changed files with 29 additions and 5 deletions

View File

@ -89,11 +89,17 @@ pub trait Component {
fn parsed_style(&self) -> Style<f32> {
let style = self.style();
let (width, height) = self.get_dynamic_wh();
let width = self.parse_size(style.width, width)
+ style.padding.horizontal()
+ style.margin.horizontal();
Style {
width: self.parse_size(style.width, width)
+ style.padding.horizontal()
+ style.margin.horizontal(),
min_width: style.min_width,
width: if width > style.min_width {
width
} else {
style.min_width
},
height: self.parse_size(style.height, height)
+ style.padding.vertical()
+ style.margin.vertical(),

View File

@ -15,6 +15,7 @@ pub enum Size {
pub struct Style<T> {
pub width: T,
pub height: T,
pub min_width: f32,
pub align: ComponentAlign,
pub padding: Padding,
pub margin: Margin,
@ -26,6 +27,7 @@ pub type ComponentStyle = Style<f32>;
impl Default for RawComponentStyle {
fn default() -> Self {
Style {
min_width: 0.,
width: Size::Dynamic,
height: Size::Dynamic,
align: ComponentAlign::Row,
@ -38,6 +40,7 @@ impl Default for RawComponentStyle {
impl Default for ComponentStyle {
fn default() -> Self {
Style {
min_width: 0.,
width: 0.,
height: 0.,
align: ComponentAlign::Row,
@ -54,6 +57,12 @@ impl RawComponentStyle {
self
}
// Only works if the width is calculate dynamically
pub fn min_width(mut self, min_width: f32) -> Self {
self.min_width = min_width;
self
}
pub fn align(mut self, align: ComponentAlign) -> Self {
self.align = align;
self

View File

@ -10,6 +10,7 @@ pub const EDITOR_PADDING: f32 = 20.;
pub struct Rect {
radius: f32,
min_width: f32,
children: Vec<Box<dyn Component>>,
}
@ -20,6 +21,7 @@ impl Component for Rect {
fn style(&self) -> RawComponentStyle {
Style::default()
.min_width(self.min_width)
.align(ComponentAlign::Column)
.padding(Padding::from_value(EDITOR_PADDING))
}
@ -94,7 +96,11 @@ impl Component for Rect {
}
impl Rect {
pub fn new(radius: f32, children: Vec<Box<dyn Component>>) -> Rect {
Rect { radius, children }
pub fn new(radius: f32, min_width: Option<f32>, children: Vec<Box<dyn Component>>) -> Rect {
Rect {
radius,
children,
min_width: min_width.unwrap_or(0.),
}
}
}

View File

@ -29,6 +29,7 @@ pub struct TakeSnapshotParams {
pub start_line_number: Option<usize>,
pub highlight_start_line_number: Option<usize>,
pub highlight_end_line_number: Option<usize>,
pub min_width: Option<f32>,
}
impl FromObject for TakeSnapshotParams {

View File

@ -29,6 +29,7 @@ pub fn take_snapshot(params: TakeSnapshotParams) -> render_error::Result<Pixmap>
let pixmap = Container::from_children(vec![Box::new(Background::from_children(vec![
Box::new(Rect::new(
16.,
params.min_width,
vec![
Box::new(MacTitleBar::from_radius(8., params.mac_window_bar)),
Box::new(Breadcrumbs::from_path(

View File

@ -11,6 +11,7 @@ return {
breadcrumbs_separator = "/",
has_breadcrumbs = false,
has_line_number = false,
min_width = 0,
},
cwd = path_utils.back(path_utils.back(debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])"))),
preview_switch = true,