Migrate to tiny macros of button
This commit is contained in:
1 parent
444352c007
commit
1ad991667b
12 files changed
+52
-45
No files matched your search
@@ -11,7 +11,7 @@ use crate::pages::dictionary::DictionaryMessage::*;
|
||||
use crate::pages::dictionary_quiz::DictionaryQuizState;
|
||||
use crate::pages::import::ImportState;
|
||||
use crate::pages::word::WordState;
|
||||
use crate::push_error;
|
||||
use crate::{jl_button, push_error};
|
||||
use crate::push_error_task;
|
||||
use crate::styling::*;
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
@@ -81,7 +81,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
let mut words = vec![];
|
||||
let dict = &self.state.dictionary.read();
|
||||
|
||||
let mut query = dict.query(Arc::new(|_| true));
|
||||
let query = dict.query(Arc::new(|_| true));
|
||||
let handles = query.handles();
|
||||
words = handles.filter(|h| self.included.contains(h)).collect();
|
||||
|
||||
@@ -257,7 +257,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
|
||||
let mut dictionary = self.state.dictionary.write();
|
||||
|
||||
let reload_query = handle.real() == false;
|
||||
let reload_query = !handle.real();
|
||||
let _ = dictionary.save(&mut handle);
|
||||
if reload_query {
|
||||
self.displayed_words_query.load(&dictionary);
|
||||
@@ -373,7 +373,7 @@ impl DictionaryState {
|
||||
key: word.key.clone().into(),
|
||||
value: word.value.clone().into(),
|
||||
tags: word.tags.clone().into(),
|
||||
handle: word_handle.clone(),
|
||||
handle: *word_handle,
|
||||
};
|
||||
|
||||
let lazy_line = lazy(word_line_data, Self::word_line);
|
||||
@@ -387,7 +387,7 @@ impl DictionaryState {
|
||||
|
||||
fn word_line<'a>(data: &WordLineState) -> Row<'a, DictionaryMessage> {
|
||||
let mut line = Row::new().width(Fill).align_y(Center);
|
||||
let handle = data.handle.clone();
|
||||
let handle = data.handle;
|
||||
line = line.push(
|
||||
checkbox(data.is_included)
|
||||
.label("")
|
||||
@@ -435,7 +435,7 @@ impl DictionaryState {
|
||||
return button("-")
|
||||
.on_press(WordAction(data.handle))
|
||||
.style(
|
||||
|_x: &iced::Theme, _status: iced::widget::button::Status| Style {
|
||||
|_x: &Theme, _status: button::Status| Style {
|
||||
background: None,
|
||||
text_color: Color::BLACK,
|
||||
border: Border::default(),
|
||||
@@ -590,12 +590,12 @@ impl DictionaryState {
|
||||
}
|
||||
|
||||
let groups = self.state.word_groups.read();
|
||||
let group = groups.get_static(self.selected_group.clone()).unwrap();
|
||||
let group = groups.get_static(self.selected_group).unwrap();
|
||||
|
||||
iced::widget::column![
|
||||
scrollable(row).width(Fill).horizontal(),
|
||||
row![
|
||||
button("⇳").on_press(ChangeDirection).style(jl_button),
|
||||
jl_button!("⇳").on_press(ChangeDirection),
|
||||
text_input("Название группы слов", &group.name)
|
||||
.on_input(EditGroup)
|
||||
.width(250)
|
||||
@@ -617,7 +617,7 @@ impl DictionaryState {
|
||||
}
|
||||
|
||||
fn add_word_button(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
let button = button("Добавить слово").style(jl_button);
|
||||
let button = jl_button!("Добавить слово");
|
||||
|
||||
if self.selected_group.real() {
|
||||
return button.on_press(NewWord).into();
|
||||
|
||||
@@ -14,6 +14,7 @@ use iced::{Border, Element, Fill, Task, Theme, alignment};
|
||||
use rand::prelude::SliceRandom;
|
||||
use crate::app::AppState;
|
||||
use crate::data::repositories::Repository;
|
||||
use crate::jl_button;
|
||||
|
||||
pub struct DictionaryQuizState {
|
||||
state: AppState,
|
||||
@@ -91,7 +92,7 @@ impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
||||
]
|
||||
.spacing(DEFAULT_SPACING),
|
||||
row![
|
||||
button("Закончить").style(jl_button).on_press(Back),
|
||||
jl_button!("Закончить").on_press(Back),
|
||||
self.appeal_button()
|
||||
]
|
||||
.spacing(DEFAULT_SPACING),
|
||||
@@ -218,7 +219,7 @@ impl DictionaryQuizState {
|
||||
|
||||
fn appeal_button(&self) -> Element<'_, DictionaryQuizMessage> {
|
||||
if self.is_help && !self.no_typing {
|
||||
return button("Апелляция").style(jl_button).on_press(Appeal).into();
|
||||
return jl_button!("Апелляция").on_press(Appeal).into();
|
||||
}
|
||||
space().into()
|
||||
}
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ use crate::notification::NotificationData::OpenFileError;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::pages::import::ImportMessage::*;
|
||||
use crate::push_error;
|
||||
use crate::jl_button;
|
||||
use crate::styling::*;
|
||||
use iced::widget::button::danger;
|
||||
use iced::widget::container::success;
|
||||
@@ -155,7 +156,7 @@ impl NavigatedPage<ImportMessage> for ImportState {
|
||||
scrollable(
|
||||
column![
|
||||
row![
|
||||
button("Выбрать файл").style(jl_button).on_press(SelectFile),
|
||||
jl_button!("Выбрать файл").on_press(SelectFile),
|
||||
text!("{}", {
|
||||
if let Some(path) = &self.path {
|
||||
path.to_string_lossy().to_string()
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ use crate::styling::*;
|
||||
use iced::widget::*;
|
||||
use iced::{Element, Fill, Task, alignment};
|
||||
use rand::seq::SliceRandom;
|
||||
use crate::jl_button;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct QuizState {
|
||||
@@ -82,7 +83,7 @@ impl NavigatedPage<QuizMessage> for QuizState {
|
||||
.width(150)
|
||||
.on_input(ContentChanged),
|
||||
score_display(&self.score),
|
||||
button("Закончить").style(jl_button).on_press(Back),
|
||||
jl_button!("Закончить").on_press(Back),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.align_x(alignment::Horizontal::Center),
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::navigation::RootMessage;
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::pages::randomizer::RandomizerMessage::{Back, Edit, Start};
|
||||
use crate::styling::{HALF_SPACING, back_overlay, jl_button};
|
||||
use crate::styling::{HALF_SPACING, back_overlay};
|
||||
use crate::jl_button;
|
||||
use iced::Task;
|
||||
use iced::widget::{button, text_editor};
|
||||
use iced::widget::text_editor;
|
||||
use rand::prelude::SliceRandom;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -56,7 +57,7 @@ impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
||||
.width(400)
|
||||
.height(400)
|
||||
.placeholder("Каждый элемент с новой строки"),
|
||||
button("Перемешать").style(jl_button).on_press(Start),
|
||||
jl_button!("Перемешать").on_press(Start),
|
||||
]
|
||||
.spacing(HALF_SPACING)
|
||||
.into(),
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::pages::repetitions::DeckRunData;
|
||||
use crate::jl_button;
|
||||
use crate::styling::*;
|
||||
use crate::{push_error, push_error_task};
|
||||
use iced::alignment::Horizontal::Center;
|
||||
@@ -255,8 +256,7 @@ impl RepetitionState {
|
||||
}
|
||||
|
||||
fn draw_voice(&self) -> Element<'_, RepetitionMessage> {
|
||||
button("Воспроизвести")
|
||||
.style(jl_button)
|
||||
jl_button!("Воспроизвести")
|
||||
.on_press(RepetitionMessage::Play)
|
||||
.into()
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::notification::MaybeError;
|
||||
use crate::pages::repetition_settings::RepetitionSettingsMessage::*;
|
||||
use crate::jl_button;
|
||||
use crate::styling::*;
|
||||
use crate::{push_error, push_error_task};
|
||||
use iced::widget::button::danger;
|
||||
@@ -163,8 +164,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
||||
primary
|
||||
})
|
||||
.on_input(SetFilter),
|
||||
button("Проверить фильтр")
|
||||
.style(jl_button)
|
||||
jl_button!("Проверить фильтр")
|
||||
.on_press(TryFilter),
|
||||
self.count_view(),
|
||||
]
|
||||
@@ -180,7 +180,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
||||
)
|
||||
.height(Fill),
|
||||
row![
|
||||
button("Сохранить").style(jl_button).on_press(Save),
|
||||
jl_button!("Сохранить").on_press(Save),
|
||||
horizontal(),
|
||||
button(if self.real_delete_states {
|
||||
"Вы уверены?"
|
||||
|
||||
@@ -12,6 +12,7 @@ use crate::pages::repetition_settings::RepetitionSettingsState;
|
||||
use crate::pages::repetitions::RepetitionsMessage::*;
|
||||
use crate::push_error;
|
||||
use crate::push_error_task;
|
||||
use crate::jl_button;
|
||||
use crate::styling::*;
|
||||
use chrono::{Days, Local, Utc};
|
||||
use hashbrown::HashSet;
|
||||
@@ -227,8 +228,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
||||
row![
|
||||
column![
|
||||
scrollable(self.decks_list()).height(Fill),
|
||||
button("Добавить")
|
||||
.style(jl_button)
|
||||
jl_button!("Добавить")
|
||||
.width(Fill)
|
||||
.on_press(CreateSet),
|
||||
]
|
||||
@@ -331,8 +331,7 @@ impl RepetitionsState {
|
||||
column![
|
||||
text!("Фильтр"),
|
||||
text_input("", &deck.filter).on_input(SetFilter),
|
||||
button("Проверить фильтр")
|
||||
.style(jl_button)
|
||||
jl_button!("Проверить фильтр")
|
||||
.on_press(TryFilter),
|
||||
self.count_view(deck),
|
||||
]
|
||||
@@ -361,7 +360,7 @@ impl RepetitionsState {
|
||||
Some(deck.open_mode),
|
||||
SetOpenMode
|
||||
),
|
||||
button("История").style(jl_button).on_press(GoToHistory),
|
||||
jl_button!("История").on_press(GoToHistory),
|
||||
]
|
||||
.spacing(HALF_SPACING)
|
||||
}
|
||||
@@ -378,7 +377,7 @@ impl RepetitionsState {
|
||||
)
|
||||
.height(Fill),
|
||||
row![
|
||||
button("Сохранить").style(jl_button).on_press(Save),
|
||||
jl_button!("Сохранить").on_press(Save),
|
||||
self.launch_delete_button(deck)
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
|
||||
@@ -18,6 +18,7 @@ use iced_core::Background;
|
||||
use iced_core::Color;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use crate::jl_button;
|
||||
|
||||
pub struct SelectorState {
|
||||
pub set: KanaSet,
|
||||
@@ -81,9 +82,8 @@ impl NavigatedPage<SelectorMessage> for SelectorState {
|
||||
container(
|
||||
iced::widget::column![
|
||||
row![
|
||||
button("あ ↔ ア")
|
||||
.on_press(SelectorMessage::Change)
|
||||
.style(jl_button),
|
||||
jl_button!("あ ↔ ア")
|
||||
.on_press(SelectorMessage::Change),
|
||||
button("Словарь")
|
||||
.on_press(SelectorMessage::ToDictionary)
|
||||
.style(Self::nav_style),
|
||||
|
||||
+6
-8
@@ -6,6 +6,7 @@ use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::notification::{NotificationData, NotificationRequest};
|
||||
use crate::pages::sync::SyncMessage::*;
|
||||
use crate::jl_button;
|
||||
use crate::styling::*;
|
||||
use crate::{push_error, push_error_task};
|
||||
use iced::widget::button::danger;
|
||||
@@ -221,14 +222,13 @@ impl SyncState {
|
||||
.padding(3)
|
||||
)
|
||||
.style(rounded_box),
|
||||
button("Скопировать в буфер обмена")
|
||||
.style(jl_button)
|
||||
jl_button!("Скопировать в буфер обмена")
|
||||
.on_press(CopyKey)
|
||||
.width(Fill),
|
||||
row![
|
||||
button("↑ Отправить").style(jl_button).on_press(Send),
|
||||
jl_button!("↑ Отправить").on_press(Send),
|
||||
space().width(Fill),
|
||||
button("↓ Скачать").style(jl_button).on_press(GetLast)
|
||||
jl_button!("↓ Скачать").on_press(GetLast)
|
||||
]
|
||||
.spacing(DEFAULT_SPACING),
|
||||
toggler(self.auto_fetch)
|
||||
@@ -241,11 +241,9 @@ impl SyncState {
|
||||
]
|
||||
} else {
|
||||
column![
|
||||
button("Создать сохранение")
|
||||
.style(jl_button)
|
||||
jl_button!("Создать сохранение")
|
||||
.on_press(InitSync),
|
||||
button("Вставить ключ из буфера")
|
||||
.style(jl_button)
|
||||
jl_button!("Вставить ключ из буфера")
|
||||
.on_press(GetKey),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::core::kana_set::KanaSet;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::jl_button;
|
||||
use crate::styling::*;
|
||||
use iced::widget::*;
|
||||
use iced::{Element, Fill, Task, alignment};
|
||||
@@ -45,11 +46,9 @@ impl NavigatedPage<WritingMessage> for WritingState {
|
||||
text!("{}", self.kana).size(48),
|
||||
self.answers(),
|
||||
row![
|
||||
button(text!("{}", self.next_text))
|
||||
.style(jl_button)
|
||||
jl_button!(text!("{}", self.next_text))
|
||||
.on_press(WritingMessage::Next),
|
||||
button("Закончить")
|
||||
.style(jl_button)
|
||||
jl_button!("Закончить")
|
||||
.on_press(WritingMessage::Back),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
|
||||
+10
-3
@@ -1,7 +1,7 @@
|
||||
use iced::Element;
|
||||
use iced::border::Radius;
|
||||
use iced::widget::button::*;
|
||||
use iced::widget::{button, container};
|
||||
use iced::widget::container;
|
||||
use iced_core::Length::Fill;
|
||||
use iced_core::alignment::Horizontal::Left;
|
||||
use iced_core::{Border, Theme};
|
||||
@@ -14,7 +14,7 @@ pub const BUTTON_RADIUS: f32 = 8.0;
|
||||
|
||||
pub const SETTINGS_ICON: &[u8] = include_bytes!("../settings_icon.svg");
|
||||
|
||||
pub fn jl_button(theme: &Theme, status: Status) -> Style {
|
||||
pub fn jl_button_style(theme: &Theme, status: Status) -> Style {
|
||||
let mut style = primary(theme, status);
|
||||
style.border = Border {
|
||||
color: Default::default(),
|
||||
@@ -30,10 +30,17 @@ pub fn cta_button(theme: &Theme, status: Status) -> Style {
|
||||
style
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! jl_button {
|
||||
($content:expr) => {
|
||||
iced::widget::button($content).style($crate::styling::jl_button_style)
|
||||
};
|
||||
}
|
||||
|
||||
pub fn back_overlay<'a, T: Clone + 'a>(content: Element<'a, T>, back_message: T) -> Element<'a, T> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
button("Назад").style(jl_button).on_press(back_message),
|
||||
jl_button!("Назад").on_press(back_message),
|
||||
content
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
|
||||
Reference in new issue
Block a user