This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS, Android, UWP] Added padding to Button control #2426
Merged
rmarinho
merged 1 commit into
xamarin:master
from
paymicro:fix-gh1702-padding_on_buttons
May 14, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/GitHub1702.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Collections.Generic; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 1702, "[Enhancement] Padding on Buttons", PlatformAffected.All)] | ||
public class GitHub1702 : TestContentPage | ||
{ | ||
bool animation = false; | ||
|
||
protected override void Init() | ||
{ | ||
StackLayout layout = new StackLayout() | ||
{ | ||
Children = | ||
{ | ||
new Button() | ||
{ | ||
Image = "coffee.png", | ||
BackgroundColor = Color.GreenYellow, | ||
Text = "No padding? Height 100", | ||
HeightRequest = 100, | ||
}, | ||
new Button() | ||
{ | ||
Image = "coffee.png", | ||
BackgroundColor = Color.Green, | ||
Padding = new Thickness(100, 0, 0, 0), | ||
Text = "Do I have left padding? I should have left padding.", | ||
}, | ||
new Button() | ||
{ | ||
Image = "coffee.png", | ||
BackgroundColor = Color.LawnGreen, | ||
Padding = new Thickness(0, 30, 0, 0), | ||
Text = "Do I have top padding? I should have top padding." | ||
}, | ||
new Button() | ||
{ | ||
Image = "coffee.png", | ||
BackgroundColor = Color.LightGreen, | ||
Padding = new Thickness(0, 0, 100, 0), | ||
Text = "Do I have right padding? I should have right padding." | ||
}, | ||
new Button() | ||
{ | ||
Image = "coffee.png", | ||
BackgroundColor = Color.ForestGreen, | ||
Padding = new Thickness(0, 0, 0, 30), | ||
Text = "Do I have bottom padding? I should have bottom padding." | ||
} | ||
} | ||
}; | ||
|
||
var buttons = layout.Children.OfType<Button>(); | ||
layout.Children.Insert(0, ActionGrid(buttons.ToList())); | ||
PaddingAnimation(buttons).Start(); | ||
|
||
Content = layout; | ||
} | ||
|
||
Grid ActionGrid(List<Button> buttons) | ||
{ | ||
Button firstButton = buttons.FirstOrDefault(); | ||
Grid actionGrid = new Grid(); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "Reset text", | ||
Command = new Command(() => | ||
{ | ||
buttons.ForEach(b => b.Text = string.Empty); | ||
}) | ||
}, 0, 0); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "Reset padding", | ||
Command = new Command(() => | ||
{ | ||
buttons.ForEach(b => b.Padding = new Thickness(0, 0, 0, 0)); | ||
}) | ||
}, 0, 1); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "Set text", | ||
Command = new Command(() => | ||
{ | ||
buttons.ForEach(b => b.Text = "Some text"); | ||
}) | ||
}, 1, 0); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "Animation", | ||
Command = new Command(() => animation = !animation) | ||
}, 1, 1); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "Add Top", | ||
Command = new Command(() => | ||
{ | ||
var button = firstButton; | ||
button.Padding = new Thickness(0, button.Padding.Top + 10, 0, button.Padding.Bottom); | ||
if (!String.IsNullOrWhiteSpace(button.Text)) | ||
button.Text = $"Top: {button.Padding.Top} Bottom: {button.Padding.Bottom}"; | ||
}) | ||
}, 2, 0); | ||
actionGrid.AddChild(new Button() | ||
{ | ||
Text = "Add Bottom", | ||
Command = new Command(() => | ||
{ | ||
var button = firstButton; | ||
button.Padding = new Thickness(0, button.Padding.Top, 0, button.Padding.Bottom + 10); | ||
if (!String.IsNullOrWhiteSpace(button.Text)) | ||
button.Text = $"Top: {button.Padding.Top} Bottom: {button.Padding.Bottom}"; | ||
}) | ||
}, 2, 1); | ||
return actionGrid; | ||
} | ||
|
||
Thread PaddingAnimation(IEnumerable<Button> buttons) | ||
{ | ||
return new Thread(() => | ||
{ | ||
int increment = 1; | ||
int current = 0; | ||
int max = 15; | ||
int FPS = 30; | ||
int sleep = 1000 / FPS; | ||
|
||
while (true) | ||
{ | ||
Thread.Sleep(sleep); | ||
|
||
if (!animation) | ||
continue; | ||
|
||
current += increment; | ||
if (current > max || current < 0) | ||
{ | ||
increment *= -1; | ||
current += increment * 2; | ||
} | ||
|
||
Device.BeginInvokeOnMainThread(() => | ||
{ | ||
foreach (var button in buttons) | ||
{ | ||
var padding = button.Padding; | ||
button.Padding = padding = new Thickness( | ||
padding.Left + increment, | ||
padding.Top + increment, | ||
padding.Right + increment, | ||
padding.Bottom + increment); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,12 @@ protected override void Build (StackLayout stackLayout) | |
} | ||
); | ||
|
||
var paddingContainer = new ViewContainer<Button> (Test.Button.Padding, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to be added into the enum |
||
new Button { | ||
Text = "Padding", BackgroundColor = Color.Red, Padding = new Thickness (20, 30, 60, 15) | ||
} | ||
); | ||
|
||
Add (borderButtonContainer); | ||
Add (borderRadiusContainer); | ||
Add (borderWidthContainer); | ||
|
@@ -102,6 +108,7 @@ protected override void Build (StackLayout stackLayout) | |
Add (imageContainer); | ||
Add (textContainer); | ||
Add (textColorContainer); | ||
Add (paddingContainer); | ||
//stackLayout.Children.Add (textColorContainer); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,6 +227,7 @@ public enum Button | |
BorderColor, | ||
BorderRadius, | ||
Image, | ||
Padding | ||
} | ||
|
||
public enum VisualElement | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to Issue1702.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that in
Issue####
classes some othergithub
number is specified and different description.For example
Issue1461.cs
created almost 2 years agoXamarin.Forms/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1461.cs
Lines 30 to 31 in b794caf
And
Github1461.cs
created a couple of months agoXamarin.Forms/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github1461.cs
Lines 13 to 14 in b794caf
Github1461.cs
is correct for this repository #1461I was confused. Is renaming to
Issue####
still valid?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea :-/ Right now there's a mix of numbers that relate to the old github repo before the project went public. For now we're still just creating the Issues as Issue#### when there isn't a number collision