Skip to content

Commit

Permalink
Merge branch 'sourcegit-scm:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiboz authored Sep 11, 2024
2 parents fa42f53 + a63450f commit beb7b54
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
15 changes: 15 additions & 0 deletions src/ViewModels/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ public Launcher(string startupRepo)
_ignoreIndexChange = false;
}

public void Quit(double width, double height)
{
var pref = Preference.Instance;
pref.Layout.LauncherWidth = width;
pref.Layout.LauncherHeight = height;
pref.Save();

_ignoreIndexChange = true;

foreach (var one in Pages)
CloseRepositoryInTab(one, false);

_ignoreIndexChange = false;
}

public void AddNewTab()
{
var page = new LauncherPage();
Expand Down
57 changes: 33 additions & 24 deletions src/Views/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public uint Value
set => SetValue(ValueProperty, value);
}

// Values are copied from Avalonia: src/Avalonia.Controls.ColorPicker/ColorPalettes/FluentColorPalette.cs
private static readonly Color[,] COLOR_TABLE = new Color[,]
{
{
// Ordering reversed for this section only
Color.FromArgb(255, 255, 67, 67), /* #FF4343 */
Color.FromArgb(255, 209, 52, 56), /* #D13438 */
Color.FromArgb(255, 239, 105, 80), /* #EF6950 */
Expand Down Expand Up @@ -93,21 +93,25 @@ public override void Render(DrawingContext context)
base.Render(context);

// Color table.
var border = this.FindResource("Brush.Border0") as IBrush;
var pen = new Pen(border, 0.2);
{
// Colors
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 8; j++)
{
var idx = i * 8 + j;
var x = j * 32.0;
var y = i * 32.0;
context.DrawRectangle(new SolidColorBrush(COLOR_TABLE[i, j]), pen, new Rect(x, y, 32, 32));
if (idx == _hightlightedTableElement)
context.DrawRectangle(new Pen(Brushes.White, 2), new Rect(x + 2, y + 2, 28, 28));
}
context.FillRectangle(new SolidColorBrush(COLOR_TABLE[i, j]), new Rect(j * 32, i * 32, 32, 32));
}

// Borders
var border = this.FindResource("Brush.Border0") as IBrush;
var pen = new Pen(border, 0.4);
for (int i = 1; i < 6; i++)
context.DrawLine(pen, new Point(0, i * 32), new Point(256, i * 32));
for (int j = 1; j < 8; j++)
context.DrawLine(pen, new Point(j * 32, 0), new Point(j * 32, 192));

// Selected
if (_hightlightedTableRect is { } rect)
context.DrawRectangle(new Pen(Brushes.White, 2), rect);
}

// Palette picker
Expand Down Expand Up @@ -136,6 +140,12 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
}
}

protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
_hightlightedTableRect = null;
}

protected override Size MeasureOverride(Size availableSize)
{
return new Size(256, 256);
Expand All @@ -148,12 +158,12 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
var p = e.GetPosition(this);
if (_colorTableRect.Contains(p))
{
int col = (int)Math.Floor(p.X / 32.0);
int row = (int)Math.Floor(p.Y / 32.0);
int idx = row * 8 + col;
if (_hightlightedTableElement != idx)
var col = (int)Math.Floor(p.X / 32.0);
var row = (int)Math.Floor(p.Y / 32.0);
var rect = new Rect(col * 32 + 2, row * 32 + 2, 28, 28);
if (!rect.Equals(_hightlightedTableRect))
{
_hightlightedTableElement = idx;
_hightlightedTableRect = rect;
SetCurrentValue(ValueProperty, COLOR_TABLE[row, col].ToUInt32());
}

Expand All @@ -162,32 +172,32 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)

if (_darkestRect.Rect.Contains(p))
{
_hightlightedTableElement = -1;
_hightlightedTableRect = null;
SetCurrentValue(ValueProperty, _darkestColor.ToUInt32());
}
else if (_darkerRect.Contains(p))
{
_hightlightedTableElement = -1;
_hightlightedTableRect = null;
SetCurrentValue(ValueProperty, _darkerColor.ToUInt32());
}
else if (_darkRect.Contains(p))
{
_hightlightedTableElement = -1;
_hightlightedTableRect = null;
SetCurrentValue(ValueProperty, _darkColor.ToUInt32());
}
else if (_lightRect.Contains(p))
{
_hightlightedTableElement = -1;
_hightlightedTableRect = null;
SetCurrentValue(ValueProperty, _lightColor.ToUInt32());
}
else if (_lighterRect.Contains(p))
{
_hightlightedTableElement = -1;
_hightlightedTableRect = null;
SetCurrentValue(ValueProperty, _lighterColor.ToUInt32());
}
else if (_lightestRect.Rect.Contains(p))
{
_hightlightedTableElement = -1;
_hightlightedTableRect = null;
SetCurrentValue(ValueProperty, _lightestColor.ToUInt32());
}
}
Expand Down Expand Up @@ -224,8 +234,7 @@ private Color GetNextColor(HsvColor c, double step)
private Rect _lightRect = new Rect(160, 200, 32, 32);
private Rect _lighterRect = new Rect(192, 200, 32, 32);
private RoundedRect _lightestRect = new RoundedRect(new Rect(224, 200, 32, 32), new CornerRadius(0, 4, 4, 0));

