kings of the sides drawn as pieces: White light, Black dark, in both themes (task 45)
This commit is contained in:
parent
70422ce635
commit
117a3880f6
7 changed files with 80 additions and 76 deletions
|
|
@ -131,6 +131,11 @@ impl PieceSet {
|
||||||
format!("bytes://pieces/{}/{}.svg", self.name(), Self::index(piece))
|
format!("bytes://pieces/{}/{}.svg", self.name(), Self::index(piece))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The piece's picture, to put in a widget.
|
||||||
|
pub fn image(self, piece: Piece) -> egui::Image<'static> {
|
||||||
|
egui::Image::new(self.uri(piece))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn paint(self, ui: &egui::Ui, piece: Piece, rect: Rect) {
|
pub fn paint(self, ui: &egui::Ui, piece: Piece, rect: Rect) {
|
||||||
egui::Image::new(self.uri(piece)).paint_at(ui, rect);
|
egui::Image::new(self.uri(piece)).paint_at(ui, rect);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4367,17 +4367,18 @@ impl GameView {
|
||||||
.size(15.0),
|
.size(15.0),
|
||||||
);
|
);
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
let (short, long) = match pos.turn() {
|
let white = pos.turn() == Color::White;
|
||||||
Color::White => ("♔", tr("♔ White to move")),
|
let long = if white {
|
||||||
Color::Black => ("♚", tr("♚ Black to move")),
|
tr("White to move")
|
||||||
|
} else {
|
||||||
|
tr("Black to move")
|
||||||
};
|
};
|
||||||
// In a narrow panel the king alone says who moves.
|
// In a narrow panel the king alone says who moves.
|
||||||
let text = if ui.available_width() < 110.0 {
|
let narrow = ui.available_width() < 110.0;
|
||||||
short
|
if !narrow {
|
||||||
} else {
|
ui.label(RichText::new(long).strong().size(15.0));
|
||||||
long
|
}
|
||||||
};
|
ui.add(crate::widgets::side_king(white, 17.0).sense(egui::Sense::hover()))
|
||||||
ui.label(RichText::new(text).strong().size(15.0))
|
|
||||||
.on_hover_text(long);
|
.on_hover_text(long);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -12544,17 +12544,6 @@ const ROWS: &[[&str; 9]] = &[
|
||||||
"Rangingiz",
|
"Rangingiz",
|
||||||
"Түсіңіз",
|
"Түсіңіз",
|
||||||
],
|
],
|
||||||
[
|
|
||||||
"♔ White",
|
|
||||||
"♔ Белые",
|
|
||||||
"♔ Blancs",
|
|
||||||
"♔ Weiß",
|
|
||||||
"♔ Blancas",
|
|
||||||
"♔ Bianco",
|
|
||||||
"♔ Brancas",
|
|
||||||
"♔ Oqlar",
|
|
||||||
"♔ Ақтар",
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
"Random",
|
"Random",
|
||||||
"Случайно",
|
"Случайно",
|
||||||
|
|
@ -12566,17 +12555,6 @@ const ROWS: &[[&str; 9]] = &[
|
||||||
"Tasodifiy",
|
"Tasodifiy",
|
||||||
"Кездейсоқ",
|
"Кездейсоқ",
|
||||||
],
|
],
|
||||||
[
|
|
||||||
"♚ Black",
|
|
||||||
"♚ Чёрные",
|
|
||||||
"♚ Noirs",
|
|
||||||
"♚ Schwarz",
|
|
||||||
"♚ Negras",
|
|
||||||
"♚ Nero",
|
|
||||||
"♚ Pretas",
|
|
||||||
"♚ Qoralar",
|
|
||||||
"♚ Қаралар",
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
"Time",
|
"Time",
|
||||||
"Время",
|
"Время",
|
||||||
|
|
@ -15020,28 +14998,6 @@ const ROWS: &[[&str; 9]] = &[
|
||||||
"Yurish {n} / {last}",
|
"Yurish {n} / {last}",
|
||||||
"Жүріс {n} / {last}",
|
"Жүріс {n} / {last}",
|
||||||
],
|
],
|
||||||
[
|
|
||||||
"♔ White to move",
|
|
||||||
"♔ ход белых",
|
|
||||||
"♔ Trait aux Blancs",
|
|
||||||
"♔ Weiß am Zug",
|
|
||||||
"♔ Juegan blancas",
|
|
||||||
"♔ Muove il Bianco",
|
|
||||||
"♔ Brancas jogam",
|
|
||||||
"♔ Oqlar yuradi",
|
|
||||||
"♔ Ақтар жүреді",
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"♚ Black to move",
|
|
||||||
"♚ ход чёрных",
|
|
||||||
"♚ Trait aux Noirs",
|
|
||||||
"♚ Schwarz am Zug",
|
|
||||||
"♚ Juegan negras",
|
|
||||||
"♚ Muove il Nero",
|
|
||||||
"♚ Pretas jogam",
|
|
||||||
"♚ Qoralar yuradi",
|
|
||||||
"♚ Қаралар жүреді",
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
"Mistakes: {n}",
|
"Mistakes: {n}",
|
||||||
"Ошибок: {n}",
|
"Ошибок: {n}",
|
||||||
|
|
|
||||||
|
|
@ -210,13 +210,13 @@ pub(crate) fn set_side(settings: &mut Settings, id: &RepertoireId, side: Learnin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn king(side: LearningSide) -> &'static str {
|
pub(crate) fn king(side: LearningSide) -> egui::Image<'static> {
|
||||||
match side {
|
crate::widgets::side_king(side == LearningSide::White, KING)
|
||||||
LearningSide::White => "♔",
|
|
||||||
LearningSide::Black => "♚",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The side of the king of [`king`] (as a 14-point ♔ took).
|
||||||
|
pub(crate) const KING: f32 = 16.0;
|
||||||
|
|
||||||
pub(crate) fn you_play(side: LearningSide) -> &'static str {
|
pub(crate) fn you_play(side: LearningSide) -> &'static str {
|
||||||
tr(match side {
|
tr(match side {
|
||||||
LearningSide::White => "You play White",
|
LearningSide::White => "You play White",
|
||||||
|
|
|
||||||
|
|
@ -1557,11 +1557,34 @@ impl Dialog {
|
||||||
section(ui, tr("Your colour"));
|
section(ui, tr("Your colour"));
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
for (c, label) in [
|
for (c, label) in [
|
||||||
(ColorChoice::White, tr("♔ White")),
|
(ColorChoice::White, tr("White")),
|
||||||
(ColorChoice::Random, tr("Random")),
|
(ColorChoice::Random, tr("Random")),
|
||||||
(ColorChoice::Black, tr("♚ Black")),
|
(ColorChoice::Black, tr("Black")),
|
||||||
] {
|
] {
|
||||||
if choice(ui, self.prefs.color == c, label, [(W - 2.0 * GAP) / 3.0, TILE_H]).clicked() {
|
let size = [(W - 2.0 * GAP) / 3.0, TILE_H];
|
||||||
|
let on = self.prefs.color == c;
|
||||||
|
let king = match c {
|
||||||
|
ColorChoice::White => Some(true),
|
||||||
|
ColorChoice::Black => Some(false),
|
||||||
|
ColorChoice::Random => None,
|
||||||
|
};
|
||||||
|
let clicked = match king {
|
||||||
|
Some(white) => ui
|
||||||
|
.add_sized(
|
||||||
|
size,
|
||||||
|
egui::Button::selectable(
|
||||||
|
on,
|
||||||
|
(
|
||||||
|
crate::widgets::side_king(white, 16.0),
|
||||||
|
RichText::new(label).size(14.0),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.frame_when_inactive(true),
|
||||||
|
)
|
||||||
|
.clicked(),
|
||||||
|
None => choice(ui, on, label, size).clicked(),
|
||||||
|
};
|
||||||
|
if clicked {
|
||||||
self.prefs.color = c;
|
self.prefs.color = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1582,25 +1582,24 @@ impl RepertoireUi {
|
||||||
// The colour gives way first: down to the king, the words on
|
// The colour gives way first: down to the king, the words on
|
||||||
// hover; only then is the name cut.
|
// hover; only then is the name cut.
|
||||||
let gap = ui.spacing().item_spacing.x;
|
let gap = ui.spacing().item_spacing.x;
|
||||||
let full = format!("{} {}", layout::king(side), layout::you_play(side));
|
let words = layout::you_play(side);
|
||||||
let name_w = style_width(ui, &name, egui::TextStyle::Heading);
|
let name_w = style_width(ui, &name, egui::TextStyle::Heading);
|
||||||
let full_w = style_width(ui, &full, egui::TextStyle::Body) + gap;
|
let king_w = layout::KING + gap;
|
||||||
|
let full_w = king_w + style_width(ui, words, egui::TextStyle::Body) + gap;
|
||||||
let short = name_w + full_w > width;
|
let short = name_w + full_w > width;
|
||||||
let you = if short {
|
let you_w = if short { king_w } else { full_w };
|
||||||
layout::king(side).to_owned()
|
|
||||||
} else {
|
|
||||||
full
|
|
||||||
};
|
|
||||||
let you_w = style_width(ui, &you, egui::TextStyle::Body) + gap;
|
|
||||||
ui.allocate_ui_with_layout(
|
ui.allocate_ui_with_layout(
|
||||||
vec2((width - you_w - gap).max(0.0), 26.0),
|
vec2((width - you_w - gap).max(0.0), 26.0),
|
||||||
egui::Layout::left_to_right(egui::Align::Center),
|
egui::Layout::left_to_right(egui::Align::Center),
|
||||||
|ui| layout::line(ui, RichText::new(&name).heading()),
|
|ui| layout::line(ui, RichText::new(&name).heading()),
|
||||||
);
|
);
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
let label = ui.label(RichText::new(you).weak());
|
if !short {
|
||||||
|
ui.label(RichText::new(words).weak());
|
||||||
|
}
|
||||||
|
let king = ui.add(layout::king(side).sense(egui::Sense::hover()));
|
||||||
if short {
|
if short {
|
||||||
label.on_hover_text(layout::you_play(side));
|
king.on_hover_text(words);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -1800,7 +1799,7 @@ impl RepertoireUi {
|
||||||
layout::line(ui, repertoire.name.as_str());
|
layout::line(ui, repertoire.name.as_str());
|
||||||
});
|
});
|
||||||
row.col(|ui| {
|
row.col(|ui| {
|
||||||
ui.label(layout::king(side))
|
ui.add(layout::king(side).sense(egui::Sense::hover()))
|
||||||
.on_hover_text(layout::you_play(side));
|
.on_hover_text(layout::you_play(side));
|
||||||
});
|
});
|
||||||
let has_moves = self.index.get(id).is_none_or(|row| row.has_moves);
|
let has_moves = self.index.get(id).is_none_or(|row| row.has_moves);
|
||||||
|
|
@ -2773,14 +2772,17 @@ fn side_choice(ui: &mut Ui, side: &mut LearningSide) {
|
||||||
ui.add_space(2.0);
|
ui.add_space(2.0);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
for (value, label) in [
|
for (value, label) in [
|
||||||
(LearningSide::White, tr("♔ White")),
|
(LearningSide::White, tr("White")),
|
||||||
(LearningSide::Black, tr("♚ Black")),
|
(LearningSide::Black, tr("Black")),
|
||||||
] {
|
] {
|
||||||
if ui
|
if ui
|
||||||
.add_sized(
|
.add_sized(
|
||||||
[222.0, 34.0],
|
[222.0, 34.0],
|
||||||
egui::Button::selectable(*side == value, RichText::new(label).size(14.0))
|
egui::Button::selectable(
|
||||||
.frame_when_inactive(true),
|
*side == value,
|
||||||
|
(layout::king(value), RichText::new(label).size(14.0)),
|
||||||
|
)
|
||||||
|
.frame_when_inactive(true),
|
||||||
)
|
)
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,23 @@ pub fn primary(ui: &mut egui::Ui, label: &str) -> egui::Response {
|
||||||
primary_wide(ui, label, 0.0)
|
primary_wide(ui, label, 0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The king of a side, `size` points square: White's light with a dark outline,
|
||||||
|
/// Black's dark with a light one, the same in both themes (task 45; a font's ♔/♚ read
|
||||||
|
/// the other way round on a dark background). From the classic set, whatever the board's.
|
||||||
|
pub fn side_king(white: bool, size: f32) -> egui::Image<'static> {
|
||||||
|
let color = if white {
|
||||||
|
shakmaty::Color::White
|
||||||
|
} else {
|
||||||
|
shakmaty::Color::Black
|
||||||
|
};
|
||||||
|
crate::assets::PieceSet::Cburnett
|
||||||
|
.image(shakmaty::Piece {
|
||||||
|
color,
|
||||||
|
role: shakmaty::Role::King,
|
||||||
|
})
|
||||||
|
.fit_to_exact_size(egui::vec2(size, size))
|
||||||
|
}
|
||||||
|
|
||||||
/// `primary()` at least `width` wide (a button whose label changes keeps its place).
|
/// `primary()` at least `width` wide (a button whose label changes keeps its place).
|
||||||
pub fn primary_wide(ui: &mut egui::Ui, label: &str, width: f32) -> egui::Response {
|
pub fn primary_wide(ui: &mut egui::Ui, label: &str, width: f32) -> egui::Response {
|
||||||
ui.add(
|
ui.add(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue