Skip to content

Commit

Permalink
Migrate theme to new data types
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Feb 29, 2024
1 parent 56cc79d commit fd02589
Show file tree
Hide file tree
Showing 45 changed files with 669 additions and 590 deletions.
4 changes: 2 additions & 2 deletions src/interface/cursor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ impl MouseCursor {
Grabbed::Texture(texture) => renderer.render_sprite(
render_target,
texture,
mouse_position - ScreenSize::uniform(15.0 * *interface_settings.scaling),
ScreenSize::uniform(30.0 * *interface_settings.scaling),
mouse_position - ScreenSize::uniform(15.0 * interface_settings.scaling.get()),
ScreenSize::uniform(30.0 * interface_settings.scaling.get()),
ScreenClip::default(),
Color::monochrome(255),
false,
Expand Down
22 changes: 11 additions & 11 deletions src/interface/elements/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> ElementRenderer<'a> {

pub fn get_text_dimensions(&self, text: &str, font_size: f32, available_width: f32) -> Vector2<f32> {
self.renderer
.get_text_dimensions(text, font_size * *self.interface_settings.scaling, available_width)
.get_text_dimensions(text, font_size * self.interface_settings.scaling.get(), available_width)
}

pub fn set_scroll(&mut self, scroll: f32) {
Expand All @@ -55,7 +55,7 @@ impl<'a> ElementRenderer<'a> {
self.position,
self.size,
self.screen_clip,
corner_radius * *self.interface_settings.scaling,
corner_radius * self.interface_settings.scaling.get(),
color,
);
}
Expand All @@ -66,7 +66,7 @@ impl<'a> ElementRenderer<'a> {
self.position + position,
size,
self.screen_clip,
corner_radius * *self.interface_settings.scaling,
corner_radius * self.interface_settings.scaling.get(),
color,
);
}
Expand All @@ -75,18 +75,18 @@ impl<'a> ElementRenderer<'a> {
self.renderer.render_text(
self.render_target,
text,
self.position + offset * *self.interface_settings.scaling,
self.position + offset * self.interface_settings.scaling.get(),
self.screen_clip,
foreground_color,
font_size * *self.interface_settings.scaling,
font_size * self.interface_settings.scaling.get(),
)
}

pub fn render_checkbox(&mut self, offset: ScreenPosition, size: ScreenSize, color: Color, checked: bool) {
self.renderer.render_checkbox(
self.render_target,
self.position + offset * *self.interface_settings.scaling,
size * *self.interface_settings.scaling,
self.position + offset * self.interface_settings.scaling.get(),
size * self.interface_settings.scaling.get(),
self.screen_clip,
color,
checked,
Expand All @@ -96,8 +96,8 @@ impl<'a> ElementRenderer<'a> {
pub fn render_expand_arrow(&mut self, offset: ScreenPosition, size: ScreenSize, color: Color, expanded: bool) {
self.renderer.render_expand_arrow(
self.render_target,
self.position + offset * *self.interface_settings.scaling,
size * *self.interface_settings.scaling,
self.position + offset * self.interface_settings.scaling.get(),
size * self.interface_settings.scaling.get(),
self.screen_clip,
color,
expanded,
Expand All @@ -108,8 +108,8 @@ impl<'a> ElementRenderer<'a> {
self.renderer.render_sprite(
self.render_target,
texture,
self.position + offset * *self.interface_settings.scaling,
size * *self.interface_settings.scaling,
self.position + offset * self.interface_settings.scaling.get(),
size * self.interface_settings.scaling.get(),
self.screen_clip,
color,
false,
Expand Down
17 changes: 6 additions & 11 deletions src/interface/elements/buttons/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,17 @@ impl Element for CloseButton {
.element_renderer(render_target, renderer, interface_settings, parent_position, screen_clip);

let background_color = match self.is_element_self(hovered_element) || self.is_element_self(focused_element) {
true => *theme.close_button.hovered_background_color,
false => *theme.close_button.background_color,
true => theme.close_button.hovered_background_color.get(),
false => theme.close_button.background_color.get(),
};

renderer.render_background((*theme.close_button.corner_radius).into(), background_color);

let text_position = ScreenPosition {
left: theme.close_button.text_offset.x,
top: theme.close_button.text_offset.y,
};
renderer.render_background((theme.close_button.corner_radius.get()).into(), background_color);

renderer.render_text(
"X",
text_position,
*theme.close_button.foreground_color,
*theme.close_button.font_size,
theme.close_button.text_offset.get(),
theme.close_button.foreground_color.get(),
theme.close_button.font_size.get(),
);
}
}
24 changes: 12 additions & 12 deletions src/interface/elements/buttons/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,30 @@ impl<T: AsRef<str> + 'static, E: ElementEvent> Element for Button<T, E> {

let disabled = self.is_disabled();
let background_color = match self.is_element_self(hovered_element) || self.is_element_self(focused_element) {
_ if disabled => *theme.button.disabled_background_color,
true => *theme.button.hovered_background_color,
_ if disabled => theme.button.disabled_background_color.get(),
true => theme.button.hovered_background_color.get(),
false if self.background_color.is_some() => (self.background_color.as_ref().unwrap())(theme),
false => *theme.button.background_color,
false => theme.button.background_color.get(),
};

renderer.render_background((*theme.button.corner_radius).into(), background_color);
renderer.render_background(theme.button.corner_radius.get(), background_color);

if let Some(text) = &self.text {
let foreground_color = if disabled {
*theme.button.disabled_foreground_color
theme.button.disabled_foreground_color.get()
} else {
self.foreground_color
.as_ref()
.map(|closure| closure(theme))
.unwrap_or(*theme.button.foreground_color)
.unwrap_or(theme.button.foreground_color.get())
};

let text_position = ScreenPosition {
left: theme.button.text_offset.x,
top: theme.button.text_offset.y,
};

renderer.render_text(text.as_ref(), text_position, foreground_color, *theme.button.font_size);
renderer.render_text(
text.as_ref(),
theme.button.text_offset.get(),
foreground_color,
theme.button.font_size.get(),
);
}
}
}
16 changes: 7 additions & 9 deletions src/interface/elements/buttons/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,17 @@ impl Element for DragButton {
.element_renderer(render_target, renderer, interface_settings, parent_position, screen_clip);

if self.is_element_self(hovered_element) {
renderer.render_background((*theme.window.title_corner_radius).into(), *theme.window.title_background_color);
renderer.render_background(
(theme.window.title_corner_radius.get()).into(),
theme.window.title_background_color.get(),
);
}

let text_position = ScreenPosition {
left: theme.window.text_offset.x,
top: theme.window.text_offset.y,
};

renderer.render_text(
&self.window_title,
text_position,
*theme.window.foreground_color,
*theme.window.font_size,
theme.window.text_offset.get(),
theme.window.foreground_color.get(),
theme.window.font_size.get(),
);
}
}
36 changes: 13 additions & 23 deletions src/interface/elements/buttons/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,42 +124,32 @@ where

if !self.transparent_background {
let background_color = match highlighted {
true => *theme.button.hovered_background_color,
false => *theme.button.background_color,
true => theme.button.hovered_background_color.get(),
false => theme.button.background_color.get(),
};

renderer.render_background((*theme.button.corner_radius).into(), background_color);
renderer.render_background(theme.button.corner_radius.get(), background_color);
}

let foreground_color = match self.transparent_background && highlighted {
true => *theme.button.hovered_foreground_color,
false => *theme.button.foreground_color,
};

let box_position = ScreenPosition {
left: theme.button.icon_offset.x,
top: theme.button.icon_offset.y,
};

let box_size = ScreenSize {
width: theme.button.icon_size.x,
height: theme.button.icon_size.y,
true => theme.button.hovered_foreground_color.get(),
false => theme.button.foreground_color.get(),
};

renderer.render_checkbox(
box_position,
box_size,
theme.button.icon_offset.get(),
theme.button.icon_size.get(),
foreground_color,
(self.selector.as_ref().unwrap())(state_provider),
);

if let Some(text) = &self.text {
let text_position = ScreenPosition {
left: theme.button.icon_text_offset.x,
top: theme.button.icon_text_offset.y,
};

renderer.render_text(text.as_ref(), text_position, foreground_color, *theme.button.font_size);
renderer.render_text(
text.as_ref(),
theme.button.icon_text_offset.get(),
foreground_color,
theme.button.font_size.get(),
);
}
}
}
10 changes: 5 additions & 5 deletions src/interface/elements/containers/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl CharacterPreview {
Button::default()
.with_text("Delete")
.with_event(UserEvent::DeleteCharacter(character_information.character_id))
.with_background_color(|theme| *theme.close_button.background_color)
.with_foreground_color(|theme| *theme.close_button.foreground_color)
.with_background_color(|theme| theme.close_button.background_color.get())
.with_foreground_color(|theme| theme.close_button.foreground_color.get())
.with_width(dimension!(50%))
.wrap(),
];
Expand Down Expand Up @@ -180,11 +180,11 @@ impl Element for CharacterPreview {
.element_renderer(render_target, renderer, interface_settings, parent_position, screen_clip);

let background_color = match self.is_element_self(hovered_element) || self.is_element_self(focused_element) {
true => *theme.button.hovered_background_color,
false => *theme.button.background_color,
true => theme.button.hovered_background_color.get(),
false => theme.button.background_color.get(),
};

renderer.render_background((*theme.button.corner_radius).into(), background_color);
renderer.render_background(theme.button.corner_radius.get(), background_color);

self.state.render(
&mut renderer,
Expand Down
68 changes: 26 additions & 42 deletions src/interface/elements/containers/expandable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Element for Expandable {
.resolve_partial(
placement_resolver.get_available(),
placement_resolver.get_remaining(),
*interface_settings.scaling,
interface_settings.scaling.get(),
)
.finalize();

Expand All @@ -72,22 +72,11 @@ impl Element for Expandable {
};

if self.expanded && !self.state.elements.is_empty() {
let screen_position = ScreenPosition::only_top(closed_size.height)
+ ScreenPosition {
left: theme.expandable.element_offset.x,
top: theme.expandable.element_offset.y,
} * *interface_settings.scaling;

let screen_size = ScreenSize {
width: theme.expandable.border_size.x,
height: theme.expandable.border_size.y,
};

let mut inner_placement_resolver = placement_resolver.derive(size, screen_position, screen_size);
inner_placement_resolver.set_gaps(ScreenSize {
width: theme.expandable.gaps.x,
height: theme.expandable.gaps.y,
});
let screen_position =
ScreenPosition::only_top(closed_size.height) + theme.expandable.element_offset.get() * interface_settings.scaling.get();

let mut inner_placement_resolver = placement_resolver.derive(size, screen_position, theme.expandable.border_size.get());
inner_placement_resolver.set_gaps(theme.expandable.gaps.get());

self.state.elements.iter_mut().for_each(|element| {
element
Expand All @@ -98,14 +87,14 @@ impl Element for Expandable {
if self.open_size_constraint.height.is_flexible() {
let final_height = inner_placement_resolver.final_height()
+ closed_size.height
+ theme.expandable.element_offset.y * *interface_settings.scaling
+ theme.expandable.border_size.y * *interface_settings.scaling * 2.0;
+ theme.expandable.element_offset.get().top * interface_settings.scaling.get()
+ theme.expandable.border_size.get().height * interface_settings.scaling.get() * 2.0;

let final_height = self.open_size_constraint.validated_height(
final_height,
placement_resolver.get_available().height,
placement_resolver.get_available().height,
*interface_settings.scaling,
interface_settings.scaling.get(),
);

size.height = Some(final_height);
Expand Down Expand Up @@ -178,35 +167,30 @@ impl Element for Expandable {
.element_renderer(render_target, renderer, interface_settings, parent_position, screen_clip);

let background_color = match second_theme {
true => *theme.expandable.second_background_color,
false => *theme.expandable.background_color,
};

renderer.render_background((*theme.button.corner_radius).into(), background_color);

let arrow_position = ScreenPosition {
left: theme.expandable.icon_offset.x,
top: theme.expandable.icon_offset.y,
true => theme.expandable.second_background_color.get(),
false => theme.expandable.background_color.get(),
};

let arrow_size = ScreenSize {
width: theme.expandable.icon_size.x,
height: theme.expandable.icon_size.y,
};
renderer.render_background(theme.button.corner_radius.get(), background_color);

renderer.render_expand_arrow(arrow_position, arrow_size, *theme.expandable.foreground_color, self.expanded);
renderer.render_expand_arrow(
theme.expandable.icon_offset.get(),
theme.expandable.icon_size.get(),
theme.expandable.foreground_color.get(),
self.expanded,
);

let foreground_color = match self.is_element_self(hovered_element) || self.is_element_self(focused_element) {
true => *theme.expandable.hovered_foreground_color,
false => *theme.expandable.foreground_color,
};

let text_position = ScreenPosition {
left: theme.expandable.text_offset.x,
top: theme.expandable.text_offset.y,
true => theme.expandable.hovered_foreground_color.get(),
false => theme.expandable.foreground_color.get(),
};

renderer.render_text(&self.display, text_position, foreground_color, *theme.expandable.font_size);
renderer.render_text(
&self.display,
theme.expandable.text_offset.get(),
foreground_color,
theme.expandable.font_size.get(),
);

if self.expanded && !self.state.elements.is_empty() {
self.state.render(
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ContainerState {
final_height,
placement_resolver.get_available().height,
placement_resolver.get_available().height,
*interface_settings.scaling,
interface_settings.scaling.get(),
);
size.height = Some(final_height);
placement_resolver.register_height(final_height);
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Element for ScrollView {
.element_renderer(render_target, renderer, interface_settings, parent_position, screen_clip);

if let Some(color_selector) = &self.background_color {
renderer.render_background((*theme.button.corner_radius).into(), color_selector(theme));
renderer.render_background(theme.button.corner_radius.get(), color_selector(theme));
}

renderer.set_scroll(self.scroll);
Expand Down
Loading

0 comments on commit fd02589

Please sign in to comment.