}
fn handle_page_switch(cursor:[f64;2],current_page:PagId)->Option{
let x=cursor[0];
let y=cursor[1];
code
Assistant
User
warning: fields buffer and indices are never read
--> src\graphics\internal_canvas.rs:689:9
|
688 | pub struct InstanceArrayView {
| ----------------- fields in this struct
689 | pub buffer: ArcBuffer,
| ^^^^^^
690 | pub indices: ArcBuffer,
| ^^^^^^^
|
= note: has a derived impl for the trait , but this is intentionally ignored during dead code analysis
= note: on by default
Assistant
if x>=5.0 && x<=50.0 {
for (i,page) in [PagId::Main,PagId::Second,PagId::Third].iter().enumerate(){
let y_start=50.0+i as f64 *30.0;
if y>=y_start && y<=y_start+28.0 && *page != current_page{
return Some(StateCommand::SwitchPage(*page));
}
}
}
None
}
//===================工具函數==================
fn draw_page_centered(
text_str:&str,
c:Context,
g:&mut G2d,
glyphs:&mut Glyphs,
y:f64,
){
use graphics::Transformed;
let font_size=48;
let width=glyphs.width(font_size, text_str).unwrap_or(0.0);
let x=320.0-width/2.0;
let transform=c.transform.trans(x, y);
let text_obj=graphics::text::Text::new_color([0.0,0.0,0.0,1.0], font_size);
text_obj.draw(text_str, glyphs,&graphics::DrawState::default(), transform, g).unwrap();
}
fn draw_page_numbers(c:Context,g:&mut G2d,glyphs:&mut Glyphs,current:PagId){
let pages=[
(PagId::Main,"主頁"),
(PagId::Second,"第二頁"),
(PagId::Third,"第三頁"),
];
for (i,(id,name)) in pages.iter().enumerate(){
let y=5.0 + i as f64 *30.0;
let color =if *id==current{
[1.0;4]
} else {
[0.0,0.0,0.0,1.0]
};
code
let text_obj=graphics::text::Text::new_color(color, 24);
text_obj.draw(name, glyphs, &graphics::DrawState::default(), c.transform.trans(5.0, y+20.0), g).unwrap();
}
}
fn main(){
let mut window22:PistonWindow=WindowSettings::new("title", [640,480]).exit_on_esc(true).build().unwrap();
let assets=find_folder::Search::ParentsThenKids(3, 3).for_folder("assets").expect("找不到資料夾");
let font_path=assets.join("mingliu.ttc");
let mut glyphs=window22.load_font(assets).expect("找不到字形");
let mut state_stack=StateStack::new(Box::new(MainPage::new()));
let mut cursor_pos:Option<[f64;2]>=None;
while let Some(event) = window22.next() {
if let Some(pos)=event.mouse_cursor_args(){
cursor_pos=Some(pos);
}
if let Some(button)=event.press_args(){
state_stack.input(button);
}
if let Some(button_args)=event.button_args(){
if let Button::Mouse(mouse_button)=button_args.button{
if let Some(cursor)=cursor_pos{
state_stack.mouse_input(cursor, mouse_button);
}
}
}
if let Some(args) = event.update_args() {
state_stack.update(&args);
}
window22.draw_2d(&event, |c,g,device|{
code
glyphs.factory.encoder.flush(device);
});
if state_stack.is_empty(){
break;
}
}
warning: method append is never used
--> src\vfs.rs:112:8
|
97 | pub trait VFS: Debug {
| --- method in this trait
...
112 | fn append(&self, path: &Path) -> GameResult<Box> {
| ^^^^^^
warning: method len is never used
--> src\vfs.rs:149:8
|
140 | pub trait VMetadata {
| --------- method in this trait
...
149 | fn len(&self) -> u64;
| ^^^
warning: ggez (lib) generated 3 warnings
Compiling ggez v0.9.3 (D:\ggez-master\ggez-master)
error[E0659]: graphics is ambiguous
--> examples\1_01_super_simple.rs:466:9
|
466 | use graphics::Transformed;
| ^^^^^^^^ ambiguous name
|
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
= note: graphics could refer to a crate passed with --extern
= help: use ::graphics to refer to this crate unambiguously
note: graphics could also refer to the crate imported here
--> examples\1_01_super_simple.rs:1:5
|
1 | use piston_window::*;
| ^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of graphics to disambiguate
= help: or use crate::graphics to refer to this crate unambiguously
warning: unused variable: cursor
--> examples\1_01_super_simple.rs:25:31
|
25 | fn mouse_input(&mut self, cursor: [f64; 2], button: MouseButton) -> Option<State...
| ^^^^^^ help: if this is intentional, prefix it with an underscore: _cursor
|
= note: #[warn(unused_variables)] on by default
warning: unused variable: button
--> examples\1_01_super_simple.rs:25:49
|
25 | ...&mut self, cursor: [f64; 2], button: MouseButton) -> Option {
| ^^^^^^ help: if this is intentional, prefix it with an underscore: _button
For more information about this error, try rustc --explain E0659.
warning: ggez (example "1_01_super_simple") generated 2 warnings
error: could not compile ggez (example "1_01_super_simple") due to 1 previous error; 2 warnings emitted
您遇到的錯誤與警告主要是:
1. error[E0659]: graphics is ambiguous
code
466 | use graphics::Transformed;
| ^^^^^^^^ ambiguous name
...
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
= note: `graphics` could refer to a crate passed with `--extern`
= help: use `::graphics` to refer to this crate unambiguously
note: `graphics` could also refer to the crate imported here
1 | use piston_window::*;
| ^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `graphics` to disambiguate
= help: or use `crate::graphics` to refer to this crate unambiguously
這是一個因在 examples/1_01_super_simple.rs 檔案中使用了
rust
use piston_window::*;
導致名稱衝突(graphics 既可能是外部套件,也可能是子模組名稱)。
解決方式:
方式一:用絕對路徑明確指明
把
rust
use graphics::Transformed;
改成
rust
use ::graphics::Transformed;
或
rust
use crate::graphics::Transformed;
方式二:改成特定引入
如果是從 piston_window 引入的,你可以改用:
rust
use piston_window::graphics::Transformed;
確保引入的是正確的 graphics。
方式三:不要使用 glob (*) 引入
避免用 use piston_window::*; 改用精確引入需要使用的項目,降低衝突。
2. 警告:unused variable
code
warning: unused variable: `cursor`
--> examples\1_01_super_simple.rs:25:31
|
25 | fn mouse_input(&mut self, cursor: [f64; 2], button: MouseButton) -> Option<StateCommand> {
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_cursor`