Skip to content

Commit

Permalink
Clean up examples
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Nov 20, 2024
1 parent 8699367 commit 05f4b22
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/yakui/examples/autofocus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use yakui::widgets::{Pad, TextBox};
use yakui::{center, use_state};

pub fn run() {
let text = use_state(|| String::new());
let text = use_state(String::new);
let autofocus = use_state(|| false);

center(|| {
let mut box1 = TextBox::new("".to_owned());
let mut box1 = TextBox::new(text.borrow().clone());
box1.style.font_size = 60.0;
box1.padding = Pad::all(50.0);
box1.placeholder = "placeholder".into();
Expand Down
10 changes: 2 additions & 8 deletions crates/yakui/examples/clear_textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ use yakui::{button, column, textbox, use_state};

fn run() {
column(|| {
let text = use_state(String::new);
let clear = use_state(|| false);

if clear.get() {
text.borrow_mut().clear();
clear.set(false);
}
let text = use_state(|| String::from("Hello"));

let res = textbox(text.borrow().clone());
if let Some(new_text) = res.into_inner().text {
text.set(new_text);
}

if button("Clear").clicked {
clear.set(true);
text.borrow_mut().clear();
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions crates/yakui/examples/custom_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ use yakui::{column, text, Color};

pub fn run() {
column(|| {
// The default font for text is the application-wide "sans-serif" font.
text(32.0, "Default Font");

// Fonts can be named by their type, like sans-serif or monospace
let mut text = Text::new(32.0, "Custom Font");
text.style.attrs.family_owned = FamilyOwned::Monospace;
text.style.color = Color::GREEN;
text.show();

// ...or you can name the font family directly
let mut text = Text::new(32.0, "Custom Font (by name)");
text.style.attrs.family_owned = FamilyOwned::Name("Hack".to_owned());
text.style.color = Color::GREEN;
text.show();
});
}

Expand Down
4 changes: 2 additions & 2 deletions crates/yakui/examples/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use yakui::{button, checkbox, label, pad, row, slider, textbox, use_state};

pub fn run() {
let checked = use_state(|| false);
let name = use_state(|| String::new());
let name = use_state(|| String::from("Hello"));
let step_size = use_state(|| 0.0);
let sliding = use_state(|| 50.0);

Expand All @@ -18,7 +18,7 @@ pub fn run() {
let res = checkbox(checked.get());
checked.set(res.checked);

let res = textbox("Hello");
let res = textbox(name.borrow().clone());
if let Some(new_text) = res.into_inner().text {
name.set(new_text);
}
Expand Down

0 comments on commit 05f4b22

Please sign in to comment.