From dfffb658f4acefa0bea2a633b584c3a6065ab89f Mon Sep 17 00:00:00 2001 From: Syniis Date: Sun, 28 Jan 2024 20:18:19 +0100 Subject: [PATCH] Allow moving chat window --- voxygen/src/hud/chat.rs | 30 ++++++++++++++++++++++-------- voxygen/src/hud/mod.rs | 6 ++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index a9ce2dbd4c..1ec404c12b 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -82,6 +82,7 @@ pub struct Chat<'a> { // TODO: add an option to adjust this history_max: usize, chat_size: Vec2, + chat_pos: Vec2, localized_strings: &'a Localization, } @@ -96,6 +97,7 @@ impl<'a> Chat<'a> { fonts: &'a Fonts, localized_strings: &'a Localization, chat_size: Vec2, + chat_pos: Vec2, ) -> Self { Self { pulse, @@ -110,6 +112,7 @@ impl<'a> Chat<'a> { common: widget::CommonBuilder::default(), history_max: 32, chat_size, + chat_pos, localized_strings, } } @@ -186,6 +189,7 @@ pub enum Event { ChangeChatTab(Option), ShowChatTabSettings(usize), ResizeChat(Vec2), + MoveChat(Vec2), } impl<'a> Widget for Chat<'a> { @@ -239,15 +243,25 @@ impl<'a> Widget for Chat<'a> { } }); - let handle_chat_resize = |chat_widget, ui: &mut UiCell, events: &mut Vec| { - let dragged: Vec2 = ui + let handle_chat_mouse_events = |chat_widget, ui: &mut UiCell, events: &mut Vec| { + let pos_delta: Vec2 = ui + .widget_input(chat_widget) + .drags() + .left() + .map(|drag| Vec2::::from(drag.delta_xy)) + .sum(); + if !pos_delta.is_approx_zero() { + let pos = self.chat_pos + pos_delta; + events.push(Event::MoveChat(pos)); + } + let size_delta: Vec2 = ui .widget_input(chat_widget) .drags() .right() .map(|drag| Vec2::::from(drag.delta_xy)) - .sum::>(); - if !dragged.is_approx_zero() { - let size = self.chat_size + dragged; + .sum(); + if !size_delta.is_approx_zero() { + let size = self.chat_size + size_delta; let size = size.map3(MIN_DIMENSION, MAX_DIMENSION, |sz, min, max| { sz.clamp(min, max) }); @@ -255,7 +269,7 @@ impl<'a> Widget for Chat<'a> { } }; - handle_chat_resize(state.ids.message_box, ui, &mut events); + handle_chat_mouse_events(state.ids.message_box, ui, &mut events); // Maintain scrolling // if !self.new_messages.is_empty() { @@ -417,7 +431,7 @@ impl<'a> Widget for Chat<'a> { }; Rectangle::fill([self.chat_size.x, y]) .rgba(0.0, 0.0, 0.0, chat_settings.chat_opacity + 0.1) - .bottom_left_with_margins_on(ui.window, 10.0, 10.0) + .bottom_left_with_margins_on(ui.window, self.chat_pos.y, self.chat_pos.x) .w(self.chat_size.x) .set(state.ids.chat_input_bg, ui); @@ -467,7 +481,7 @@ impl<'a> Widget for Chat<'a> { 0.0 + CHAT_MARGIN_THICKNESS / 2.0, ) } else { - r.bottom_left_with_margins_on(ui.window, 10.0, 10.0) + r.bottom_left_with_margins_on(ui.window, self.chat_pos.y, self.chat_pos.x) } }) .crop_kids() diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index b33477c0ff..0020215046 100755 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -1295,6 +1295,7 @@ pub struct Hud { voxel_minimap: VoxelMinimap, map_drag: Vec2, chat_size: Vec2, + chat_pos: Vec2, } impl Hud { @@ -1431,6 +1432,7 @@ impl Hud { }, map_drag: Vec2::zero(), chat_size: Vec2::new(DEFAULT_CHAT_BOX_WIDTH, DEFAULT_CHAT_BOX_HEIGHT), + chat_pos: Vec2::new(10.0, 10.0), } } @@ -3464,6 +3466,7 @@ impl Hud { &self.fonts, i18n, self.chat_size, + self.chat_pos, ) .and_then(self.force_chat_input.take(), |c, input| c.input(input)) .and_then(self.tab_complete.take(), |c, input| { @@ -3496,6 +3499,9 @@ impl Hud { chat::Event::ResizeChat(size) => { self.chat_size = size; }, + chat::Event::MoveChat(pos) => { + self.chat_pos = pos; + }, } } }