Skip to content

Commit

Permalink
support scale
Browse files Browse the repository at this point in the history
  • Loading branch information
beyaz committed Sep 8, 2024
1 parent 35db64b commit dd97a82
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
44 changes: 39 additions & 5 deletions ReactWithDotNet/UIDesigner/ReactWithDotNetDesigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public sealed class ReactWithDotNetDesigner : Component<ReactWithDotNetDesignerM

bool Preview => GetQuery("preview") == "true";

StyleModifier ScaleStyle => TransformOrigin("0 0") + Transform($"scale({state.Scale / (double)100})");

/// <summary>
/// Indicates component is in design mode.
/// </summary>
Expand Down Expand Up @@ -97,7 +99,7 @@ protected override Element render()
return new ReactWithDotNetDesignerComponentPreview();
}

var propertyPanelContent = new FlexColumn(SizeFull, FontSize15)
var propertyPanelContent = new FlexColumn(SizeFull, FontSize15, Gap(4))
{
new link { href = "https://fonts.cdnfonts.com/css/ibm-plex-mono-3", rel = "stylesheet" },

Expand Down Expand Up @@ -128,7 +130,6 @@ protected override Element render()
}
},

SpaceY(5),
new FlexColumn(WidthFull, Flex(1, 1, 0), PaddingLeftRight(3))
{
new MethodSelectionView
Expand All @@ -141,8 +142,6 @@ protected override Element render()
}
},

SpaceY(10),

new FlexRow(WidthFull, PaddingLeftRight(3))
{
new fieldset(WidthFull)
Expand Down Expand Up @@ -260,6 +259,41 @@ protected override Element render()
}
}
}
},

new FlexRow(WidthFull, PaddingLeftRight(3), AlignItemsCenter, Gap(5))
{
createLabel($"Scale: %{state.Scale}"),
new FlexRowCentered(BorderRadius(100), Padding(3), Background(Blue200), Hover(Background(Blue300)))
{
OnClick(async _ =>
{
if (state.Scale <= 50)
{
return;
}

state = state with { Scale = state.Scale - 10 };

await SaveState();
}),
new IconMinus()
},
new FlexRowCentered(BorderRadius(100), Padding(3), Background(Blue200), Hover(Background(Blue300)))
{
OnClick(async _ =>
{
if (state.Scale >= 100)
{
return;
}

state = state with { Scale = state.Scale + 10 };

await SaveState();
}),
new IconPlus()
}
}
};

Expand Down Expand Up @@ -309,7 +343,7 @@ protected override Element render()
{
new HotReloadListener(),
propertyPanel,
new FlexColumn(AlignItemsCenter, FlexGrow(1), Padding(7), MarginLeft(40))
new FlexColumn(AlignItemsCenter, FlexGrow(1), Padding(7), MarginLeft(40), ScaleStyle)
{
createHorizontalRuler() + Width(state.ScreenWidth) + MarginTop(5),
outputPanel
Expand Down
2 changes: 2 additions & 0 deletions ReactWithDotNet/UIDesigner/ReactWithDotNetDesignerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public sealed record ReactWithDotNetDesignerModel
public bool PropertyPanelIsClosed { get; init; }

public int ScreenHeight { get; init; } = 100;

public int Scale { get; init; } = 100;
}

0 comments on commit dd97a82

Please sign in to comment.