add padding to language select and server select menu buttons so that the scrollbar doesn't overlap them

This commit is contained in:
Yusuf Bera Ertan 2020-07-25 16:52:04 +03:00 committed by Imbris
parent 52479fec2f
commit bae7f56393
4 changed files with 90 additions and 60 deletions

View File

@ -114,7 +114,6 @@ Is the client up to date?"#,
"main.connecting": "Connecting", "main.connecting": "Connecting",
"main.creating_world": "Creating world", "main.creating_world": "Creating world",
"main.tip": "Tip:", "main.tip": "Tip:",
"main.select_language": "Select a language",
// Welcome notice that appears the first time Veloren is started // Welcome notice that appears the first time Veloren is started
"main.notice": r#"Welcome to the alpha version of Veloren! "main.notice": r#"Welcome to the alpha version of Veloren!
@ -159,6 +158,7 @@ https://veloren.net/account/."#,
"main.login.not_on_whitelist": "You need a Whitelist entry by an Admin to join", "main.login.not_on_whitelist": "You need a Whitelist entry by an Admin to join",
"main.login.banned": "You have been banned with the following reason", "main.login.banned": "You have been banned with the following reason",
"main.login.kicked": "You have been kicked with the following reason", "main.login.kicked": "You have been kicked with the following reason",
"main.login.select_language": "Select a language",
"main.servers.select_server": "Select a server", "main.servers.select_server": "Select a server",

View File

