Skip to content

Commit

Permalink
Add views and layouts, updates docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
emmabritton committed Apr 17, 2024
1 parent 0bb452d commit 4cb41c4
Show file tree
Hide file tree
Showing 31 changed files with 1,275 additions and 338 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

### Version 0.19.0

- BREAKING
- Change scenes param from `&[KeyCode]` to `&FxHashSet<KeyCode>`
- Remove view styles from dialog style
- Clicking a toggle button in a group will now automatically select it and unselect the others
- Add `Checkbox` view
- Add new options to `layout!`
- `[left|right|centerh]_to_[left|right|centerh]_of`
- `[top|bottom|centerv]_to_[top|bottom|centerv]_of`
- `align_centerv`, `align_centerh`
- Add `MenuBar::uncheck_all_children`
- Add feature `copypaste` which adds copying and pasting to `TextField`s

### Version 0.18.0

- BREAKING
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pixels-graphics-lib"
version = "0.18.0"
version = "0.19.0"
edition = "2021"
authors = ["Emma Britton <emmabritton@pm.me>"]
description = "Simple wrapper library around Pixels/Buffer Graphics"
Expand Down Expand Up @@ -29,15 +29,16 @@ pixels = "0.13.0"
winit = { version = "0.29.15", features = ["rwh_05"] }
winit_input_helper = { version = "0.16.0" }
thiserror = "1.0.58"
serde = { version = "1.0.197", features = ["derive"], optional = true }
serde = { version = "1.0.198", features = ["derive"], optional = true }
directories = { version = "5.0.1", optional = true }
buffer-graphics-lib = { version = "0.17.0", default-features = false }
buffer-graphics-lib = { version = "0.18.0", default-features = false }
rustc-hash = "1.1.0"
simple-game-utils = { version = "0.4.2", default-features = false }
log = "0.4.21"

[dev-dependencies]
fastrand = "2.0.2"
anyhow = "1.0.81"
anyhow = "1.0.82"

