This commit is contained in:
Jon Lipsky 2019-07-11 23:19:18 -05:00
Родитель 1cbbc769cf
Коммит 75c999f5ad
7 изменённых файлов: 62 добавлений и 46 удалений

Просмотреть файл

@ -42,18 +42,15 @@ namespace HotUI.Samples
{ {
(state.CanEdit (state.CanEdit
? (View) new TextField(() => state.Text, onCommit: value => state.Text = value) ? (View) new TextField(() => state.Text, onCommit: value => state.Text = value)
: new Text(() => $"{state.Text}: multiText")), // Fromated Text will warn you. This should be done by TextBinding : new Text(() => $"{state.Text}: multiText")), // Text will warn you. This should be done by TextBinding
new Text(state.Text), new Text(state.Text),
new HStack new HStack
{ {
new Button("Toggle Entry/Label") new Button("Toggle Entry/Label",
{ () => state.CanEdit = !state.CanEdit)
OnClick = () => state.CanEdit = !state.CanEdit .Background(Color.Salmon),
}.Background(Color.Salmon), new Button("Update Text",
new Button("Update Text") () => state.Text = $"Click Count: {clickCount.Value++}" )
{
OnClick = () => { state.Text = $"Click Count: {clickCount.Value++}"; }
}
} }
}; };
} }

Просмотреть файл

@ -40,24 +40,18 @@ namespace HotUI.Samples {
new Text(state.Text), new Text(state.Text),
new HStack new HStack
{ {
new Button("Toggle Entry/Label") new Button("Toggle Entry/Label",
{ () => state.CanEdit = !state.CanEdit),
OnClick = () => state.CanEdit = !state.CanEdit new Button("Update Text",
}, () => state.Text = $"Click Count: {clickCount.Value++}"),
new Button("Update Text") new Button("Update FontSize",
{ () => {
OnClick = () => { state.Text = $"Click Count: {clickCount.Value++}"; }
},
new Button("Update FontSize")
{
OnClick = () => {
var font = View.GetGlobalEnvironment<Font>(EnvironmentKeys.Fonts.Font) ?? Font.System(14); var font = View.GetGlobalEnvironment<Font>(EnvironmentKeys.Fonts.Font) ?? Font.System(14);
var size = font.Attributes.Size + 5; var size = font.Attributes.Size + 5;
var newFont = Font.System(size); var newFont = Font.System(size);
View.SetGlobalEnvironment (EnvironmentKeys.Fonts.Font, newFont); View.SetGlobalEnvironment (EnvironmentKeys.Fonts.Font, newFont);
} }),
},
}, },
new Toggle(() =>state.CanEdit) new Toggle(() =>state.CanEdit)
{ {

Просмотреть файл

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
namespace HotUI.Samples
{
public class ButtonSample1 : View
{
readonly State<int> count = 0;
public ButtonSample1()
{
Body = () => new VStack
{
new Button("Increment Value", () => count.Value = count + 1),
new Text($"Value: {count.Value}"),
};
}
}
}

Просмотреть файл

@ -7,9 +7,9 @@ namespace HotUI.Samples {
{ {
Body = () => { Body = () => {
var stack = new VStack { var stack = new VStack {
new Button (()=> myBoolean.Value ? myText.Value : $"State: {myBoolean.Value}") { new Button
OnClick = ()=> myBoolean.Value = !myBoolean.Value, (()=> myBoolean.Value ? myText.Value : $"State: {myBoolean.Value}",
}, ()=> myBoolean.Value = !myBoolean.Value),
}; };
for (var i = 0; i < 100; i++) { for (var i = 0; i < 100; i++) {
stack.Add (new Text (i.ToString ())); stack.Add (new Text (i.ToString ()));

Просмотреть файл

@ -25,6 +25,7 @@ namespace HotUI.Samples {
new MenuItem("ListPage1", ()=> new ListPage()), new MenuItem("ListPage1", ()=> new ListPage()),
new MenuItem("ListPage2", ()=> new ListPage2()), new MenuItem("ListPage2", ()=> new ListPage2()),
new MenuItem("Insane Diff", ()=> new InsaneDiffPage()), new MenuItem("Insane Diff", ()=> new InsaneDiffPage()),
new MenuItem("ButtonSample1", ()=> new ButtonSample1()),
new MenuItem("SecureFieldSample1", ()=> new SecureFieldSample1()), new MenuItem("SecureFieldSample1", ()=> new SecureFieldSample1()),
new MenuItem("SecureFieldSample2", ()=> new SecureFieldSample2()), new MenuItem("SecureFieldSample2", ()=> new SecureFieldSample2()),
new MenuItem("SecureFieldSample3", ()=> new SecureFieldSample3()), new MenuItem("SecureFieldSample3", ()=> new SecureFieldSample3()),

Просмотреть файл

@ -1,25 +1,33 @@
using System; using System;
namespace HotUI {
public class Button : View { namespace HotUI
{
public class Button : View
{
public Button () public Button ()
{ {
} }
public Button (string text) : base (true)
public Button (string text, Action action = null) : base (true)
{ {
Text = text; Text = text;
OnClick = action;
} }
public Button (Func<string> formatedText)
public Button (Func<string> text, Action action = null)
{ {
TextBinding = formatedText; TextBinding = text;
OnClick = action;
} }
private string text;
private string _text;
public string Text { public string Text {
get => text; get => _text;
private set => this.SetValue (State, ref text, value, ViewPropertyChanged); private set => this.SetValue (State, ref _text, value, ViewPropertyChanged);
} }
public Action OnClick { get; set; } public Action OnClick { get; private set; }
public Func<string> TextBinding { get; private set; } public Func<string> TextBinding { get; private set; }
@ -37,6 +45,5 @@ namespace HotUI {
Text = text; Text = text;
} }
} }
} }
} }

Просмотреть файл

@ -1,23 +1,21 @@
using System; using System;
namespace HotUI { namespace HotUI
public class NavigationButton : ContentView { {
public class NavigationButton : ContentView
{
public NavigationButton(Func<View> destination) public NavigationButton(Func<View> destination)
{ {
Destination = destination; Destination = destination;
} }
public NavigationButton (Func<string> text,Func<View> destination) public NavigationButton (Func<string> text,Func<View> destination)
{ {
Content = new Button (text) { Content = new Button (text, Navigate);
OnClick = Navigate,
};
Destination = destination; Destination = destination;
} }
public NavigationButton (string text, Func<View> destination) public NavigationButton (string text, Func<View> destination)
{ {
Content = new Button (text) { Content = new Button (text,Navigate);
OnClick = Navigate,
};
Destination = destination; Destination = destination;
} }