Skip to content

Commit

Permalink
Further cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Apr 15, 2024
1 parent 9e8b44e commit 3c25046
Show file tree
Hide file tree
Showing 51 changed files with 149 additions and 166 deletions.
2 changes: 1 addition & 1 deletion korangar/src/graphics/renderers/deferred/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
#[cfg(feature = "debug")]
use cgmath::SquareMatrix;
use cgmath::{Matrix4, Vector2, Vector3};
use korangar_interface::settings::FontSizeTrait;
use korangar_interface::application::FontSizeTrait;
use korangar_procedural::profile;
use vulkano::device::{DeviceOwned, Queue};
use vulkano::format::Format;
Expand Down
4 changes: 2 additions & 2 deletions korangar/src/graphics/renderers/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;

use korangar_interface::settings::Application;
use korangar_interface::application::Application;
use korangar_procedural::profile;
use vulkano::device::{DeviceOwned, Queue};
use vulkano::format::{ClearColorValue, Format};
Expand Down Expand Up @@ -138,7 +138,7 @@ impl InterfaceRenderer {
}
}

impl korangar_interface::traits::InterfaceRenderer<Adapter> for InterfaceRenderer {
impl korangar_interface::application::InterfaceRenderer<Adapter> for InterfaceRenderer {
type Target = <Self as Renderer>::Target;

fn get_text_dimensions(
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ mod mode;
use std::mem::variant_count;

use cgmath::Vector2;
use korangar_interface::application::FocusState;
use korangar_interface::elements::{ElementCell, Focus};
use korangar_interface::event::ClickAction;
use korangar_interface::state::{RawTrackedState, TrackedState};
use korangar_interface::traits::FocusState;
use korangar_interface::Interface;
use korangar_procedural::profile;
use winit::dpi::PhysicalPosition;
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/input/mode.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use cgmath::Vector2;
use korangar_interface::application::MouseInputModeTrait;
use korangar_interface::elements::{Element, ElementCell};
use korangar_interface::settings::MouseInputModeTrait;
use vulkano::image::view::ImageView;

use crate::interface::application::Adapter;
Expand Down
14 changes: 7 additions & 7 deletions korangar/src/interface/application.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::marker::ConstParamTy;

use korangar_interface::application::{Application, ScalingTrait};
use korangar_interface::elements::{Container, ElementCell, ElementWrap, PickList, PrototypeElement, Text};
use korangar_interface::event::ClickAction;
use korangar_interface::settings::{Application, ScalingTrait};
use korangar_interface::state::{RawTrackedState, TrackedStateClone};
use korangar_interface::windows::PrototypeWindow;
use korangar_procedural::{dimension_bound, profile, PrototypeElement};
Expand All @@ -19,14 +19,14 @@ use crate::graphics::{Color, InterfaceRenderer};
use crate::input::{MouseInputMode, UserEvent};
use crate::loaders::{FontLoader, FontSize, Scaling};

impl korangar_interface::traits::ColorTrait for Color {
impl korangar_interface::application::ColorTrait for Color {
fn is_transparent(&self) -> bool {
const TRANSPARENCY_THRESHOLD: f32 = 0.999;
self.alpha < TRANSPARENCY_THRESHOLD
}
}

impl korangar_interface::traits::SizeTrait for ScreenSize {
impl korangar_interface::application::SizeTrait for ScreenSize {
fn new(width: f32, height: f32) -> Self {
ScreenSize { width, height }
}
Expand All @@ -40,7 +40,7 @@ impl korangar_interface::traits::SizeTrait for ScreenSize {
}
}

impl korangar_interface::traits::PositionTrait for ScreenPosition {
impl korangar_interface::application::PositionTrait for ScreenPosition {
fn new(left: f32, top: f32) -> Self {
ScreenPosition { left, top }
}
Expand All @@ -54,7 +54,7 @@ impl korangar_interface::traits::PositionTrait for ScreenPosition {
}
}

impl korangar_interface::traits::ClipTrait for ScreenClip {
impl korangar_interface::application::ClipTrait for ScreenClip {
fn new(left: f32, top: f32, right: f32, bottom: f32) -> Self {
Self { left, right, top, bottom }
}
Expand All @@ -76,7 +76,7 @@ impl korangar_interface::traits::ClipTrait for ScreenClip {
}
}

impl korangar_interface::traits::CornerRadiusTrait for CornerRadius {
impl korangar_interface::application::CornerRadiusTrait for CornerRadius {
fn new(top_left: f32, top_right: f32, bottom_right: f32, bottom_left: f32) -> Self {
Self {
top_left,
Expand All @@ -103,7 +103,7 @@ impl korangar_interface::traits::CornerRadiusTrait for CornerRadius {
}
}

impl korangar_interface::traits::PartialSizeTrait for PartialScreenSize {
impl korangar_interface::application::PartialSizeTrait for PartialScreenSize {
fn new(width: f32, height: Option<f32>) -> Self {
Self { width, height }
}
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/elements/containers/character.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::cell::RefCell;
use std::rc::Weak;

use korangar_interface::application::FontSizeTrait;
use korangar_interface::elements::{ButtonBuilder, ContainerState, Element, ElementCell, ElementState, ElementWrap, Focus, Text};
use korangar_interface::event::{ChangeEvent, ClickAction, HoverInformation};
use korangar_interface::layout::PlacementResolver;
use korangar_interface::settings::FontSizeTrait;
use korangar_interface::state::{RawRemote, Remote};
use korangar_procedural::{dimension_bound, size_bound};

Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/elements/miscellanious/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ mod builder;
use std::cell::RefCell;
use std::rc::Rc;

use korangar_interface::application::{Application, FontSizeTraitExt};
use korangar_interface::elements::{Element, ElementState};
use korangar_interface::event::ChangeEvent;
use korangar_interface::layout::{Dimension, PlacementResolver};
use korangar_interface::settings::{Application, FontSizeTraitExt};
use korangar_interface::state::{RawRemote, Remote};
use korangar_procedural::size_bound;

Expand Down
3 changes: 1 addition & 2 deletions korangar/src/interface/elements/miscellanious/item.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use derive_new::new;
use korangar_interface::application::{FontSizeTrait, SizeTraitExt};
use korangar_interface::elements::{Element, ElementState};
use korangar_interface::event::{ClickAction, HoverInformation};
use korangar_interface::layout::PlacementResolver;
use korangar_interface::settings::FontSizeTrait;
use korangar_interface::traits::SizeTraitExt;
use korangar_procedural::size_bound;

use crate::graphics::{Color, InterfaceRenderer, Renderer, SpriteRenderer};
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/elements/miscellanious/skill.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use derive_new::new;
use korangar_interface::application::FontSizeTrait;
use korangar_interface::elements::{Element, ElementState};
use korangar_interface::event::{ClickAction, HoverInformation};
use korangar_interface::layout::PlacementResolver;
use korangar_interface::settings::FontSizeTrait;
use korangar_procedural::size_bound;

use crate::graphics::{Color, InterfaceRenderer, Renderer};
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/elements/profiler/frame.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use korangar_interface::application::FontSizeTrait;
use korangar_interface::elements::{Element, ElementState};
use korangar_interface::event::{ChangeEvent, ClickAction, HoverInformation};
use korangar_interface::layout::PlacementResolver;
use korangar_interface::settings::FontSizeTrait;
use korangar_interface::state::{RawRemote, Remote};
use korangar_procedural::size_bound;

Expand Down
6 changes: 3 additions & 3 deletions korangar/src/interface/elements/profiler/inspector.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::time::{Duration, Instant};

use derive_new::new;
use korangar_interface::application::FontSizeTrait;
use korangar_interface::elements::{Element, ElementRenderer, ElementState};
use korangar_interface::event::{ChangeEvent, HoverInformation};
use korangar_interface::layout::PlacementResolver;
use korangar_interface::settings::FontSizeTrait;
use korangar_procedural::size_bound;

use crate::debug::*;
Expand Down Expand Up @@ -76,7 +76,7 @@ impl FrameInspectorView {
top: size.height - theme.profiler.distance_text_offset.get() * renderer.application.get_scaling_factor(),
};

korangar_interface::traits::InterfaceRenderer::render_text(
korangar_interface::application::InterfaceRenderer::render_text(
renderer.renderer,
renderer.render_target,
text,
Expand Down Expand Up @@ -157,7 +157,7 @@ impl FrameInspectorView {
}
+ text_offset;

korangar_interface::traits::InterfaceRenderer::render_text(
korangar_interface::application::InterfaceRenderer::render_text(
renderer.renderer,
renderer.render_target,
&text,
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/theme/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use korangar_interface::application::FontSizeTrait;
use korangar_interface::event::{Nothing, Render, Resolve};
use korangar_interface::layout::{DimensionBound, SizeBound};
use korangar_interface::settings::FontSizeTrait;
use korangar_procedural::{dimension_bound, size_bound, PrototypeElement, PrototypeWindow};
use ron::ser::PrettyConfig;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/windows/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl WindowCache {
}
}

impl korangar_interface::traits::WindowCache<Adapter> for WindowCache {
impl korangar_interface::application::WindowCache<Adapter> for WindowCache {
fn create() -> Self {
Self::load().unwrap_or_else(|| {
#[cfg(feature = "debug")]
Expand Down
8 changes: 4 additions & 4 deletions korangar/src/loaders/font/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use cgmath::{Array, Vector2};
use korangar_interface::application::FontSizeTrait;
use korangar_interface::elements::ElementDisplay;
use korangar_interface::settings::FontSizeTrait;
use rusttype::gpu_cache::Cache;
use rusttype::*;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -47,7 +47,7 @@ impl ElementDisplay for FontSize {
}
}

impl korangar_interface::settings::FontSizeTrait for FontSize {
impl korangar_interface::application::FontSizeTrait for FontSize {
fn new(value: f32) -> Self {
Self(value)
}
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Scaling {
}
}

impl korangar_interface::settings::ScalingTrait for Scaling {
impl korangar_interface::application::ScalingTrait for Scaling {
fn get_factor(&self) -> f32 {
self.0
}
Expand Down Expand Up @@ -334,7 +334,7 @@ impl FontLoader {
}
}

impl korangar_interface::settings::FontLoaderTrait<Adapter> for std::rc::Rc<std::cell::RefCell<FontLoader>> {
impl korangar_interface::application::FontLoaderTrait<Adapter> for std::rc::Rc<std::cell::RefCell<FontLoader>> {
fn get_text_dimensions(&self, text: &str, font_size: FontSize, available_width: f32) -> ScreenSize {
self.borrow().get_text_dimensions(text, font_size, available_width)
}
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/loaders/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::Arc;

use cgmath::{Matrix3, Matrix4, Quaternion, Rad, SquareMatrix, Vector2, Vector3};
use derive_new::new;
use korangar_interface::application::Application;
use korangar_interface::elements::{ElementCell, PrototypeElement};
use korangar_interface::settings::Application;
use korangar_procedural::PrototypeElement;
use ragnarok_bytes::{ByteStream, ConversionError, ConversionResult, ConversionResultExt, FromBytes, FromBytesExt};
use vulkano::image::view::ImageView;
Expand Down
3 changes: 1 addition & 2 deletions korangar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ use std::sync::Arc;
use cgmath::{Vector2, Vector3, Zero};
use image::io::Reader as ImageReader;
use image::{EncodableLayout, ImageFormat};
use korangar_interface::settings::{Application, FontSizeTrait, FontSizeTraitExt};
use korangar_interface::application::{Application, FocusState, FontSizeTrait, FontSizeTraitExt, PositionTraitExt};
use korangar_interface::state::{RawTrackedState, Remote, RemoteClone, TrackedState, TrackedStateVec};
use korangar_interface::traits::{FocusState, PositionTraitExt};
use korangar_interface::Interface;
use korangar_procedural::debug_condition;
use network::SkillType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,70 @@
use std::rc::{Rc, Weak};

use crate::elements::{ElementCell, WeakElementCell};
use crate::settings::{Application, ScalingTrait};
use crate::elements::{Element, ElementCell, WeakElementCell};
use crate::theme::InterfaceTheme;

pub trait Application: Sized + 'static {
type ThemeKind: Default;
type Theme: InterfaceTheme<Settings = Self>;
type Color: ColorTrait;
type Renderer: InterfaceRenderer<Self>;
type Size: SizeTrait;
type PartialSize: PartialSizeTrait;
type Position: PositionTrait;
type Clip: ClipTrait;
type CornerRadius: CornerRadiusTrait;
type FontSize: FontSizeTrait;
type Scaling: ScalingTrait;
type FontLoader: FontLoaderTrait<Self>;
type MouseInputMode: MouseInputModeTrait<Self>;
type Cache: WindowCache<Self>;
type DropResource;
type DropResult;
type CustomEvent;

fn get_scaling(&self) -> Self::Scaling;

fn get_theme(&self, kind: &Self::ThemeKind) -> &Self::Theme;
}

pub trait MouseInputModeTrait<App>
where
App: Application,
{
fn is_none(&self) -> bool;

fn is_self_dragged(&self, element: &dyn Element<App>) -> bool;
}

pub trait FontSizeTrait: Copy {
fn new(value: f32) -> Self;

fn get_value(&self) -> f32;
}

pub trait FontSizeTraitExt {
fn scaled(&self, scaling: impl ScalingTrait) -> Self;
}

impl<T> FontSizeTraitExt for T
where
T: FontSizeTrait,
{
fn scaled(&self, scaling: impl ScalingTrait) -> Self {
Self::new(self.get_value() * scaling.get_factor())
}
}

pub trait FontLoaderTrait<App>: Clone
where
App: Application,
{
fn get_text_dimensions(&self, text: &str, font_size: App::FontSize, available_width: f32) -> App::Size;
}

pub trait ScalingTrait: Copy {
fn get_factor(&self) -> f32;
}

pub trait InterfaceRenderer<App>
where
Expand Down Expand Up @@ -189,9 +252,9 @@ pub trait SizeTrait: Copy {
pub trait SizeTraitExt {
fn zero() -> Self;

// fn only_width(width: f32) -> Self;
fn only_width(width: f32) -> Self;

// fn from_position(position: impl PositionTrait) -> Self;
fn only_height(height: f32) -> Self;

fn grow(&self, growth: Self) -> Self;

Expand All @@ -214,14 +277,13 @@ where
Self::new(0.0, 0.0)
}

// fn only_width(width: f32) -> Self {
// Self::new(0.0, width)
// }
//
fn only_width(width: f32) -> Self {
Self::new(width, 0.0)
}

// fn from_position(position: impl PositionTrait) -> Self {
// Self::new(position.left(), position.top())
// }
fn only_height(height: f32) -> Self {
Self::new(0.0, height)
}

fn grow(&self, size: Self) -> Self {
Self::new(self.width() + size.width(), self.height() + size.height())
Expand Down
8 changes: 4 additions & 4 deletions korangar_interface/src/elements/base.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::cell::{Cell, RefCell};
use std::rc::{Rc, Weak};

use crate::application::{
Application, ClipTrait, CornerRadiusTraitExt, FontSizeTraitExt, InterfaceRenderer, PartialSizeTraitExt, PositionTrait,
PositionTraitExt, SizeTrait, SizeTraitExt,
};
use crate::event::{ChangeEvent, ClickAction, HoverInformation};
use crate::layout::{PlacementResolver, SizeBound};
use crate::settings::{Application, FontSizeTraitExt};
use crate::traits::{
ClipTrait, CornerRadiusTraitExt, InterfaceRenderer, PartialSizeTraitExt, PositionTrait, PositionTraitExt, SizeTrait, SizeTraitExt,
};

pub type ElementCell<App> = Rc<RefCell<dyn Element<App>>>;
pub type WeakElementCell<App> = Weak<RefCell<dyn Element<App>>>;
Expand Down
Loading

0 comments on commit 3c25046

Please sign in to comment.