Skip to content

Commit 474cb2e

Browse files
authored
Merge pull request #107 from rust3ds/improve/api
Improve general API
2 parents 855dc46 + 294284e commit 474cb2e

38 files changed

+477
-546
lines changed

ctru-rs/examples/audio-filters.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,23 @@ fn main() {
9999
hid.scan_input();
100100
let keys_down = hid.keys_down();
101101

102-
if keys_down.contains(KeyPad::KEY_START) {
102+
if keys_down.contains(KeyPad::START) {
103103
break;
104104
} // break in order to return to hbmenu
105105

106-
if keys_down.intersects(KeyPad::KEY_DOWN) {
106+
if keys_down.intersects(KeyPad::DOWN) {
107107
note = note.saturating_sub(1);
108-
} else if keys_down.intersects(KeyPad::KEY_UP) {
108+
} else if keys_down.intersects(KeyPad::UP) {
109109
note = std::cmp::min(note + 1, NOTEFREQ.len() - 1);
110110
}
111111

112112
let mut update_params = false;
113-
if keys_down.intersects(KeyPad::KEY_LEFT) {
113+
if keys_down.intersects(KeyPad::LEFT) {
114114
filter -= 1;
115115
filter = filter.rem_euclid(filter_names.len() as _);
116116

117117
update_params = true;
118-
} else if keys_down.intersects(KeyPad::KEY_RIGHT) {
118+
} else if keys_down.intersects(KeyPad::RIGHT) {
119119
filter += 1;
120120
filter = filter.rem_euclid(filter_names.len() as _);
121121

ctru-rs/examples/buttons.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ fn main() {
4242
// You can also use the .bits() method to do direct comparisons on
4343
// the underlying bits
4444

45-
if keys.contains(KeyPad::KEY_A) {
45+
if keys.contains(KeyPad::A) {
4646
println!("You held A!");
4747
}
48-
if keys.bits() & KeyPad::KEY_B.bits() != 0 {
48+
if keys.bits() & KeyPad::B.bits() != 0 {
4949
println!("You held B!");
5050
}
51-
if keys.contains(KeyPad::KEY_X | KeyPad::KEY_Y) {
51+
if keys.contains(KeyPad::X | KeyPad::Y) {
5252
println!("You held X and Y!");
5353
}
54-
if keys.intersects(KeyPad::KEY_L | KeyPad::KEY_R | KeyPad::KEY_ZL | KeyPad::KEY_ZR) {
54+
if keys.intersects(KeyPad::L | KeyPad::R | KeyPad::ZL | KeyPad::ZR) {
5555
println!("You held a shoulder button!");
5656
}
57-
if keys.intersects(KeyPad::KEY_START) {
57+
if keys.intersects(KeyPad::START) {
5858
println!("See ya!");
5959
break;
6060
}

ctru-rs/examples/camera-image.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use ctru::gfx::Screen;
21
use ctru::prelude::*;
3-
use ctru::services::cam::{Cam, CamOutputFormat, CamShutterSoundType, CamSize, Camera};
2+
use ctru::services::cam::{Cam, Camera, OutputFormat, ShutterSound, ViewSize};
3+
use ctru::services::gfx::Screen;
44
use ctru::services::gspgpu::FramebufferFormat;
55

66
use std::time::Duration;
@@ -37,10 +37,10 @@ fn main() {
3737
let camera = &mut cam.outer_right_cam;
3838

3939
camera
40-
.set_view_size(CamSize::CTR_TOP_LCD)
40+
.set_view_size(ViewSize::TopLCD)
4141
.expect("Failed to set camera size");
4242
camera
43-
.set_output_format(CamOutputFormat::RGB_565)
43+
.set_output_format(OutputFormat::Rgb565)
4444
.expect("Failed to set camera output format");
4545
camera
4646
.set_noise_filter(true)
@@ -65,11 +65,11 @@ fn main() {
6565
hid.scan_input();
6666
keys_down = hid.keys_down();
6767

68-
if keys_down.contains(KeyPad::KEY_START) {
68+
if keys_down.contains(KeyPad::START) {
6969
break;
7070
}
7171

72-
if keys_down.contains(KeyPad::KEY_R) {
72+
if keys_down.contains(KeyPad::R) {
7373
println!("Capturing new image");
7474

7575
let camera = &mut cam.outer_right_cam;
@@ -83,12 +83,12 @@ fn main() {
8383
)
8484
.expect("Failed to take picture");
8585

86-
cam.play_shutter_sound(CamShutterSoundType::NORMAL)
86+
cam.play_shutter_sound(ShutterSound::Normal)
8787
.expect("Failed to play shutter sound");
8888

8989
rotate_image_to_screen(
9090
&buf,
91-
gfx.top_screen.borrow_mut().get_raw_framebuffer().ptr,
91+
gfx.top_screen.borrow_mut().raw_framebuffer().ptr,
9292
WIDTH,
9393
HEIGHT,
9494
);

ctru-rs/examples/file-explorer.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
let gfx = Gfx::init().unwrap();
1717

1818
#[cfg(all(feature = "romfs", romfs_exists))]
19-
let _romfs = ctru::romfs::RomFS::init().unwrap();
19+
let _romfs = ctru::services::romfs::RomFS::init().unwrap();
2020

2121
FileExplorer::init(&apt, &hid, &gfx).run();
2222
}
@@ -56,15 +56,15 @@ impl<'a> FileExplorer<'a> {
5656
self.hid.scan_input();
5757
let input = self.hid.keys_down();
5858

59-
if input.contains(KeyPad::KEY_START) {
59+
if input.contains(KeyPad::START) {
6060
break;
61-
} else if input.contains(KeyPad::KEY_B) && self.path.components().count() > 1 {
61+
} else if input.contains(KeyPad::B) && self.path.components().count() > 1 {
6262
self.path.pop();
6363
self.console.clear();
6464
self.print_menu();
65-
} else if input.contains(KeyPad::KEY_A) {
65+
} else if input.contains(KeyPad::A) {
6666
self.get_input_and_run(Self::set_next_path);
67-
} else if input.contains(KeyPad::KEY_X) {
67+
} else if input.contains(KeyPad::X) {
6868
self.get_input_and_run(Self::set_exact_path);
6969
}
7070

@@ -147,11 +147,11 @@ impl<'a> FileExplorer<'a> {
147147
self.hid.scan_input();
148148
let input = self.hid.keys_down();
149149

150-
if input.contains(KeyPad::KEY_A) {
150+
if input.contains(KeyPad::A) {
151151
break;
152152
}
153153

154-
if input.contains(KeyPad::KEY_START) {
154+
if input.contains(KeyPad::START) {
155155
self.running = false;
156156
return;
157157
}
@@ -162,17 +162,16 @@ impl<'a> FileExplorer<'a> {
162162

163163
fn get_input_and_run(&mut self, action: impl FnOnce(&mut Self, String)) {
164164
let mut keyboard = Swkbd::default();
165-
let mut new_path_str = String::new();
166165

167-
match keyboard.get_utf8(&mut new_path_str) {
168-
Ok(Button::Right) => {
166+
match keyboard.get_string(2048) {
167+
Ok((path, Button::Right)) => {
169168
// Clicked "OK"
170-
action(self, new_path_str);
169+
action(self, path);
171170
}
172-
Ok(Button::Left) => {
171+
Ok((_, Button::Left)) => {
173172
// Clicked "Cancel"
174173
}
175-
Ok(Button::Middle) => {
174+
Ok((_, Button::Middle)) => {
176175
// This button wasn't shown
177176
unreachable!()
178177
}

ctru-rs/examples/gfx-3d-mode.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use ctru::gfx::{Screen, Side, TopScreen3D};
21
use ctru::prelude::*;
2+
use ctru::services::gfx::{Screen, Side, TopScreen3D};
33

44
/// See `graphics-bitmap.rs` for details on how the image is generated.
55
///
@@ -31,20 +31,20 @@ fn main() {
3131
//Scan all the inputs. This should be done once for each frame
3232
hid.scan_input();
3333

34-
if hid.keys_down().contains(KeyPad::KEY_START) {
34+
if hid.keys_down().contains(KeyPad::START) {
3535
break;
3636
}
3737

38-
let left_buf = left.get_raw_framebuffer();
39-
let right_buf = right.get_raw_framebuffer();
38+
let left_buf = left.raw_framebuffer();
39+
let right_buf = right.raw_framebuffer();
4040

4141
// Clear both buffers every time, in case the user switches sides this loop
4242
unsafe {
4343
left_buf.ptr.copy_from(ZERO.as_ptr(), ZERO.len());
4444
right_buf.ptr.copy_from(ZERO.as_ptr(), ZERO.len());
4545
}
4646

47-
if hid.keys_down().contains(KeyPad::KEY_A) {
47+
if hid.keys_down().contains(KeyPad::A) {
4848
// flip which buffer we're writing to
4949
current_side = match current_side {
5050
Side::Left => Side::Right,

ctru-rs/examples/gfx-wide-mode.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ fn main() {
1313
while apt.main_loop() {
1414
hid.scan_input();
1515

16-
if hid.keys_down().contains(KeyPad::KEY_START) {
16+
if hid.keys_down().contains(KeyPad::START) {
1717
break;
1818
}
1919

20-
if hid.keys_down().contains(KeyPad::KEY_A) {
20+
if hid.keys_down().contains(KeyPad::A) {
2121
drop(console);
2222

23-
let wide_mode = gfx.top_screen.borrow().get_wide_mode();
23+
let wide_mode = gfx.top_screen.borrow().is_wide();
2424
gfx.top_screen.borrow_mut().set_wide_mode(!wide_mode);
2525

2626
console = Console::init(gfx.top_screen.borrow_mut());

ctru-rs/examples/graphics-bitmap.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use ctru::gfx::Screen as _;
21
use ctru::prelude::*;
2+
use ctru::services::gfx::Screen;
33

44
/// Ferris image taken from <https://rustacean.net> and scaled down to 320x240px.
55
/// To regenerate the data, you will need to install `imagemagick` and run this
@@ -31,7 +31,7 @@ fn main() {
3131
bottom_screen.set_double_buffering(false);
3232

3333
// We assume the image is the correct size already, so we drop width + height.
34-
let frame_buffer = bottom_screen.get_raw_framebuffer();
34+
let frame_buffer = bottom_screen.raw_framebuffer();
3535

3636
// Copy the image into the frame buffer
3737
unsafe {
@@ -43,7 +43,7 @@ fn main() {
4343
//Scan all the inputs. This should be done once for each frame
4444
hid.scan_input();
4545

46-
if hid.keys_down().contains(KeyPad::KEY_START) {
46+
if hid.keys_down().contains(KeyPad::START) {
4747
break;
4848
}
4949

ctru-rs/examples/hashmaps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
gfx.wait_for_vblank();
2727

2828
hid.scan_input();
29-
if hid.keys_down().contains(KeyPad::KEY_START) {
29+
if hid.keys_down().contains(KeyPad::START) {
3030
break;
3131
}
3232
}

ctru-rs/examples/hello-both-screens.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() {
3232
gfx.wait_for_vblank();
3333

3434
hid.scan_input();
35-
if hid.keys_down().contains(KeyPad::KEY_START) {
35+
if hid.keys_down().contains(KeyPad::START) {
3636
break;
3737
}
3838
}

ctru-rs/examples/hello-world.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
//Scan all the inputs. This should be done once for each frame
2727
hid.scan_input();
2828

29-
if hid.keys_down().contains(KeyPad::KEY_START) {
29+
if hid.keys_down().contains(KeyPad::START) {
3030
break;
3131
}
3232
// Flush and swap framebuffers

ctru-rs/examples/linear-memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() {
3434
//Scan all the inputs. This should be done once for each frame
3535
hid.scan_input();
3636

37-
if hid.keys_down().contains(KeyPad::KEY_START) {
37+
if hid.keys_down().contains(KeyPad::START) {
3838
break;
3939
}
4040
// Flush and swap framebuffers

ctru-rs/examples/mii-selector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
//Scan all the inputs. This should be done once for each frame
3131
hid.scan_input();
3232

33-
if hid.keys_down().contains(KeyPad::KEY_START) {
33+
if hid.keys_down().contains(KeyPad::START) {
3434
break;
3535
}
3636
// Flush and swap framebuffers

ctru-rs/examples/network-sockets.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() {
6161
}
6262

6363
hid.scan_input();
64-
if hid.keys_down().contains(KeyPad::KEY_START) {
64+
if hid.keys_down().contains(KeyPad::START) {
6565
break;
6666
};
6767
}

ctru-rs/examples/output-3dslink.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
//Scan all the inputs. This should be done once for each frame
3131
hid.scan_input();
3232

33-
if hid.keys_down().contains(KeyPad::KEY_START) {
33+
if hid.keys_down().contains(KeyPad::START) {
3434
break;
3535
}
3636
// Flush and swap framebuffers

ctru-rs/examples/romfs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
// This never fails as `ctru-rs` examples inherit all of the `ctru` features,
1414
// but it might if a normal user application wasn't setup correctly
1515
if #[cfg(all(feature = "romfs", romfs_exists))] {
16-
let _romfs = ctru::romfs::RomFS::init().unwrap();
16+
let _romfs = ctru::services::romfs::RomFS::init().unwrap();
1717

1818
let f = std::fs::read_to_string("romfs:/test-file.txt").unwrap();
1919
println!("Contents of test-file.txt: \n{f}\n");
@@ -33,7 +33,7 @@ fn main() {
3333
//Scan all the inputs. This should be done once for each frame
3434
hid.scan_input();
3535

36-
if hid.keys_down().contains(KeyPad::KEY_START) {
36+
if hid.keys_down().contains(KeyPad::START) {
3737
break;
3838
}
3939
// Flush and swap framebuffers

ctru-rs/examples/software-keyboard.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,23 @@ fn main() {
1818

1919
hid.scan_input();
2020

21-
if hid.keys_down().contains(KeyPad::KEY_A) {
21+
if hid.keys_down().contains(KeyPad::A) {
2222
// Prepares a software keyboard with two buttons: One to cancel input and one
2323
// to accept it. You can also use `Swkbd::init()` to launch the keyboard in different
2424
// configurations.
2525
let mut keyboard = Swkbd::default();
2626

27-
// String used to store text received from the keyboard
28-
let mut text = String::new();
29-
3027
// Raise the software keyboard. You can perform different actions depending on which
3128
// software button the user pressed
32-
match keyboard.get_utf8(&mut text) {
33-
Ok(Button::Right) => println!("You entered: {text}"),
34-
Ok(Button::Left) => println!("Cancelled"),
35-
Ok(Button::Middle) => println!("How did you even press this?"),
29+
match keyboard.get_string(2048) {
30+
Ok((text, Button::Right)) => println!("You entered: {text}"),
31+
Ok((_, Button::Left)) => println!("Cancelled"),
32+
Ok((_, Button::Middle)) => println!("How did you even press this?"),
3633
Err(_) => println!("Oh noes, an error happened!"),
3734
}
3835
}
3936

40-
if hid.keys_down().contains(KeyPad::KEY_START) {
37+
if hid.keys_down().contains(KeyPad::START) {
4138
break;
4239
}
4340
}

ctru-rs/examples/system-configuration.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ fn main() {
1010
let cfgu = Cfgu::init().expect("Couldn't obtain CFGU controller");
1111
let _console = Console::init(gfx.top_screen.borrow_mut());
1212

13-
println!("\x1b[0;0HRegion: {:?}", cfgu.get_region().unwrap());
14-
println!("\x1b[10;0HLanguage: {:?}", cfgu.get_language().unwrap());
15-
println!("\x1b[20;0HModel: {:?}", cfgu.get_model().unwrap());
13+
println!("\x1b[0;0HRegion: {:?}", cfgu.region().unwrap());
14+
println!("\x1b[10;0HLanguage: {:?}", cfgu.language().unwrap());
15+
println!("\x1b[20;0HModel: {:?}", cfgu.model().unwrap());
1616

1717
// Main loop
1818
while apt.main_loop() {
1919
//Scan all the inputs. This should be done once for each frame
2020
hid.scan_input();
2121

22-
if hid.keys_down().contains(KeyPad::KEY_START) {
22+
if hid.keys_down().contains(KeyPad::START) {
2323
break;
2424
}
2525
// Flush and swap framebuffers

ctru-rs/examples/time-rtc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
// Scan all the inputs. This should be done once for each frame
1717
hid.scan_input();
1818

19-
if hid.keys_down().contains(KeyPad::KEY_START) {
19+
if hid.keys_down().contains(KeyPad::START) {
2020
break;
2121
}
2222

0 commit comments

Comments
 (0)