Skip to content

Commit

Permalink
fixed cargo.lock issue with rustix, removed duplicate methods from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
togglebyte committed Nov 14, 2023
2 parents fd362c7 + cc7d4ba commit bb5a0a2
Show file tree
Hide file tree
Showing 46 changed files with 5,473 additions and 1,332 deletions.
383 changes: 381 additions & 2 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[workspace]

[package]
name = "gooey"
version = "0.1.0"
Expand All @@ -16,8 +18,14 @@ interner = "0.2.1"
kempt = "0.2.1"
intentional = "0.1.0"
tracing = "0.1.40"
rustix = "=0.38.21"

tracing-subscriber = { version = "0.3", optional = true }
tracing-subscriber = { version = "0.3", optional = true, features = [
"env-filter",
] }
palette = "0.7.3"
ahash = "0.8.6"
gooey-macros = { version = "0.1.0", path = "gooey-macros" }


# [patch."https://github.com/khonsulabs/kludgine"]
Expand All @@ -35,3 +43,6 @@ opt-level = 2

[dev-dependencies]
pollster = "0.3.0"

[profile.release]
debug = true
17 changes: 14 additions & 3 deletions examples/button.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
use gooey::value::Dynamic;
use gooey::widget::MakeWidget;
use gooey::widgets::button::ButtonOutline;
use gooey::widgets::Button;
use gooey::Run;
use kludgine::Color;

