veloren_voxygen/hud/settings_window/
accessibility.rs1use crate::{
2 GlobalState,
3 hud::{TEXT_COLOR, img_ids::Imgs},
4 render::RenderMode,
5 session::settings_change::{Accessibility as AccessibilityChange, Accessibility::*},
6 ui::{ToggleButton, fonts::Fonts},
7};
8use conrod_core::{
9 Colorable, Positionable, Sizeable, Widget, WidgetCommon, color,
10 widget::{self, Rectangle, Text},
11 widget_ids,
12};
13use i18n::Localization;
14
15widget_ids! {
16 struct Ids {
17 window,
18 window_r,
19 flashing_lights_button,
20 flashing_lights_label,
21 flashing_lights_info_label,
22 subtitles_button,
23 subtitles_label,
24 }
25}
26
27#[derive(WidgetCommon)]
28pub struct Accessibility<'a> {
29 global_state: &'a GlobalState,
30 imgs: &'a Imgs,
31 fonts: &'a Fonts,
32 localized_strings: &'a Localization,
33 #[conrod(common_builder)]
34 common: widget::CommonBuilder,
35}
36impl<'a> Accessibility<'a> {
37 pub fn new(
38 global_state: &'a GlobalState,
39 imgs: &'a Imgs,
40 fonts: &'a Fonts,
41 localized_strings: &'a Localization,
42 ) -> Self {
43 Self {
44 global_state,
45 imgs,
46 fonts,
47 localized_strings,
48 common: widget::CommonBuilder::default(),
49 }
50 }
51}
52
53pub struct State {
54 ids: Ids,
55}
56
57impl Widget for Accessibility<'_> {
58 type Event = Vec<AccessibilityChange>;
59 type State = State;
60 type Style = ();
61
62 fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
63 State {
64 ids: Ids::new(id_gen),
65 }
66 }
67
68 fn style(&self) -> Self::Style {}
69
70 fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
71 common_base::prof_span!("Accessibility::update");
72 let widget::UpdateArgs { state, ui, .. } = args;
73
74 let mut events = Vec::new();
75
76 Rectangle::fill_with(args.rect.dim(), color::TRANSPARENT)
77 .xy(args.rect.xy())
78 .graphics_for(args.id)
79 .scroll_kids()
80 .scroll_kids_vertically()
81 .set(state.ids.window, ui);
82 Rectangle::fill_with([args.rect.w() / 2.0, args.rect.h()], color::TRANSPARENT)
83 .top_right()
84 .parent(state.ids.window)
85 .set(state.ids.window_r, ui);
86
87 let render_mode = &self.global_state.settings.graphics.render_mode;
89
90 Text::new(
92 &self
93 .localized_strings
94 .get_msg("hud-settings-flashing_lights"),
95 )
96 .font_size(self.fonts.cyri.scale(14))
97 .font_id(self.fonts.cyri.conrod_id)
98 .top_left_with_margins_on(state.ids.window, 10.0, 10.0)
99 .color(TEXT_COLOR)
100 .set(state.ids.flashing_lights_label, ui);
101
102 let flashing_lights_enabled = ToggleButton::new(
103 render_mode.flashing_lights_enabled,
104 self.imgs.checkbox,
105 self.imgs.checkbox_checked,
106 )
107 .w_h(18.0, 18.0)
108 .right_from(state.ids.flashing_lights_label, 10.0)
109 .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
110 .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
111 .set(state.ids.flashing_lights_button, ui);
112
113 Text::new(
114 &self
115 .localized_strings
116 .get_msg("hud-settings-flashing_lights_info"),
117 )
118 .font_size(self.fonts.cyri.scale(14))
119 .font_id(self.fonts.cyri.conrod_id)
120 .right_from(state.ids.flashing_lights_label, 32.0)
121 .color(TEXT_COLOR)
122 .set(state.ids.flashing_lights_info_label, ui);
123
124 if render_mode.flashing_lights_enabled != flashing_lights_enabled {
125 events.push(ChangeRenderMode(Box::new(RenderMode {
126 flashing_lights_enabled,
127 ..render_mode.clone()
128 })));
129 }
130
131 Text::new(&self.localized_strings.get_msg("hud-settings-subtitles"))
133 .font_size(self.fonts.cyri.scale(14))
134 .font_id(self.fonts.cyri.conrod_id)
135 .down_from(state.ids.flashing_lights_label, 10.0)
136 .color(TEXT_COLOR)
137 .set(state.ids.subtitles_label, ui);
138
139 let subtitles_enabled = ToggleButton::new(
140 self.global_state.settings.audio.subtitles,
141 self.imgs.checkbox,
142 self.imgs.checkbox_checked,
143 )
144 .w_h(18.0, 18.0)
145 .right_from(state.ids.subtitles_label, 10.0)
146 .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
147 .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
148 .set(state.ids.subtitles_button, ui);
149
150 if subtitles_enabled != self.global_state.settings.audio.subtitles {
151 events.push(SetSubtitles(subtitles_enabled));
152 }
153
154 events
155 }
156}