Skip to content

Commit 6ce6a38

Browse files
committed
Change to the glow renderer of iced
Using the glow renderer since it's more compatible with older systems, a huge drawback is that it currently doesn't support images, so I had to switch to the unicode pieces from the gnu FreeSerif font as they're at least not as ugly as the ones in some sans fonts.
1 parent 8da3e92 commit 6ce6a38

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
iced = {version = "0.2", features = ["image"] }
10+
iced = {version = "0.2", features = ["glow", "glow_default_system_font"] }
1111
rand = "0.8"
1212
chess = "3.2.0"
1313
csv = "1.1.6"

FreeSerif.otf

1.95 MB
Binary file not shown.

src/main.rs

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use iced::{button, container, slider, pick_list, Container, Align, Length, HorizontalAlignment, VerticalAlignment, Background, Button, Slider, PickList, Row, Column, Element, Sandbox, Settings, Text, Image};
2-
1+
use iced::{button, container, slider, pick_list, Container, Align, Length, HorizontalAlignment, VerticalAlignment, Background, Button, Slider, PickList, Row, Column, Element, Sandbox, Settings, Text};
2+
use iced::Font;
33
use chess::{Board, BoardStatus, ChessMove, Color, Piece, Rank, Square, File};
44
use std::str::FromStr;
55

@@ -12,6 +12,11 @@ extern crate serde_derive;
1212
#[macro_use]
1313
extern crate lazy_static;
1414

15+
pub const FREE_SERIF: Font = Font::External {
16+
name: "Free Serif",
17+
bytes: include_bytes!("../FreeSerif.otf"),
18+
};
19+
1520
lazy_static!{
1621
static ref SETTINGS: OfflinePuzzlesConfig = load_config();
1722
}
@@ -659,29 +664,33 @@ impl Sandbox for OfflinePuzzles {
659664
if let Some(piece) = piece {
660665
if color.unwrap() == Color::White {
661666
text = match piece {
662-
Piece::Pawn => "/wP.png",
663-
Piece::Rook => "/wR.png",
664-
Piece::Knight => "/wN.png",
665-
Piece::Bishop => "/wB.png",
666-
Piece::Queen => "/wQ.png",
667-
Piece::King => "/wK.png"
667+
Piece::Pawn => "",
668+
Piece::Rook => "",
669+
Piece::Knight => "",
670+
Piece::Bishop => "",
671+
Piece::Queen => "",
672+
Piece::King => ""
668673
};
669674
} else {
670675
text = match piece {
671-
Piece::Pawn => "/bP.png",
672-
Piece::Rook => "/bR.png",
673-
Piece::Knight => "/bN.png",
674-
Piece::Bishop => "/bB.png",
675-
Piece::Queen => "/bQ.png",
676-
Piece::King => "/bK.png"
676+
Piece::Pawn => "",
677+
Piece::Rook => "",
678+
Piece::Knight => "",
679+
Piece::Bishop => "",
680+
Piece::Queen => "",
681+
Piece::King => ""
677682
};
678683
}
679684
}
680685

681686
row = row.push(Button::new(button,
682-
Image::new(String::from(&SETTINGS.piece_theme) + text)
687+
Text::new(text)
688+
.horizontal_alignment(HorizontalAlignment::Center)
689+
.vertical_alignment(VerticalAlignment::Center)
683690
.width(Length::Fill)
684691
.height(Length::Fill)
692+
.font(FREE_SERIF)
693+
.size(SETTINGS.square_size)
685694
)
686695
.width(Length::Units(SETTINGS.square_size))
687696
.height(Length::Units(SETTINGS.square_size))
@@ -759,29 +768,33 @@ impl Sandbox for OfflinePuzzles {
759768
i = 0;
760769
for button in &mut self.btns_promotion {
761770
let piece;
762-
let mut image = String::from(&SETTINGS.piece_theme);
771+
let text;
763772
match i {
764773
0 => {
765774
piece = Piece::Rook;
766-
image.push_str("/wR.png");
775+
text = "♖";
767776
}
768777
1 => {
769778
piece = Piece::Knight;
770-
image.push_str("/wN.png");
779+
text = "♘";
771780
}
772781
2 => {
773782
piece = Piece::Bishop;
774-
image.push_str("/wB.png");
783+
text = "♗";
775784
}
776785
_ => {
777786
piece = Piece::Queen;
778-
image.push_str("/wQ.png");
787+
text = "♕";
779788
}
780789
};
781790
row_promotion = row_promotion.push(Row::new().spacing(0).align_items(Align::Center).push(Button::new(button,
782-
Image::new(String::from(image))
791+
Text::new(text)
792+
.horizontal_alignment(HorizontalAlignment::Center)
793+
.vertical_alignment(VerticalAlignment::Center)
783794
.width(Length::Fill)
784795
.height(Length::Fill)
796+
.font(FREE_SERIF)
797+
.size(SETTINGS.square_size/2)
785798
)
786799
.width(Length::Units(SETTINGS.square_size/2))
787800
.height(Length::Units(SETTINGS.square_size/2))

0 commit comments

Comments
 (0)