@ -1,4 +1,4 @@
use super::{Imgs, LoginInfo, Message}; use super::{Imgs, LoginInfo, Message, FILL_FRAC_ONE, FILL_FRAC_TWO};
use crate::{ use crate::{
i18n::Localization, i18n::Localization,
ui::{ ui::{
@ -20,8 +20,6 @@ use iced::{
}; };
use vek::*; use vek::*;
const FILL_FRAC_ONE: f32 = 0.77;
const FILL_FRAC_TWO: f32 = 0.53;
const INPUT_WIDTH: u16 = 280; const INPUT_WIDTH: u16 = 280;
const INPUT_TEXT_SIZE: u16 = 24; const INPUT_TEXT_SIZE: u16 = 24;
@ -217,47 +215,59 @@ impl LanguageSelectBanner {
selected_language_index: Option<usize>, selected_language_index: Option<usize>,
button_style: style::button::Style, button_style: style::button::Style,
) -> Element<Message> { ) -> Element<Message> {
let title = Text::new(i18n.get("main.select_language")) // Reset button states if languages were added / removed
if self.language_buttons.len() != language_metadatas.len() {
self.language_buttons = vec![Default::default(); language_metadatas.len()];
}
let title = Text::new(i18n.get("main.login.select_language"))
.size(fonts.cyri.scale(35)) .size(fonts.cyri.scale(35))
.horizontal_alignment(iced::HorizontalAlignment::Center); .horizontal_alignment(iced::HorizontalAlignment::Center);
let mut list = Scrollable::new(&mut self.selection_list) let mut list = Scrollable::new(&mut self.selection_list)
.spacing(8) .spacing(8)
.height(Length::Fill) .height(Length::Fill)
.width(Length::Fill)
.align_items(Align::Start); .align_items(Align::Start);
if self.language_buttons.len() != language_metadatas.len() { let list_items = self
self.language_buttons = vec![Default::default(); language_metadatas.len()];
}
for (i, (state, lang)) in self
.language_buttons .language_buttons
.iter_mut() .iter_mut()
.zip(language_metadatas) .zip(language_metadatas)
.enumerate() .enumerate()
{ .map(|(i, (state, lang))| {
let color = if Some(i) == selected_language_index { let color = if Some(i) == selected_language_index {
(97, 255, 18) (97, 255, 18)
} else { } else {
(97, 97, 25) (97, 97, 25)
}; };
let button = Button::new( let button = Button::new(
state, state,
Container::new(Text::new(lang.language_name.clone()).size(fonts.cyri.scale(25))) Row::with_children(vec![
.padding(16) Space::new(Length::FillPortion(5), Length::Units(0)).into(),
.center_y(), Text::new(lang.language_name.clone())
) .width(Length::FillPortion(95))
.style( .size(fonts.cyri.scale(25))
style::button::Style::new(imgs.selection) .vertical_alignment(iced::VerticalAlignment::Center)
.hover_image(imgs.selection_hover) .into(),
.press_image(imgs.selection_press) ]),
.image_color(vek::Rgba::new(color.0, color.1, color.2, 192)), )
) .style(
.width(Length::Fill) style::button::Style::new(imgs.selection)
.min_height(56) .hover_image(imgs.selection_hover)
.on_press(Message::LanguageChanged(i)); .press_image(imgs.selection_press)
list = list.push(button); .image_color(vek::Rgba::new(color.0, color.1, color.2, 192)),
)
.min_height(56)
.on_press(Message::LanguageChanged(i));
Row::with_children(vec![
Space::new(Length::FillPortion(3), Length::Units(0)).into(),
button.width(Length::FillPortion(92)).into(),
Space::new(Length::FillPortion(5), Length::Units(0)).into(),
])
});
for item in list_items {
list = list.push(item);
} }
let okay_button = Container::new(neat_button( let okay_button = Container::new(neat_button(
@ -287,7 +297,7 @@ impl LanguageSelectBanner {
.height(Length::Fill), .height(Length::Fill),
content, content,
) )
.padding(Padding::new().horizontal(8).vertical(15).bottom(50)) .padding(Padding::new().horizontal(5).top(15).bottom(50))
.max_width(350); .max_width(350);
selection_menu.into() selection_menu.into()

View File

@ -33,6 +33,9 @@ const UI_HIGHLIGHT_0: Color = Color::Rgba(0.79, 1.09, 1.09, 1.0);*/
pub const TEXT_COLOR: iced::Color = iced::Color::from_rgb(1.0, 1.0, 1.0); pub const TEXT_COLOR: iced::Color = iced::Color::from_rgb(1.0, 1.0, 1.0);
pub const DISABLED_TEXT_COLOR: iced::Color = iced::Color::from_rgba(1.0, 1.0, 1.0, 0.2); pub const DISABLED_TEXT_COLOR: iced::Color = iced::Color::from_rgba(1.0, 1.0, 1.0, 0.2);
pub const FILL_FRAC_ONE: f32 = 0.77;
pub const FILL_FRAC_TWO: f32 = 0.53;
image_ids_ice! { image_ids_ice! {
struct Imgs { struct Imgs {
<VoxelGraphic> <VoxelGraphic>
@ -218,7 +221,7 @@ impl Controls {
let language_metadatas = crate::i18n::list_localizations(); let language_metadatas = crate::i18n::list_localizations();
let selected_language_index = language_metadatas let selected_language_index = language_metadatas
.iter() .iter()
.position(|f| &f.language_identifier == &settings.language.selected_language); .position(|f| f.language_identifier == settings.language.selected_language);
Self { Self {
fonts, fonts,

View File

@ -1,4 +1,4 @@
use super::{Imgs, Message}; use super::{Imgs, Message, FILL_FRAC_ONE};
use crate::{ use crate::{
i18n::Localization, i18n::Localization,
ui::{ ui::{
@ -48,7 +48,7 @@ impl Screen {
Container::new(neat_button( Container::new(neat_button(
&mut self.back_button, &mut self.back_button,
i18n.get("common.back"), i18n.get("common.back"),
0.77_f32, FILL_FRAC_ONE,
button_style, button_style,
Some(Message::Back), Some(Message::Back),
)) ))
@ -63,33 +63,50 @@ impl Screen {
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill); .height(Length::Fill);
// Reset button states if servers were added / removed
if self.server_buttons.len() != servers.len() { if self.server_buttons.len() != servers.len() {
self.server_buttons = vec![Default::default(); servers.len()]; self.server_buttons = vec![Default::default(); servers.len()];
} }
for (i, (state, server)) in self.server_buttons.iter_mut().zip(servers).enumerate() { let list_items =
let color = if Some(i) == selected_server_index { self.server_buttons
(97, 255, 18) .iter_mut()
} else { .zip(servers)
(97, 97, 25) .enumerate()
}; .map(|(i, (state, server))| {
let button = Button::new( let color = if Some(i) == selected_server_index {
state, (97, 255, 18)
Container::new(Text::new(server.as_ref()).size(fonts.cyri.scale(30))) } else {
.padding(24) (97, 97, 25)
.center_y() };
.height(Length::Fill), let button = Button::new(
) state,
.style( Row::with_children(vec![
style::button::Style::new(imgs.selection) Space::new(Length::FillPortion(5), Length::Units(0)).into(),
.hover_image(imgs.selection_hover) Text::new(server.as_ref())
.press_image(imgs.selection_press) .size(fonts.cyri.scale(30))
.image_color(vek::Rgba::new(color.0, color.1, color.2, 255)), .width(Length::FillPortion(95))
) .vertical_alignment(iced::VerticalAlignment::Center)
.width(Length::Fill) .into(),
.min_height(100) ]),
.on_press(Message::ServerChanged(i)); )
list = list.push(button); .style(
style::button::Style::new(imgs.selection)
.hover_image(imgs.selection_hover)
.press_image(imgs.selection_press)
.image_color(vek::Rgba::new(color.0, color.1, color.2, 255)),
)
.min_height(100)
.on_press(Message::ServerChanged(i));
Row::with_children(vec![
Space::new(Length::FillPortion(3), Length::Units(0)).into(),
button.width(Length::FillPortion(92)).into(),
Space::new(Length::FillPortion(5), Length::Units(0)).into(),
])
});
for item in list_items {
list = list.push(item);
} }
Container::new( Container::new(