marble-machinations/src/config.rs

45 lines
1.1 KiB
Rust

use raylib::prelude::*;
use serde::{Deserialize, Serialize};
use crate::{input::Input, theme::FG_CHAPTER_TITLE, ui::text_button, util::Scroll, Globals};
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub input: Input,
#[serde(skip)]
scroll_offset: u32,
}
pub enum MenuReturn {
Stay,
StaySave,
ReturnSave,
ReturnCancel,
}
impl Config {
#[must_use]
pub fn draw_edit(&mut self, d: &mut RaylibDrawHandle, globals: &mut Globals) -> MenuReturn {
match globals.mouse.scroll() {
Some(Scroll::Down) => self.scroll_offset += 64,
Some(Scroll::Up) => self.scroll_offset = self.scroll_offset.saturating_sub(64),
None => (),
}
let y = -(self.scroll_offset as i32);
d.draw_text("Settings", 16, y + 16, 30, FG_CHAPTER_TITLE);
if text_button(d, &globals.mouse, 10, y + 60, 80, "apply") {
return MenuReturn::StaySave;
}
if text_button(d, &globals.mouse, 100, y + 60, 80, "done") {
return MenuReturn::ReturnSave;
}
if text_button(d, &globals.mouse, 190, y + 60, 80, "cancel") {
return MenuReturn::ReturnCancel;
}
self.input.draw_edit(d, globals, y);
MenuReturn::Stay
}
}