Skip to content

Commit

Permalink
editor: rearrange file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
barsoosayque committed Nov 30, 2024
1 parent ab66b11 commit 4f3391c
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 41 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
mod file_dialogs;
mod package_tab;
mod package_tree;
mod question_tab;
mod round_tab;
mod theme_tab;
mod workarea;

use opensi_core::prelude::*;

use crate::{
file_dialogs::{self, LoadingPackageReceiver},
package_tree::{self},
workarea,
};
use crate::app::file_dialogs::LoadingPackageReceiver;

const FONT_REGULAR_ID: &'static str = "Regular";
const FONT_ITALIC_ID: &'static str = "Italic";
Expand All @@ -31,11 +35,11 @@ impl EditorApp {
let mut font_definitions = egui::FontDefinitions::default();
font_definitions.font_data.insert(
FONT_REGULAR_ID.into(),
egui::FontData::from_static(include_bytes!("../assets/ui/Lora-Medium.ttf")),
egui::FontData::from_static(include_bytes!("../../assets/ui/Lora-Medium.ttf")),
);
font_definitions.font_data.insert(
FONT_ITALIC_ID.into(),
egui::FontData::from_static(include_bytes!("../assets/ui/Lora-MediumItalic.ttf")),
egui::FontData::from_static(include_bytes!("../../assets/ui/Lora-MediumItalic.ttf")),
);
if let Some(family) = font_definitions.families.get_mut(&egui::FontFamily::Proportional) {
family.insert(0, FONT_REGULAR_ID.into());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use itertools::Itertools;
use opensi_core::prelude::*;

use crate::utils::{danger_button, simple_row, unselectable_heading, unselectable_label};
use crate::element::{danger_button, simple_row, unselectable_heading, unselectable_label};

/// Workarea tab to edit package info.
pub fn package_tab(package: &mut Package, selected: &mut Option<PackageNode>, ui: &mut egui::Ui) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use egui::collapsing_header::CollapsingState;
use opensi_core::prelude::*;

use crate::utils::node_name;
use crate::element::node_name;

/// Ui for a whole [`Package`] in a form of a tree.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use opensi_core::prelude::*;

use crate::utils::todo_label;
use crate::element::todo_label;

pub fn question_tab(_question: &mut Question, ui: &mut egui::Ui) {
todo_label(ui);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use opensi_core::prelude::*;

use crate::{
card::CardKind,
utils::{error_label, info_edit, simple_row, unselectable_heading, unselectable_label},
use crate::element::{
error_label, info_edit, simple_row, unselectable_heading, unselectable_label, Card,
};

/// Workarea tab to edit round info and its themes.
Expand Down Expand Up @@ -104,23 +103,23 @@ fn round_themes(
};

row.col(|ui| {
if CardKind::Theme(theme).show(ui).clicked() {
if ui.add(Card::Theme(theme)).clicked() {
*selected = Some(theme_idx.into());
}
});

for (question_index, question) in theme.questions.iter().enumerate()
{
row.col(|ui| {
if CardKind::Question(question).show(ui).clicked() {
if ui.add(Card::Question(question)).clicked() {
*selected =
Some(theme_idx.question(question_index).into());
}
});
}

row.col(|ui| {
if CardKind::New.show(ui).clicked() {
if ui.add(Card::New).clicked() {
theme.questions.push(Question {
price: theme.guess_next_question_price(),
..Default::default()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use opensi_core::prelude::*;

use crate::{
card::CardKind,
utils::{error_label, info_edit, simple_row, unselectable_heading},
};
use crate::element::{error_label, info_edit, simple_row, unselectable_heading, Card};

pub fn theme_tab(
package: &mut Package,
Expand Down Expand Up @@ -79,14 +76,14 @@ fn theme_questions(
.horizontal(|mut strip| {
for (question_index, question) in theme.questions.iter().enumerate() {
strip.cell(|ui| {
if CardKind::Question(question).show(ui).clicked() {
if ui.add(Card::Question(question)).clicked() {
*selected = Some(idx.question(question_index).into());
}
});
}

strip.cell(|ui| {
if CardKind::New.show(ui).clicked() {
if ui.add(Card::New).clicked() {
theme.questions.push(Question {
price: theme.guess_next_question_price(),
..Default::default()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
package_tab, question_tab, round_tab, theme_tab,
utils::{error_label, node_name},
};
use crate::app::{package_tab, question_tab, round_tab, theme_tab};
use crate::element::{error_label, node_name};

use opensi_core::prelude::*;

/// UI for general area of [`Package`] editing.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use opensi_core::prelude::*;

/// Rectangular cilckable card.
#[derive(Debug, Clone, Copy)]
pub enum CardKind<'a> {
pub enum Card<'a> {
Theme(&'a Theme),
Question(&'a Question),
New,
}

impl<'a> CardKind<'a> {
pub fn show(&self, ui: &mut egui::Ui) -> egui::Response {
impl<'a> egui::Widget for Card<'a> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
let (text, fill, text_color) = match self {
CardKind::Theme(theme) => (
Card::Theme(theme) => (
theme.name.clone(),
ui.visuals().widgets.active.bg_fill,
ui.visuals().widgets.active.text_color(),
),
CardKind::Question(question) => (
Card::Question(question) => (
question.price.to_string(),
egui::Color32::TRANSPARENT,
ui.visuals().widgets.inactive.text_color(),
),
CardKind::New => (
Card::New => (
"➕ Новый вопрос".to_string(),
egui::Color32::TRANSPARENT,
ui.visuals().weak_text_color(),
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions crates/opensi-editor/src/element/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod card;
pub mod common;

pub use card::Card;
pub use common::*;
10 changes: 1 addition & 9 deletions crates/opensi-editor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#![warn(clippy::all)]

mod app;
mod card;
mod file_dialogs;
mod package_tab;
mod package_tree;
mod question_tab;
mod round_tab;
mod theme_tab;
mod utils;
mod workarea;
mod element;

pub use app::EditorApp;

0 comments on commit 4f3391c

Please sign in to comment.