Skip to content

Commit 726771c

Browse files
committed
Add image color peek sample to Media page
- Enables live ARGB color display on image hover for user inspection
1 parent 1809bd5 commit 726771c

1 file changed

Lines changed: 36 additions & 22 deletions

File tree

‎samples/MewUI.Gallery/Program.cs‎

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,21 @@
33
using Aprillz.MewUI;
44
using Aprillz.MewUI.Controls;
55

6-
76
var stopwatch = Stopwatch.StartNew();
87
Startup();
98

109
Window window = null!;
1110
Label backendText = null!;
1211
Label themeText = null!;
12+
Image peekImage = null!;
1313
var fpsText = new ObservableValue<string>("FPS: -");
14+
var imagePeekText = new ObservableValue<string>("Color: -");
1415
var fpsStopwatch = new Stopwatch();
1516
var fpsFrames = 0;
1617
var maxFpsEnabled = new ObservableValue<bool>(false);
1718

1819
var currentAccent = ThemeManager.DefaultAccent;
1920

20-
var app = Application
21-
.Create()
22-
.UseMetrics(ThemeMetrics.Default with
23-
{
24-
FontFamily = "Noto Sans KR",
25-
ControlCornerRadius = 6,
26-
BaseControlHeight = 32,
27-
FontSize = 13
28-
});
29-
30-
3121
var logo = ImageSource.FromFile("logo_h-1280.png");
3222
var april = ImageSource.FromFile("april.jpg");
3323

@@ -77,7 +67,7 @@
7767
root.Icon = IconSource.FromStream(rs);
7868
}
7969

80-
app.Run(root);
70+
Application.Run(root);
8171

8272
FrameworkElement TopBar()
8373
{
@@ -129,7 +119,6 @@ FrameworkElement TopBar()
129119
.Ref(out themeText)
130120
.CenterVertical(),
131121

132-
133122
AccentPicker()
134123

135124
),
@@ -702,17 +691,17 @@ FrameworkElement PanelCard(string title, FrameworkElement content) =>
702691
);
703692
}
704693

705-
FrameworkElement MediaPage()
706-
{
707-
return CardGrid(
708-
Card("Image",
694+
FrameworkElement MediaPage() =>
695+
CardGrid(
696+
Card(
697+
"Image",
709698
new StackPanel()
710699
.Vertical()
711700
.Spacing(8)
712701
.Children(
713702
new Image()
714703
.Source(april)
715-
.Width(220)
704+
.Width(120)
716705
.Height(120)
717706
.StretchMode(ImageStretch.Uniform)
718707
.Center(),
@@ -722,7 +711,33 @@ FrameworkElement MediaPage()
722711
)
723712
),
724713

725-
Card("Image ViewBox",
714+
Card(
715+
"Peek Color",
716+
new StackPanel()
717+
.Vertical()
718+
.Spacing(8)
719+
.Children(
720+
new Image()
721+
.Ref(out peekImage)
722+
.OnMouseMove(e => imagePeekText.Value = peekImage.TryPeekColor(e.Position, out var c)
723+
? $"Color: #{c.ToArgb():X8}"
724+
: "Color: #--------")
725+
.Source(logo)
726+
.ImageScaleQuality(ImageScaleQuality.HighQuality)
727+
.Width(200)
728+
.Height(120)
729+
.StretchMode(ImageStretch.Uniform)
730+
.Center(),
731+
new Label()
732+
.BindText(imagePeekText)
733+
.FontFamily("Consolas")
734+
.FontSize(11)
735+
.Center()
736+
)
737+
),
738+
739+
Card(
740+
"Image ViewBox",
726741
new StackPanel()
727742
.Vertical()
728743
.Spacing(8)
@@ -746,12 +761,11 @@ FrameworkElement MediaPage()
746761
),
747762

748763
new Label()
749-
.Text("Left: full image (Uniform). Right: ViewBox (center 50%) + UniformToFill.")
764+
.Text("Full image (Uniform) / ViewBox (center 50%) + UniformToFill")
750765
.FontSize(11)
751766
)
752767
)
753768
);
754-
}
755769

756770
void UpdateTopBar()
757771
{

0 commit comments

Comments
 (0)