Skip to content

Commit

Permalink
Add tooltips to the server buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
IohannRabeson committed Aug 5, 2023
1 parent f035c21 commit 0a17eff
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions teamwork-launcher/src/ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use {
icons,
ui::{
self,
buttons::{favorite_button, svg_button},
buttons::{svg_button},
styles::BoxContainerStyle,
widgets::{self, ping, region, thumbnail},
widgets::{self, ping, region, thumbnail, tooltip},
THUMBNAIL_CONTENT_FIT,
},
},
Expand All @@ -28,6 +28,7 @@ use {
},
};
use crate::ui::widgets::spinner;
use crate::ui::buttons;

pub struct ViewContext<'l> {
pub panes: &'l pane_grid::State<PaneView>,
Expand Down Expand Up @@ -79,29 +80,54 @@ pub fn view(context: ViewContext) -> Element<Message> {
main_column.spacing(4).into()
}

const BUTTON_SIZE: u16 = 20;

fn details_button(server: &Server) -> Element<Message> {
tooltip(svg_button(icons::INFO_ICON.clone(), BUTTON_SIZE)
.on_press(Message::ShowServer(server.ip_port.clone(), server.map.clone())),
"Show details", iced::widget::tooltip::Position::Bottom)
}

fn favorite_button(server: &Server, is_bookmarked: bool) -> Element<Message> {
tooltip(buttons::favorite_button(is_bookmarked, BUTTON_SIZE)
.on_press(Message::Bookmarked(server.ip_port.clone(), !is_bookmarked)),
"Add / remove from favorites", iced::widget::tooltip::Position::Bottom)
}

fn copy_connection_string_button(server: &Server) -> Element<Message> {
tooltip(svg_button(icons::COPY_ICON.clone(), BUTTON_SIZE)
.on_press(Message::CopyConnectionString(server.ip_port.clone())),
"Copy the connection string to the clipboard", iced::widget::tooltip::Position::Bottom)
}

fn refresh_server_button(server: &Server) -> Element<Message> {
tooltip(svg_button(icons::REFRESH_ICON.clone(), BUTTON_SIZE)
.on_press(Message::RefreshServer(server.ip_port.clone())),
"Refresh server information", iced::widget::tooltip::Position::Bottom)
}

fn start_game_button(server: &Server) -> Element<Message> {
tooltip(svg_button(icons::PLAY_ICON.clone(), BUTTON_SIZE).on_press(Message::LaunchGame(server.ip_port.clone())),
"Start Team Fortress 2", iced::widget::tooltip::Position::Bottom)
}

/// The wide view that displays server information.
fn server_view<'l>(server: &'l Server, bookmarks: &'l Bookmarks, game_modes: &'l GameModes) -> Element<'l, Message> {
let is_bookmarked = bookmarks.is_bookmarked(&server.ip_port);
let ip_port_text = format!("{}:{}", server.ip_port.ip(), server.ip_port.port());
let game_modes = widgets::game_modes(game_modes, &server.game_modes);

const BUTTON_SIZE: u16 = 20;

container(
row![
thumbnail(server, Length::Fixed(250.0), Length::Fixed(125.0)),
column![
row![
text(&server.name).size(28).width(Length::Fill),
svg_button(icons::INFO_ICON.clone(), BUTTON_SIZE)
.on_press(Message::ShowServer(server.ip_port.clone(), server.map.clone())),
favorite_button(is_bookmarked, BUTTON_SIZE)
.on_press(Message::Bookmarked(server.ip_port.clone(), !is_bookmarked)),
svg_button(icons::COPY_ICON.clone(), BUTTON_SIZE)
.on_press(Message::CopyConnectionString(server.ip_port.clone())),
svg_button(icons::REFRESH_ICON.clone(), BUTTON_SIZE)
.on_press(Message::RefreshServer(server.ip_port.clone())),
svg_button(icons::PLAY_ICON.clone(), BUTTON_SIZE).on_press(Message::LaunchGame(server.ip_port.clone())),
details_button(server),
favorite_button(server, is_bookmarked),
copy_connection_string_button(server),
refresh_server_button(server),
start_game_button(server),
]
.padding(4)
.spacing(4),
Expand Down Expand Up @@ -167,15 +193,11 @@ fn compact_server_view<'l>(server: &'l Server, bookmarks: &'l Bookmarks, game_mo
row![
thumbnail,
column![
svg_button(icons::INFO_ICON.clone(), BUTTON_SIZE)
.on_press(Message::ShowServer(server.ip_port.clone(), server.map.clone())),
favorite_button(is_bookmarked, BUTTON_SIZE)
.on_press(Message::Bookmarked(server.ip_port.clone(), !is_bookmarked)),
svg_button(icons::COPY_ICON.clone(), BUTTON_SIZE)
.on_press(Message::CopyConnectionString(server.ip_port.clone())),
svg_button(icons::REFRESH_ICON.clone(), BUTTON_SIZE)
.on_press(Message::RefreshServer(server.ip_port.clone())),
svg_button(icons::PLAY_ICON.clone(), BUTTON_SIZE).on_press(Message::LaunchGame(server.ip_port.clone())),
details_button(server),
favorite_button(server, is_bookmarked),
copy_connection_string_button(server),
refresh_server_button(server),
start_game_button(server),
]
.spacing(4)
]
Expand Down

0 comments on commit 0a17eff

Please sign in to comment.