Don't let widgets have mutable access to show

Former-commit-id: 4c525c60d25bcc6551ddeabd325992fcd513619d
This commit is contained in:
timokoesters 2019-05-07 19:50:53 +02:00
parent 54cc96f0d1
commit b3ffc61119
3 changed files with 26 additions and 15 deletions

View File

@ -1,10 +1,10 @@
use conrod_core::{
color,
widget::{self, Text, Button, Image, Rectangle},
widget::{self, Button, Image, Rectangle, Text},
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
};
use super::{TEXT_COLOR, Show, font_ids::Fonts, img_ids::Imgs};
use super::{font_ids::Fonts, img_ids::Imgs, Show, TEXT_COLOR};
widget_ids! {
struct Ids {
@ -17,7 +17,7 @@ widget_ids! {
#[derive(WidgetCommon)]
pub struct MiniMap<'a> {
show: &'a mut Show,
show: &'a Show,
imgs: &'a Imgs,
fonts: &'a Fonts,
@ -27,7 +27,7 @@ pub struct MiniMap<'a> {
}
impl<'a> MiniMap<'a> {
pub fn new(show: &'a mut Show, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
Self {
show,
imgs,
@ -42,7 +42,7 @@ pub struct State {
}
pub enum Event {
Close,
Toggle,
}
impl<'a> Widget for MiniMap<'a> {
@ -99,7 +99,7 @@ impl<'a> Widget for MiniMap<'a> {
.set(state.ids.mmap_button, ui)
.was_clicked()
{
self.show.toggle_mini_map();
return Some(Event::Toggle);
}
// Title

View File

@ -1,12 +1,12 @@
mod bag;
mod buttons;
mod character_window;
mod minimap;
mod chat;
mod esc_menu;
mod font_ids;
mod img_ids;
mod map;
mod minimap;
mod settings_window;
mod skillbar;
mod small_window;
@ -14,12 +14,12 @@ mod small_window;
use bag::Bag;
use buttons::Buttons;
use character_window::CharacterWindow;
use minimap::MiniMap;
use chat::Chat;
use esc_menu::EscMenu;
use font_ids::Fonts;
use img_ids::Imgs;
use map::Map;
use minimap::MiniMap;
use settings_window::SettingsWindow;
use skillbar::Skillbar;
use small_window::{SmallWindow, SmallWindowType};
@ -320,7 +320,10 @@ impl Hud {
}
// MiniMap
MiniMap::new(&mut self.show, &self.imgs, &self.fonts).set(self.ids.minimap, ui_widgets);
match MiniMap::new(&self.show, &self.imgs, &self.fonts).set(self.ids.minimap, ui_widgets) {
Some(minimap::Event::Toggle) => self.show.toggle_mini_map(),
None => {}
}
// Bag contents
if self.show.bag {
@ -356,9 +359,14 @@ impl Hud {
// Settings
if let Windows::Settings = self.show.open_windows {
match SettingsWindow::new(&mut self.show, &self.imgs, &self.fonts)
match SettingsWindow::new(&self.show, &self.imgs, &self.fonts)
.set(self.ids.settings_window, ui_widgets)
{
Some(settings_window::Event::ToggleHelp) => self.show.toggle_help(),
Some(settings_window::Event::ToggleInventoryTestButton) => {
self.show.inventory_test_button = !self.show.inventory_test_button
}
Some(settings_window::Event::ToggleDebug) => self.show.debug = !self.show.debug,
Some(settings_window::Event::Close) => {
self.show.open_windows = Windows::None;
}

View File

@ -47,7 +47,7 @@ enum SettingsTab {
#[derive(WidgetCommon)]
pub struct SettingsWindow<'a> {
show: &'a mut Show,
show: &'a Show,
imgs: &'a Imgs,
fonts: &'a Fonts,
@ -57,7 +57,7 @@ pub struct SettingsWindow<'a> {
}
impl<'a> SettingsWindow<'a> {
pub fn new(show: &'a mut Show, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
Self {
show,
imgs,
@ -74,6 +74,9 @@ pub struct State {
}
pub enum Event {
ToggleHelp,
ToggleInventoryTestButton,
ToggleDebug,
Close,
}
@ -177,7 +180,7 @@ impl<'a> Widget for SettingsWindow<'a> {
.set(state.ids.button_help, ui);
if self.show.help != show_help {
self.show.toggle_help();
return Some(Event::ToggleHelp);
}
Text::new("Show Help")
@ -201,7 +204,7 @@ impl<'a> Widget for SettingsWindow<'a> {
.set(state.ids.inventory_test_button, ui);
if self.show.inventory_test_button != inventory_test_button {
self.show.inventory_test_button = inventory_test_button;
return Some(Event::ToggleInventoryTestButton);
}
Text::new("Show Inventory Test Button")
@ -222,7 +225,7 @@ impl<'a> Widget for SettingsWindow<'a> {
.set(state.ids.debug_button, ui);
if self.show.debug != show_debug {
self.show.debug = show_debug;
return Some(Event::ToggleDebug);
}
Text::new("Show Debug Window")