2019-04-30 14:39:19 +00:00
|
|
|
use conrod_core::{
|
|
|
|
builder_methods, color,
|
|
|
|
text::font,
|
|
|
|
widget::{self, Button, Image, Rectangle, Text},
|
|
|
|
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
|
|
|
};
|
2019-05-03 16:56:18 +00:00
|
|
|
|
2019-04-30 14:39:19 +00:00
|
|
|
use super::{
|
2019-04-30 20:43:55 +00:00
|
|
|
img_ids::Imgs,
|
|
|
|
font_ids::Fonts,
|
|
|
|
TEXT_COLOR,
|
2019-04-30 14:39:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
widget_ids! {
|
|
|
|
struct Ids {
|
2019-05-04 17:29:19 +00:00
|
|
|
map_frame,
|
2019-04-30 14:39:19 +00:00
|
|
|
map_bg,
|
2019-05-04 17:29:19 +00:00
|
|
|
map_icon,
|
2019-04-30 14:39:19 +00:00
|
|
|
map_close,
|
2019-05-04 17:29:19 +00:00
|
|
|
map_title,
|
2019-04-30 14:39:19 +00:00
|
|
|
map_frame_l,
|
|
|
|
map_frame_r,
|
2019-05-04 17:29:19 +00:00
|
|
|
map_frame_bl,
|
|
|
|
map_frame_br,
|
2019-04-30 14:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(WidgetCommon)]
|
|
|
|
pub struct Map<'a> {
|
|
|
|
imgs: &'a Imgs,
|
2019-04-30 20:43:55 +00:00
|
|
|
fonts: &'a Fonts,
|
2019-04-30 14:39:19 +00:00
|
|
|
|
|
|
|
#[conrod(common_builder)]
|
|
|
|
common: widget::CommonBuilder,
|
2019-04-30 20:43:55 +00:00
|
|
|
style: (),
|
2019-04-30 14:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Map<'a> {
|
2019-04-30 20:43:55 +00:00
|
|
|
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
2019-04-30 14:39:19 +00:00
|
|
|
Self {
|
|
|
|
imgs,
|
2019-04-30 20:43:55 +00:00
|
|
|
fonts,
|
2019-04-30 14:39:19 +00:00
|
|
|
common: widget::CommonBuilder::default(),
|
2019-04-30 20:43:55 +00:00
|
|
|
style: (),
|
2019-04-30 14:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct State {
|
|
|
|
ids: Ids,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Event {
|
|
|
|
Close,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Widget for Map<'a> {
|
|
|
|
type State = State;
|
2019-04-30 20:43:55 +00:00
|
|
|
type Style = ();
|
2019-04-30 14:39:19 +00:00
|
|
|
type Event = Option<Event>;
|
|
|
|
|
|
|
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
|
|
|
State {
|
|
|
|
ids: Ids::new(id_gen),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn style(&self) -> Self::Style {
|
2019-04-30 20:43:55 +00:00
|
|
|
()
|
2019-04-30 14:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
|
|
|
let widget::UpdateArgs {
|
|
|
|
id,
|
|
|
|
state,
|
|
|
|
ui,
|
|
|
|
style,
|
|
|
|
..
|
|
|
|
} = args;
|
|
|
|
|
|
|
|
// BG
|
2019-05-04 17:29:19 +00:00
|
|
|
Rectangle::fill_with([824.0, 976.0], color::TRANSPARENT)
|
|
|
|
.mid_top_with_margin_on(ui.window, 15.0)
|
|
|
|
.scroll_kids()
|
|
|
|
.scroll_kids_vertically()
|
|
|
|
.set(state.ids.map_bg, ui);
|
|
|
|
// Frame
|
|
|
|
Image::new(self.imgs.map_frame_l)
|
|
|
|
.top_left_with_margins_on(state.ids.map_bg, 0.0, 0.0)
|
|
|
|
.w_h(412.0, 488.0)
|
|
|
|
.set(state.ids.map_frame_l, ui);
|
|
|
|
Image::new(self.imgs.map_frame_r)
|
|
|
|
.right_from(state.ids.map_frame_l, 0.0)
|
|
|
|
.w_h(412.0, 488.0)
|
|
|
|
.set(state.ids.map_frame_r, ui);
|
|
|
|
Image::new(self.imgs.map_frame_br)
|
|
|
|
.down_from(state.ids.map_frame_r, 0.0)
|
|
|
|
.w_h(412.0, 488.0)
|
|
|
|
.set(state.ids.map_frame_br, ui);
|
|
|
|
Image::new(self.imgs.map_frame_bl)
|
|
|
|
.down_from(state.ids.map_frame_l, 0.0)
|
|
|
|
.w_h(412.0, 488.0)
|
|
|
|
.set(state.ids.map_frame_bl, ui);
|
|
|
|
|
|
|
|
// Icon
|
|
|
|
Image::new(self.imgs.map_icon)
|
|
|
|
.w_h(224.0 / 3.0, 224.0 / 3.0)
|
|
|
|
.top_left_with_margins_on(state.ids.map_frame, -10.0, -10.0)
|
|
|
|
.set(state.ids.map_icon, ui);
|
|
|
|
|
2019-04-30 14:39:19 +00:00
|
|
|
|
|
|
|
// Icon
|
|
|
|
Image::new(self.imgs.map_icon)
|
|
|
|
.w_h(224.0 / 3.0, 224.0 / 3.0)
|
|
|
|
.top_left_with_margins_on(state.ids.map_frame, -10.0, -10.0)
|
|
|
|
.set(state.ids.map_icon, ui);
|
|
|
|
|
|
|
|
// X-Button
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.close_button)
|
|
|
|
.w_h(28.0, 28.0)
|
|
|
|
.hover_image(self.imgs.close_button_hover)
|
|
|
|
.press_image(self.imgs.close_button_press)
|
|
|
|
.top_right_with_margins_on(state.ids.map_frame_r, 0.0, 0.0)
|
|
|
|
.set(state.ids.map_close, ui)
|
|
|
|
.was_clicked()
|
2019-04-30 14:39:19 +00:00
|
|
|
{
|
|
|
|
return Some(Event::Close);
|
2019-05-04 17:29:19 +00:00
|
|
|
}
|
2019-04-30 14:39:19 +00:00
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|