[[example]]
name = "test_dialogs"
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ with [Buffer Graphics Lib](https://github.com/emmabritton/buffer-graphics-lib)
In your `Cargo.toml` file add

```toml
pixels-graphics-lib = "0.18.0"
pixels-graphics-lib = "0.19.0"
winit_input_helper = "0.16.0" #only needed if you're not using `run()`
```

Expand Down Expand Up @@ -155,8 +155,12 @@ A few retro games

### [ICI Image editor](https://github.com/emmabritton/ici-image-editor)

Editor for `IndexedImage`
Editor for `IndexedImage`, ICI files

### [USFX Tester](https://github.com/emmabritton/uxfs-test)

Test GUI for [USFX](https://github.com/tversteeg/usfx)

### [Fontpad](https://github.com/emmabritton/fontpad)

Program used to create fonts for [Buffer graphics](https://github.com/emmabritton/buffer-graphics-lib)
2 changes: 1 addition & 1 deletion examples/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::rc::Rc;
use winit::keyboard::KeyCode;

/// This example shows how to load, display and alter an image
/// It also shows an example of how to do delta
/// It also shows an example of how to use delta
fn main() -> Result<()> {
let width = 300;
Expand Down
14 changes: 10 additions & 4 deletions examples/layout_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl LayoutTest {
}

impl Scene<SceneResult, SceneName> for LayoutTest {
fn render(&self, graphics: &mut Graphics, mouse: &MouseData, _: &[KeyCode]) {
fn render(&self, graphics: &mut Graphics, mouse: &MouseData, _: &FxHashSet<KeyCode>) {
graphics.clear(BLUE);
self.button.render(graphics, mouse);
self.toggle_button.render(graphics, mouse);
Expand All @@ -159,13 +159,19 @@ impl Scene<SceneResult, SceneName> for LayoutTest {
self.rightbottom.render(graphics, mouse);
}

fn on_key_up(&mut self, key: KeyCode, _: &MouseData, held: &[KeyCode]) {
fn on_key_up(&mut self, key: KeyCode, _: &MouseData, held: &FxHashSet<KeyCode>) {
self.text_field.on_key_press(key, held);
self.padding.on_key_press(key, held);
self.spacing.on_key_press(key, held);
}

fn on_mouse_click(&mut self, down_at: Coord, mouse: &MouseData, _: MouseButton, _: &[KeyCode]) {
fn on_mouse_click(
&mut self,
down_at: Coord,
mouse: &MouseData,
_: MouseButton,
_: &FxHashSet<KeyCode>,
) {
self.text_field.on_mouse_click(down_at, mouse.xy);
self.spacing.on_mouse_click(down_at, mouse.xy);
self.padding.on_mouse_click(down_at, mouse.xy);
Expand Down Expand Up @@ -211,7 +217,7 @@ impl Scene<SceneResult, SceneName> for LayoutTest {
&mut self,
timing: &Timing,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
) -> SceneUpdateResult<SceneResult, SceneName> {
self.text_field.update(timing);
self.spacing.update(timing);
Expand Down
14 changes: 10 additions & 4 deletions examples/menu_bar_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl MenuTest {
}

impl Scene<SceneResult, SceneName> for MenuTest {
fn render(&self, graphics: &mut Graphics, mouse: &MouseData, _: &[KeyCode]) {
fn render(&self, graphics: &mut Graphics, mouse: &MouseData, _: &FxHashSet<KeyCode>) {
graphics.clear(BLUE);
render!(graphics, mouse, self.menubar);

Expand All @@ -102,9 +102,15 @@ impl Scene<SceneResult, SceneName> for MenuTest {
);
}

fn on_key_up(&mut self, _: KeyCode, _: &MouseData, _: &[KeyCode]) {}
fn on_key_up(&mut self, _: KeyCode, _: &MouseData, _: &FxHashSet<KeyCode>) {}

fn on_mouse_click(&mut self, xy: Coord, mouse: &MouseData, button: MouseButton, _: &[KeyCode]) {
fn on_mouse_click(
&mut self,
xy: Coord,
mouse: &MouseData,
button: MouseButton,
_: &FxHashSet<KeyCode>,
) {
if button == MouseButton::Left {
if let Some(path) = self.menubar.on_mouse_click(xy, mouse.xy) {
println!("Clicked on {path:?} {:?}", self.menubar.label_for(path));
Expand All @@ -116,7 +122,7 @@ impl Scene<SceneResult, SceneName> for MenuTest {
&mut self,
_: &Timing,
mouse: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
) -> SceneUpdateResult<SceneResult, SceneName> {
self.menubar.on_mouse_move(mouse.xy);
Nothing
Expand Down
17 changes: 11 additions & 6 deletions examples/pre_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ impl WhiteTextScene {
}

impl Scene<SR, SN> for WhiteTextScene {
fn render(&self, graphics: &mut Graphics, _: &MouseData, _: &[KeyCode]) {
fn render(&self, graphics: &mut Graphics, _: &MouseData, _: &FxHashSet<KeyCode>) {
self.text.render(graphics);
}

fn update(&mut self, _: &Timing, _: &MouseData, _: &[KeyCode]) -> SceneUpdateResult<SR, SN> {
fn update(
&mut self,
_: &Timing,
_: &MouseData,
_: &FxHashSet<KeyCode>,
) -> SceneUpdateResult<SR, SN> {
Nothing
}
}
Expand All @@ -54,7 +59,7 @@ impl PrePost<SR, SN> for ExtrasImpl {
&mut self,
graphics: &mut Graphics,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &mut [Box<dyn Scene<SR, SN>>],
) {
graphics.clear(GB_0);
Expand All @@ -65,7 +70,7 @@ impl PrePost<SR, SN> for ExtrasImpl {
&mut self,
graphics: &mut Graphics,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &mut [Box<dyn Scene<SR, SN>>],
) {
graphics.draw_rect(Rect::new((10, 10), (90, 90)), stroke(GB_2));
Expand All @@ -77,7 +82,7 @@ impl PrePost<SR, SN> for ExtrasImpl {
&mut self,
_: &Timing,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &mut [Box<dyn Scene<SR, SN>>],
) {
}
Expand All @@ -86,7 +91,7 @@ impl PrePost<SR, SN> for ExtrasImpl {
&mut self,
timing: &Timing,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &mut [Box<dyn Scene<SR, SN>>],
) {
if self.timer.update(timing) {
Expand Down
18 changes: 12 additions & 6 deletions examples/pre_post_w_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ impl WhiteTextScene {
}

impl Scene<SR, SN> for WhiteTextScene {
fn render(&self, graphics: &mut Graphics, _: &MouseData, _: &[KeyCode], _: &GameController) {
fn render(
&self,
graphics: &mut Graphics,
_: &MouseData,
_: &FxHashSet<KeyCode>,
_: &GameController,
) {
self.text.render(graphics);
}

fn update(
&mut self,
_: &Timing,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &GameController,
) -> SceneUpdateResult<SR, SN> {
Nothing
Expand All @@ -60,7 +66,7 @@ impl PrePost<SR, SN> for ExtrasImpl {
&mut self,
graphics: &mut Graphics,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &mut [Box<dyn Scene<SR, SN>>],
_: &GameController,
) {
Expand All @@ -72,7 +78,7 @@ impl PrePost<SR, SN> for ExtrasImpl {
&mut self,
graphics: &mut Graphics,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &mut [Box<dyn Scene<SR, SN>>],
_: &GameController,
) {
Expand All @@ -85,7 +91,7 @@ impl PrePost<SR, SN> for ExtrasImpl {
&mut self,
_: &Timing,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &mut [Box<dyn Scene<SR, SN>>],
_: &GameController,
) {
Expand All @@ -95,7 +101,7 @@ impl PrePost<SR, SN> for ExtrasImpl {
&mut self,
timing: &Timing,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
_: &mut [Box<dyn Scene<SR, SN>>],
_: &GameController,
) {
Expand Down
8 changes: 4 additions & 4 deletions examples/relative_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl LayoutTest {
}

impl Scene<SceneResult, SceneName> for LayoutTest {
fn render(&self, graphics: &mut Graphics, mouse: &MouseData, _: &[KeyCode]) {
fn render(&self, graphics: &mut Graphics, mouse: &MouseData, _: &FxHashSet<KeyCode>) {
graphics.clear(BLUE);
render!(
graphics, mouse, self.mid, self.above, self.below, self.left, self.right, self.br,
Expand All @@ -196,15 +196,15 @@ impl Scene<SceneResult, SceneName> for LayoutTest {
);
}

fn on_key_up(&mut self, _: KeyCode, _: &MouseData, _: &[KeyCode]) {}
fn on_key_up(&mut self, _: KeyCode, _: &MouseData, _: &FxHashSet<KeyCode>) {}

fn on_mouse_click(&mut self, _: Coord, _: &MouseData, _: MouseButton, _: &[KeyCode]) {}
fn on_mouse_click(&mut self, _: Coord, _: &MouseData, _: MouseButton, _: &FxHashSet<KeyCode>) {}

fn update(
&mut self,
_: &Timing,
_: &MouseData,
_: &[KeyCode],
_: &FxHashSet<KeyCode>,
) -> SceneUpdateResult<SceneResult, SceneName> {
Nothing
}
Expand Down
Loading

0 comments on commit 4cb41c4

Please sign in to comment.