// begin rustme snippet: readme
fn main() -> gooey::Result {
// begin rustme snippet: readme
// Create a dynamic usize.
let count = Dynamic::new(0_usize);
let count = Dynamic::new(0_isize);

// Create a new button with a label that is produced by mapping the contents
// of `count`.
Button::new(count.map_each(ToString::to_string))
// Set the `on_click` callback to a closure that increments the counter.
.on_click(count.with_clone(|count| move |_| count.set(count.get() + 1)))
.and(
// Creates a second, outlined button
Button::new(count.map_each(ToString::to_string))
// Set the `on_click` callback to a closure that decrements the counter.
.on_click(count.with_clone(|count| move |_| count.set(count.get() - 1)))
.with(&ButtonOutline, Color::DARKRED),
)
.into_columns()
// Run the button as an an application.
.run()
// end rustme snippet
}
// end rustme snippet
6 changes: 3 additions & 3 deletions examples/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ fn main() -> gooey::Result<()> {
Canvas::new(move |context| {
angle += Angle::degrees(1);

let center = Point::from(context.graphics.size()).into_signed() / 2;
context.graphics.draw_text(
let center = Point::from(context.gfx.size()).into_signed() / 2;
context.gfx.draw_text(
Text::new("Canvas exposes the full power of Kludgine", Color::WHITE)
.origin(TextOrigin::Center),
center - Point::new(Px(0), Px(100)),
None,
None,
);
context.graphics.draw_shape(
context.gfx.draw_shape(
&Shape::filled_rect(
Rect::new(Point::new(Px(-50), Px(-50)), Size::new(Px(100), Px(100))),
Color::RED,
Expand Down
46 changes: 46 additions & 0 deletions examples/containers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use gooey::value::Dynamic;
use gooey::widget::{MakeWidget, WidgetInstance};
use gooey::widgets::{Button, Label};
use gooey::window::ThemeMode;
use gooey::Run;

fn main() -> gooey::Result {
let theme_mode = Dynamic::default();
set_of_containers(1, theme_mode.clone())
.centered()
.into_window()
.with_theme_mode(theme_mode)
.run()
}

fn set_of_containers(repeat: usize, theme_mode: Dynamic<ThemeMode>) -> WidgetInstance {
let inner = if let Some(remaining_iters) = repeat.checked_sub(1) {
set_of_containers(remaining_iters, theme_mode)
} else {
Button::new("Toggle Theme Mode")
.on_click(move |_| {
theme_mode.map_mut(|mode| mode.toggle());
})
.make_widget()
};
Label::new("Lowest")
.and(
Label::new("Low")
.and(
Label::new("Mid")
.and(
Label::new("High")
.and(Label::new("Highest").and(inner).into_rows().contain())
.into_rows()
.contain(),
)
.into_rows()
.contain(),
)
.into_rows()
.contain(),
)
.into_rows()
.contain()
.make_widget()
}
35 changes: 18 additions & 17 deletions examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ use std::string::ToString;

use gooey::value::Dynamic;
use gooey::widget::MakeWidget;
use gooey::widgets::{Button, Label, Resize, Stack};
use gooey::widgets::{Button, Label};
use gooey::Run;
use kludgine::figures::units::Lp;

fn main() -> gooey::Result {
let counter = Dynamic::new(0i32);
let label = counter.map_each(ToString::to_string);
Stack::columns(
Resize::width(Lp::points(100), Label::new(label))
.and(Button::new("+").on_click(counter.with_clone(|counter| {
move |_| {
counter.set(counter.get() + 1);
}
})))
.and(Button::new("-").on_click(counter.with_clone(|counter| {
move |_| {
counter.set(counter.get() - 1);
}
}))),
)
.centered()
.expand()
.run()

Label::new(label)
.width(Lp::points(100))
.and(Button::new("+").on_click(counter.with_clone(|counter| {
move |_| {
*counter.lock() += 1;
}
})))
.and(Button::new("-").on_click(counter.with_clone(|counter| {
move |_| {
*counter.lock() -= 1;
}
})))
.into_columns()
.centered()
.expand()
.run()
}
34 changes: 11 additions & 23 deletions examples/gameui.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
use gooey::value::Dynamic;
use gooey::widget::{MakeWidget, HANDLED, IGNORED};
use gooey::widgets::{Canvas, Input, Label, Stack};
use gooey::widgets::{Input, Label, Space};
use gooey::Run;
use kludgine::app::winit::event::ElementState;
use kludgine::app::winit::keyboard::Key;
use kludgine::figures::{Point, Rect};
use kludgine::shapes::Shape;
use kludgine::Color;

fn main() -> gooey::Result {
let chat_log = Dynamic::new("Chat log goes here.\n".repeat(100));
let chat_message = Dynamic::new(String::new());

Stack::rows(
Stack::columns(
Label::new(chat_log.clone()).vertical_scroll().expand().and(
Canvas::new(|context| {
let entire_canvas = Rect::from(context.graphics.size());
context.graphics.draw_shape(
&Shape::filled_rect(entire_canvas, Color::RED),
Point::default(),
None,
None,
);
})
.expand_weighted(2),
),
)
Label::new(chat_log.clone())
.vertical_scroll()
.expand()
.and(Space::colored(Color::RED).expand_weighted(2))
.into_columns()
.expand()
.and(Input::new(chat_message.clone()).on_key(move |input| {
match (input.state, input.logical_key) {
(ElementState::Pressed, Key::Enter) => {
let new_message = chat_message.map_mut(|text| std::mem::take(text));
let new_message = chat_message.map_mut(std::mem::take);
chat_log.map_mut(|chat_log| {
chat_log.push_str(&new_message);
chat_log.push('\n');
Expand All @@ -40,8 +28,8 @@ fn main() -> gooey::Result {
}
_ => IGNORED,
}
})),
)
.expand()
.run()
}))
.into_rows()
.expand()
.run()
}
87 changes: 42 additions & 45 deletions examples/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::process::exit;

use gooey::value::{Dynamic, MapEach};
use gooey::widget::MakeWidget;
use gooey::widgets::{Button, Expand, Input, Label, Resize, Stack};
use gooey::widgets::{Button, Expand, Input, Label};
use gooey::Run;
use kludgine::figures::units::Lp;

Expand All @@ -13,50 +13,47 @@ fn main() -> gooey::Result {
let valid =
(&username, &password).map_each(|(username, password)| validate(username, password));

Resize::width(
// TODO We need a min/max range for the Resize widget
Lp::points(400),
Stack::rows(
Stack::columns(
Label::new("Username").and(
Input::new(username.clone())
.centered()
.fit_horizontally()
.expand(),
),
)
.and(Stack::columns(
Label::new("Password").and(
// TODO secure input
Input::new(password.clone())
.centered()
.fit_horizontally()
.expand(),
),
))
.and(Stack::columns(
Button::new("Cancel")
.on_click(|_| {
eprintln!("Login cancelled");
exit(0)
})
.into_escape()
.and(Expand::empty())
.and(
Button::new("Log In")
.enabled(valid)
.on_click(move |_| {
println!("Welcome, {}", username.get());
exit(0);
})
.into_default(),
),
)),
),
)
.centered()
.expand()
.run()
// TODO this should be a grid layout to ensure proper visual alignment.
let username_row = Label::new("Username")
.and(Input::new(username.clone()).expand())
.into_columns();

let password_row = Label::new("Password")
.and(
// TODO secure input
Input::new(password.clone()).expand(),
)
.into_columns();

let buttons = Button::new("Cancel")
.on_click(|_| {
eprintln!("Login cancelled");
exit(0)
})
.into_escape()
.and(Expand::empty())
.and(
Button::new("Log In")
.enabled(valid)
.on_click(move |_| {
println!("Welcome, {}", username.get());
exit(0);
})
.into_default(),
)
.into_columns();

username_row
.pad()
.and(password_row.pad())
.and(buttons.pad())
.into_rows()
.contain()
.width(Lp::points(300)..Lp::points(600))
.scroll()
.centered()
.expand()
.run()
}

fn validate(username: &String, password: &String) -> bool {
Expand Down
1 change: 1 addition & 0 deletions examples/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ use gooey::Run;
fn main() -> gooey::Result {
Label::new(include_str!("../src/widgets/scroll.rs"))
.scroll()
.expand()
.run()
}
11 changes: 5 additions & 6 deletions examples/style.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use gooey::styles::components::TextColor;
use gooey::styles::Styles;
use gooey::widget::{MakeWidget, Widget};
use gooey::widget::MakeWidget;
use gooey::widgets::stack::Stack;
use gooey::widgets::{Button, Style};
use gooey::{styles, Run};
use gooey::Run;
use kludgine::Color;

fn main() -> gooey::Result {
Stack::rows(Button::new("Green").and(red_text(Button::new("Red"))))
.with_styles(Styles::new().with(&TextColor, Color::GREEN))
.with(&TextColor, Color::GREEN)
.run()
}

/// Creating reusable style helpers that work with any Widget is straightfoward
fn red_text(w: impl Widget) -> Style {
Style::new(styles!(TextColor => Color::RED), w)
fn red_text(w: impl MakeWidget) -> Style {
w.with(&TextColor, Color::RED)
}
Loading

0 comments on commit bb5a0a2

Please sign in to comment.