aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2025-03-18 04:48:24 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2025-03-18 04:48:24 +0100
commitaca564c44af54cd3b7fbfb9552aa1d74fab67df6 (patch)
tree5a7c22968072cd3190a78ef5761d4b23eb99d257
parent9add9a34213b2b872200634b8a59058ed919426d (diff)
checkbox focusable handling, png image detection from magic
-rw-r--r--Crow/src/Interface.cs8
-rw-r--r--Crow/src/Widgets/CheckBox.cs6
-rw-r--r--Crow/src/Widgets/Image.cs30
-rw-r--r--Crow/src/Widgets/SaturationValueSelector.cs2
-rw-r--r--Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow15
-rw-r--r--Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow10
6 files changed, 58 insertions, 13 deletions
diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs
index a10ef1db..0b4491f5 100644
--- a/Crow/src/Interface.cs
+++ b/Crow/src/Interface.cs
@@ -531,7 +531,7 @@ namespace Crow
windows [window].OnKeyDown (new KeyEventArgs (key, scanCode, modifiers));
};
static CharDelegate HandleCharDelegate = (IntPtr window, CodePoint codepoint) => {
- Console.WriteLine ($"Char: cp:{codepoint.Value} -> '{codepoint}'");
+ //Console.WriteLine ($"Char: cp:{codepoint.Value} -> '{codepoint}'");
windows [window].OnKeyPress (codepoint.ToChar());
};
static WindowSizeDelegate HandleWindowSizeDelegate = (IntPtr window, int Width, int Height) => {
@@ -1112,13 +1112,13 @@ namespace Crow
/// </summary>
public void Update(IContext ctx = null){
- CrowThread[] tmpThreads;
+ /*CrowThread[] tmpThreads;
lock (CrowThreads) {
tmpThreads = new CrowThread[CrowThreads.Count];
Array.Copy (CrowThreads.ToArray (), tmpThreads, CrowThreads.Count);
}
for (int i = 0; i < tmpThreads.Length; i++)
- tmpThreads [i].CheckState ();
+ tmpThreads [i].CheckState ();*/
if (lastMouseDownEvent != null) {
if (mouseRepeatTimer.ElapsedMilliseconds > DEVICE_REPEAT_INTERVAL) {
@@ -1935,7 +1935,7 @@ namespace Crow
}
void resetTooltip ()
{
- lock (tooltipMutex) {
+ lock (tooltipMutex) {//TODO:deadlock
if (tooltipVisible) {
ToolTipContainer.LayoutChanged -= ToolTipContainer_LayoutChanged;
ToolTipContainer.DataSource = null;
diff --git a/Crow/src/Widgets/CheckBox.cs b/Crow/src/Widgets/CheckBox.cs
index a51ff18c..82db7327 100644
--- a/Crow/src/Widgets/CheckBox.cs
+++ b/Crow/src/Widgets/CheckBox.cs
@@ -45,8 +45,10 @@ namespace Crow
public override void onMouseClick (object sender, MouseButtonEventArgs e)
{
- IsChecked = !IsChecked;
- e.Handled = true;
+ if (Focusable) {
+ IsChecked = !IsChecked;
+ e.Handled = true;
+ }
base.onMouseClick (sender, e);
}
}
diff --git a/Crow/src/Widgets/Image.cs b/Crow/src/Widgets/Image.cs
index b1a3a94f..a6f55937 100644
--- a/Crow/src/Widgets/Image.cs
+++ b/Crow/src/Widgets/Image.cs
@@ -25,6 +25,7 @@ namespace Crow
/// </remarks>
public class Image : Scalable
{
+ static readonly byte[] pngMagic = new byte[] {0x89, 0x50 ,0x4e ,0x47 ,0x0d ,0x0a};
Picture _pic;
string _svgSub;
@@ -139,9 +140,7 @@ namespace Crow
/// Initializes a new instance of the <see cref="Crow.Image"/> class from code
/// </summary>
/// <param name="iface">interface to bound to</param>
- public Image (Interface iface) : base(iface)
- {
- }
+ public Image (Interface iface, string style = null) : base(iface, style) { }
#endregion
#region Image Loading
@@ -154,8 +153,27 @@ namespace Crow
if (getcontenttype.Wait(HTTP_DOWNLOAD_TIMEOUT_MS) && getcontenttype.IsCompletedSuccessfully) {
if (!getcontenttype.Result.Content.Headers.TryGetValues("content-Type", out IEnumerable<string> contents))
return;
- string[] type = contents.FirstOrDefault().Split('/');
- if (!string.Equals(type[0], "image", StringComparison.Ordinal))
+ string[] type = contents.FirstOrDefault().Split('/');
+ if (string.Equals(contents.FirstOrDefault(), "application/octet-stream")) {
+ if (task.Wait(HTTP_DOWNLOAD_TIMEOUT_MS) && task.IsCompletedSuccessfully) {
+ MemoryStream dataCopy = new MemoryStream();
+ task.Result.CopyTo(dataCopy);
+ dataCopy.Position = 0;
+ Span<byte> magic = stackalloc byte[6];
+ dataCopy.Read(magic);
+ if (magic.SequenceEqual(pngMagic)) {
+ dataCopy.Position = 0;
+ pic = new BmpPicture(uri.AbsoluteUri);
+ } else
+ return;
+ pic.LoadFromStream(IFace, dataCopy);
+ pic.Scaled = scaled;
+ pic.KeepProportions = keepProps;
+ lock(IFace.UpdateMutex)
+ Picture = pic;
+ }
+ return;
+ } else if (!string.Equals(type[0], "image", StringComparison.Ordinal))
return;
if (string.Equals(type[1], "svg", StringComparison.Ordinal))
pic = new SvgPicture(uri.AbsoluteUri);
@@ -176,6 +194,8 @@ namespace Crow
lock(IFace.UpdateMutex)
Picture = pic;
}
+ } else {
+ Debug.WriteLine("image downloadThread: get content failed");
}
}
diff --git a/Crow/src/Widgets/SaturationValueSelector.cs b/Crow/src/Widgets/SaturationValueSelector.cs
index 69ff67b9..8cd54d18 100644
--- a/Crow/src/Widgets/SaturationValueSelector.cs
+++ b/Crow/src/Widgets/SaturationValueSelector.cs
@@ -49,6 +49,8 @@ namespace Crow
Rectangle r = ClientRectangle;
+ gr.Operator = Operator.Over;
+
if (Foreground != null) {//TODO:test if null should be removed
Foreground.SetAsSource (IFace, gr, r);
CairoHelpers.CairoRectangle (gr, r, CornerRadius);
diff --git a/Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow b/Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow
new file mode 100644
index 00000000..24b626cd
--- /dev/null
+++ b/Samples/common/ui/Interfaces/Experimental/SaturationValueSelector.crow
@@ -0,0 +1,15 @@
+<ColorPicker Height="Fit" Width="Fit">
+ <Template>
+ <VerticalStack >
+ <HorizontalStack Height="Fit" Margin="0">
+ <Label2 Text="{../svs.V}" Foreground="White"/>
+ <Label2 Text="{../svs.S}" Foreground="White"/>
+ </HorizontalStack>
+ <HorizontalStack Height="200" Margin="0">
+ <SaturationValueSelector Name="svs" V="10" S="0" Width="200" Height="200" Margin="0"
+Foreground="RebeccaPurple" Background="Transparent"/>
+ <HueSelector Orientation="Vertical" Width="20" Margin="0"/>
+ </HorizontalStack>
+ </VerticalStack>
+ </Template>
+</ColorPicker> \ No newline at end of file
diff --git a/Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow b/Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow
index 6e627506..9582994f 100644
--- a/Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow
+++ b/Samples/common/ui/Interfaces/TemplatedControl/testCheckbox.crow
@@ -19,7 +19,7 @@
</HorizontalStack>
</Template>
</CheckBox>
- <CheckBox Background="Jet" Height="30" Width="60"
+ <CheckBox Background="Jet" Height="30" Width="60" IsChecked="{²BoolVal}"
Checked="{sh.HorizontalAlignment=Right};{Background=SeaGreen}"
Unchecked="{sh.HorizontalAlignment=Left};{Background=Jet}">
<Template>
@@ -28,5 +28,11 @@
</Group>
</Template>
</CheckBox>
-
+ <CheckBox Caption="Ok" Background="Transparent" Height="30" Width="30" IsChecked="{²BoolVal}" CornerRadius="10"
+ Checked="{Background=SeaGreen}"
+ Unchecked="{Background=Red}">
+ <Template>
+ <Label2 Background="{./Background}" Text="{./Caption}" Margin="5" CornerRadius="{./CornerRadius}"/>
+ </Template>
+ </CheckBox>
</VerticalStack>