private int _hightlightedTableElement = -1;
private Rect? _hightlightedTableRect = null;

private Color _darkestColor;
private Color _darkerColor;
Expand Down
10 changes: 5 additions & 5 deletions src/Views/ConfigureWorkspace.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
x:Name="ThisControl"
Icon="/App.ico"
Title="{DynamicResource Text.ConfigureWorkspace}"
Width="494" SizeToContent="Height"
SizeToContent="WidthAndHeight"
CanResize="False"
WindowStartupLocation="CenterOwner">
<Grid RowDefinitions="Auto,Auto">
<Grid RowDefinitions="Auto,Auto" MinWidth="494">
<!-- TitleBar -->
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
<Border Grid.Column="0" Grid.ColumnSpan="3"
Expand Down Expand Up @@ -46,7 +46,7 @@
</Grid>

<!-- BODY -->
<Grid Grid.Row="1" ColumnDefinitions="200,*" Height="324" Margin="8">
<Grid Grid.Row="1" ColumnDefinitions="200,16,256" Height="324" Margin="8">
<Border Grid.Column="0"
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
Background="{DynamicResource Brush.Contents}">
Expand Down Expand Up @@ -104,12 +104,12 @@
</Grid>
</Border>

<ContentControl Grid.Column="1" Margin="16,0,0,0" Content="{Binding Selected}">
<ContentControl Grid.Column="2" Content="{Binding Selected}">
<ContentControl.DataTemplates>
<DataTemplate DataType="vm:Workspace">
<Grid RowDefinitions="Auto,Auto,Auto,Auto">
<TextBlock Grid.Row="0" Text="{DynamicResource Text.ConfigureWorkspace.Name}"/>
<TextBox Grid.Row="1" Margin="-4,4,0,0" CornerRadius="3" Height="28" Width="256" Text="{Binding Name, Mode=TwoWay}"/>
<TextBox Grid.Row="1" Margin="0,4,0,0" CornerRadius="3" Height="28" Text="{Binding Name, Mode=TwoWay}"/>

<TextBlock Grid.Row="2" Margin="0,12,0,4" Text="{DynamicResource Text.ConfigureWorkspace.Color}"/>
<v:ColorPicker Grid.Row="3" HorizontalAlignment="Left" Value="{Binding Color, Mode=TwoWay}"/>
Expand Down
6 changes: 1 addition & 5 deletions src/Views/Launcher.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,7 @@ protected override void OnKeyUp(KeyEventArgs e)

protected override void OnClosing(WindowClosingEventArgs e)
{
var pref = ViewModels.Preference.Instance;
pref.Layout.LauncherWidth = Width;
pref.Layout.LauncherHeight = Height;
pref.Save();

(DataContext as ViewModels.Launcher)?.Quit(Width, Height);
base.OnClosing(e);
}

Expand Down

0 comments on commit beb7b54

Please sign in to comment.