Skip to content

Commit

Permalink
Added a button to generate a random color (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Sep 15, 2021
1 parent 19b0b94 commit a3a4895
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ColorPicker/Pages/PalettePage.xaml
Expand Up @@ -19,7 +19,18 @@
</Grid.RowDefinitions>

<StackPanel Margin="10,40,10,5" Grid.Row="0">
<TextBlock Text="{x:Static lang:Resources.Palette}" Foreground="{Binding Source={StaticResource Foreground1}}" FontSize="16"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{x:Static lang:Resources.Palette}" Foreground="{Binding Source={StaticResource Foreground1}}" FontSize="16"/>
<Button Content="&#xF2F6;" Padding="5" x:Name="RandomColorBtn" Click="RandomColorBtn_Click" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Grid.Column="1" Style="{DynamicResource TabButtonStyle}" Background="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" FontSize="14" Margin="0,0,5,0">
<Button.ToolTip>
<ToolTip Content="{x:Static lang:Resources.PickRandomColor}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background1}}"/>
</Button.ToolTip>
</Button>
</Grid>
<StackPanel Orientation="Horizontal">
<Border x:Name="ColorDisplayer" CornerRadius="10" Margin="10" Grid.Column="0" Height="50" Width="50" HorizontalAlignment="Left"/>
<TextBlock Text="{x:Static lang:Resources.RGB}" VerticalAlignment="Center"/>
Expand Down
13 changes: 13 additions & 0 deletions ColorPicker/Pages/PalettePage.xaml.cs
Expand Up @@ -120,5 +120,18 @@ private void RGBTxt_TextChanged(object sender, TextChangedEventArgs e)

}
}

private void RandomColorBtn_Click(object sender, RoutedEventArgs e)
{
// Generate random color
int r, g, b;
Random random = new();

r = random.Next(0, 255); // Generate random number between 0 and 255
g = random.Next(0, 255); // Generate random number between 0 and 255
b = random.Next(0, 255); // Generate random number between 0 and 255

RGBTxt.Text = $"{r}{Global.Settings.RGBSeparator}{g}{Global.Settings.RGBSeparator}{b}"; // Set text
}
}
}

0 comments on commit a3a4895

Please sign in to comment.