Compare commits
3 commits
c5286a3340
...
95b66db697
Author | SHA1 | Date | |
---|---|---|---|
95b66db697 | |||
|
2a77856cb8 | ||
|
ac733ecdc7 |
25 changed files with 752 additions and 661 deletions
|
@ -116,24 +116,26 @@ impl ButtonBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn build(self, gui_handler: Arc<GuiHandler<'_>>) -> Result<Arc<Button<'_>>> {
|
||||
let framable = Framable::new(gui_handler.clone(), false)?;
|
||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<Button>> {
|
||||
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
|
||||
|
||||
let normal = FillType::new(
|
||||
gui_handler,
|
||||
framable.clone(),
|
||||
self.normal
|
||||
.ok_or(anyhow!("normal button layout not set!"))?,
|
||||
)?;
|
||||
|
||||
let selected = FillType::new(
|
||||
gui_handler,
|
||||
framable.clone(),
|
||||
self.selected
|
||||
.ok_or(anyhow!("selected button layout not set!"))?,
|
||||
)?;
|
||||
|
||||
let click_executable = Executable::new(&gui_handler);
|
||||
let select_executable = Executable::new(&gui_handler);
|
||||
let on_select_executable = Executable::new(&gui_handler);
|
||||
let click_executable = Executable::new();
|
||||
let select_executable = Executable::new();
|
||||
let on_select_executable = Executable::new();
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
let click_sound = self
|
||||
|
@ -150,7 +152,6 @@ impl ButtonBuilder {
|
|||
let clickable = Clickable::new(framable.clone(), click_executable.clone());
|
||||
|
||||
let selectable = Selectable::new(
|
||||
&gui_handler,
|
||||
click_executable.clone(),
|
||||
select_executable.clone(),
|
||||
on_select_executable.clone(),
|
||||
|
@ -183,10 +184,11 @@ impl ButtonBuilder {
|
|||
);
|
||||
|
||||
if !self.text.is_empty() {
|
||||
textable.set_text(&self.text, false)?;
|
||||
textable.set_text(gui_handler, &self.text, false)?;
|
||||
}
|
||||
|
||||
let iconizable = IconizableWrapper::new(
|
||||
gui_handler,
|
||||
framable.clone(),
|
||||
self.icon.map(IconBuilderType::Image),
|
||||
None,
|
||||
|
@ -194,6 +196,7 @@ impl ButtonBuilder {
|
|||
)?;
|
||||
|
||||
let info_icon = IconizableWrapper::new(
|
||||
gui_handler,
|
||||
framable.clone(),
|
||||
None,
|
||||
Some(IconizablePositioning {
|
||||
|
@ -253,10 +256,10 @@ pub enum ButtonSelectMode {
|
|||
Bigger,
|
||||
}
|
||||
|
||||
pub struct Button<'a> {
|
||||
pub struct Button {
|
||||
clickable: Arc<Clickable>,
|
||||
hoverable: Arc<Hoverable>,
|
||||
selectable: Arc<Selectable<'a>>,
|
||||
selectable: Arc<Selectable>,
|
||||
framable: Arc<Framable>,
|
||||
iconizable: IconizableWrapper,
|
||||
textable: TextableWrapper,
|
||||
|
@ -280,7 +283,7 @@ pub struct Button<'a> {
|
|||
visible: AtomicBool,
|
||||
}
|
||||
|
||||
impl<'a> Button<'a> {
|
||||
impl Button {
|
||||
pub fn builder() -> ButtonBuilder {
|
||||
ButtonBuilder {
|
||||
icon: None,
|
||||
|
@ -305,22 +308,23 @@ impl<'a> Button<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn select(&self) -> Result<()> {
|
||||
self.selectable.select()
|
||||
pub fn select(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.selectable.select(gui_handler)
|
||||
}
|
||||
|
||||
pub fn set_callback<F>(&self, callback: F)
|
||||
where
|
||||
F: Fn() -> Result<()> + Send + Sync + 'static,
|
||||
{
|
||||
self.click_executable.set_callback(move |_| callback());
|
||||
self.click_executable.set_callback(move |_, _| callback());
|
||||
}
|
||||
|
||||
pub fn set_select_callback<F>(&self, callback: F)
|
||||
where
|
||||
F: Fn(bool) -> Result<()> + Send + Sync + 'static,
|
||||
{
|
||||
self.on_select_executable.set_callback(callback);
|
||||
self.on_select_executable
|
||||
.set_callback(|_m, select| callback(select));
|
||||
}
|
||||
|
||||
pub fn set_custom_callback<F>(&self, callback: F)
|
||||
|
@ -330,46 +334,43 @@ impl<'a> Button<'a> {
|
|||
self.selectable.set_custom_callback(callback);
|
||||
}
|
||||
|
||||
pub fn set_text(&self, text: impl ToString) -> Result<()> {
|
||||
self.textable.set_text(text, self.visible())
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
|
||||
self.textable.set_text(gui_handler, text, self.visible())
|
||||
}
|
||||
|
||||
pub fn set_icon(&self, icon: &Arc<Image>) -> Result<()> {
|
||||
self.iconizable.set_icon(icon, self.visible())
|
||||
pub fn set_icon(&self, gui_handler: &mut GuiHandler, icon: &Arc<Image>) -> Result<()> {
|
||||
self.iconizable.set_icon(gui_handler, icon, self.visible())
|
||||
}
|
||||
|
||||
pub fn set_icon_margon(&self, margin: u32) -> Result<()> {
|
||||
self.iconizable.set_margin(margin)
|
||||
pub fn set_icon_margon(&self, gui_handler: &mut GuiHandler, margin: u32) -> Result<()> {
|
||||
self.iconizable.set_margin(gui_handler, margin)
|
||||
}
|
||||
|
||||
pub fn clear_icon(&self) -> Result<()> {
|
||||
self.iconizable.clear_icon(self.visible())
|
||||
pub fn clear_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.iconizable.clear_icon(gui_handler, self.visible())
|
||||
}
|
||||
|
||||
pub fn icon(&self) -> Result<Option<Arc<Image>>> {
|
||||
self.iconizable.icon()
|
||||
}
|
||||
|
||||
pub fn set_info_icon(&self, button: &Arc<Image>) -> Result<()> {
|
||||
self.info_icon.set_icon(button, self.visible())
|
||||
pub fn set_info_icon(&self, gui_handler: &mut GuiHandler, button: &Arc<Image>) -> Result<()> {
|
||||
self.info_icon.set_icon(gui_handler, button, self.visible())
|
||||
}
|
||||
|
||||
pub fn clear_info_icon(&self) -> Result<()> {
|
||||
self.info_icon.clear_icon(self.visible())
|
||||
pub fn clear_info_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.info_icon.clear_icon(gui_handler, self.visible())
|
||||
}
|
||||
|
||||
pub fn text(&self) -> Result<Option<String>> {
|
||||
self.textable.text()
|
||||
}
|
||||
|
||||
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
|
||||
self.textable.set_text_color(text_color)
|
||||
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
|
||||
self.textable.set_text_color(gui_handler, text_color)
|
||||
}
|
||||
|
||||
pub fn try_from(
|
||||
button_info: &ButtonInfo,
|
||||
gui_handler: &Arc<GuiHandler<'a>>,
|
||||
) -> Result<Arc<Self>> {
|
||||
pub fn try_from(gui_handler: &mut GuiHandler, button_info: &ButtonInfo) -> Result<Arc<Self>> {
|
||||
let mut button_builder = Button::builder()
|
||||
.set_select_mode(button_info.select_mode)
|
||||
.set_isolate(button_info.isolate);
|
||||
|
@ -420,13 +421,13 @@ impl<'a> Button<'a> {
|
|||
button_info.margin,
|
||||
);
|
||||
|
||||
let button = button_builder.build(gui_handler.clone())?;
|
||||
let button = button_builder.build(gui_handler)?;
|
||||
|
||||
Ok(button)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GuiElementTraits for Button<'a> {
|
||||
impl GuiElementTraits for Button {
|
||||
fn gridable(&self) -> Option<&dyn Gridable> {
|
||||
Some(self)
|
||||
}
|
||||
|
@ -435,36 +436,36 @@ impl<'a> GuiElementTraits for Button<'a> {
|
|||
Some(self)
|
||||
}
|
||||
|
||||
fn downcast<'b>(&'b self) -> Option<GuiElement<'b>> {
|
||||
fn downcast<'a>(&'a self) -> Option<GuiElement<'a>> {
|
||||
Some(GuiElement::Button(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Visibility for Button<'a> {
|
||||
impl Visibility for Button {
|
||||
fn visible(&self) -> bool {
|
||||
self.visible.load(SeqCst)
|
||||
}
|
||||
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()> {
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||
if visibility != self.visible.load(SeqCst) {
|
||||
self.visible.store(visibility, SeqCst);
|
||||
|
||||
if visibility {
|
||||
self.framable.add()?;
|
||||
self.selectable.add()?;
|
||||
self.hoverable.add()?;
|
||||
self.clickable.add()?;
|
||||
self.framable.add(gui_handler)?;
|
||||
self.selectable.add(gui_handler)?;
|
||||
self.hoverable.add(gui_handler)?;
|
||||
self.clickable.add(gui_handler)?;
|
||||
|
||||
self.textable.enable()?;
|
||||
self.iconizable.enable()?;
|
||||
self.info_icon.enable()?;
|
||||
self.textable.enable(gui_handler)?;
|
||||
self.iconizable.enable(gui_handler)?;
|
||||
self.info_icon.enable(gui_handler)?;
|
||||
|
||||
match *self.button_state.lock().unwrap() {
|
||||
ButtonState::Normal => self.normal.enable()?,
|
||||
ButtonState::Selected => self.selected.enable()?,
|
||||
ButtonState::Normal => self.normal.enable(gui_handler)?,
|
||||
ButtonState::Selected => self.selected.enable(gui_handler)?,
|
||||
}
|
||||
} else {
|
||||
self.disable_base()?;
|
||||
self.disable_base(gui_handler)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -472,9 +473,10 @@ impl<'a> Visibility for Button<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Gridable for Button<'a> {
|
||||
impl Gridable for Button {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -482,22 +484,23 @@ impl<'a> Gridable for Button<'a> {
|
|||
vert_align: VerticalAlign,
|
||||
hori_align: HorizontalAlign,
|
||||
) -> Result<()> {
|
||||
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
|
||||
self.framable
|
||||
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
|
||||
|
||||
self.normal.update_frame()?;
|
||||
self.selected.update_frame()?;
|
||||
self.textable.update()?;
|
||||
self.iconizable.update_frame()?;
|
||||
self.info_icon.update_frame()?;
|
||||
self.normal.update_frame(gui_handler)?;
|
||||
self.selected.update_frame(gui_handler)?;
|
||||
self.textable.update(gui_handler)?;
|
||||
self.iconizable.update_frame(gui_handler)?;
|
||||
self.info_icon.update_frame(gui_handler)?;
|
||||
|
||||
if self.select_mode == ButtonSelectMode::Bigger {
|
||||
self.modify_hovered_vbo()?;
|
||||
self.modify_hovered_vbo(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn selectable(&self) -> Option<&Arc<Selectable<'_>>> {
|
||||
fn selectable(&self) -> Option<&Arc<Selectable>> {
|
||||
Some(&self.selectable)
|
||||
}
|
||||
|
||||
|
@ -525,16 +528,8 @@ impl<'a> Gridable for Button<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for Button<'a> {
|
||||
fn drop(&mut self) {
|
||||
if self.visible.load(SeqCst) {
|
||||
self.disable_base().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private
|
||||
impl<'a> Button<'a> {
|
||||
impl Button {
|
||||
// fn create_hovered_changed_callback(button: Arc<Button>) -> Result<()> {
|
||||
// let button_weak = Arc::downgrade(&button);
|
||||
|
||||
|
@ -557,13 +552,13 @@ impl<'a> Button<'a> {
|
|||
// .set_hovered_changed_callback(Some(hovered_changed))
|
||||
// }
|
||||
|
||||
fn create_clicked_changed_callback(button: Arc<Button<'a>>) {
|
||||
fn create_clicked_changed_callback(button: Arc<Button>) {
|
||||
let button_weak = Arc::downgrade(&button);
|
||||
|
||||
let clicked_changed = Box::new(move || {
|
||||
let clicked_changed = Box::new(move |gui_handler| {
|
||||
if let Some(button) = button_weak.upgrade() {
|
||||
if button.clickable.clicked() {
|
||||
button.hoverable.set_hovered(false)?;
|
||||
button.hoverable.set_hovered(gui_handler, false)?;
|
||||
} else {
|
||||
// if let Some(displayable) = displayable_weak.upgrade() {
|
||||
// displayable.update_frame()?;
|
||||
|
@ -579,15 +574,15 @@ impl<'a> Button<'a> {
|
|||
.set_clicked_changed_callback(Some(clicked_changed));
|
||||
}
|
||||
|
||||
fn create_selected_changed_callback(button: Arc<Button<'a>>) {
|
||||
fn create_selected_changed_callback(button: Arc<Button>) {
|
||||
let button_weak = Arc::downgrade(&button);
|
||||
|
||||
let selected_changed = move |selected| {
|
||||
let selected_changed = move |(gui_handler, selected)| {
|
||||
if let Some(button) = button_weak.upgrade() {
|
||||
if selected {
|
||||
button.set_button_state(ButtonState::Selected)?;
|
||||
button.set_button_state(gui_handler, ButtonState::Selected)?;
|
||||
} else {
|
||||
button.set_button_state(ButtonState::Normal)?;
|
||||
button.set_button_state(gui_handler, ButtonState::Normal)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -597,7 +592,7 @@ impl<'a> Button<'a> {
|
|||
button.select_executable.set_callback(selected_changed);
|
||||
}
|
||||
|
||||
fn modify_hovered_vbo(&self) -> Result<()> {
|
||||
fn modify_hovered_vbo(&self, gui_handler: &GuiHandler) -> Result<()> {
|
||||
assert!(
|
||||
self.framable.is_framed(),
|
||||
"button frame needs to be defined before hovering can be calculated"
|
||||
|
@ -610,7 +605,7 @@ impl<'a> Button<'a> {
|
|||
let buffer = displayable.buffer();
|
||||
let mut frame = buffer.map_complete()?;
|
||||
|
||||
let ortho = self.framable.ortho();
|
||||
let ortho = gui_handler.ortho();
|
||||
let left = self.framable.left() as f32;
|
||||
let right = self.framable.right() as f32;
|
||||
let top = self.framable.top() as f32;
|
||||
|
@ -634,7 +629,7 @@ impl<'a> Button<'a> {
|
|||
let buffer = colorable.buffer();
|
||||
let mut frame = buffer.map_complete()?;
|
||||
|
||||
let ortho = self.framable.ortho();
|
||||
let ortho = gui_handler.ortho();
|
||||
let left = self.framable.left() as f32;
|
||||
let right = self.framable.right() as f32;
|
||||
let top = self.framable.top() as f32;
|
||||
|
@ -652,25 +647,29 @@ impl<'a> Button<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn disable_base(&self) -> Result<()> {
|
||||
self.framable.delete()?;
|
||||
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.framable.delete(gui_handler)?;
|
||||
|
||||
self.selectable.delete()?;
|
||||
self.hoverable.delete()?;
|
||||
self.clickable.delete()?;
|
||||
self.selectable.delete(gui_handler)?;
|
||||
self.hoverable.delete(gui_handler)?;
|
||||
self.clickable.delete(gui_handler)?;
|
||||
|
||||
self.textable.disable()?;
|
||||
self.iconizable.disable()?;
|
||||
self.info_icon.disable()?;
|
||||
self.textable.disable(gui_handler)?;
|
||||
self.iconizable.disable(gui_handler)?;
|
||||
self.info_icon.disable(gui_handler)?;
|
||||
|
||||
self.normal.disable()?;
|
||||
self.selected.disable()?;
|
||||
self.normal.disable(gui_handler)?;
|
||||
self.selected.disable(gui_handler)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_button_state(&self, button_state: ButtonState) -> Result<()> {
|
||||
fn set_button_state(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
button_state: ButtonState,
|
||||
) -> Result<()> {
|
||||
let mut current_button_state = self.button_state.lock().unwrap();
|
||||
|
||||
if button_state == *current_button_state {
|
||||
|
@ -682,16 +681,16 @@ impl<'a> Button<'a> {
|
|||
match button_state {
|
||||
ButtonState::Normal => {
|
||||
if self.visible() {
|
||||
self.normal.enable()?;
|
||||
self.normal.enable(gui_handler)?;
|
||||
}
|
||||
|
||||
self.selected.disable()?;
|
||||
self.selected.disable(gui_handler)?;
|
||||
}
|
||||
ButtonState::Selected => {
|
||||
self.normal.disable()?;
|
||||
self.normal.disable(gui_handler)?;
|
||||
|
||||
if self.visible() {
|
||||
self.selected.enable()?;
|
||||
self.selected.enable(gui_handler)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -700,8 +699,8 @@ impl<'a> Button<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for Button<'a> {
|
||||
type Target = Arc<Selectable<'a>>;
|
||||
impl Deref for Button {
|
||||
type Target = Arc<Selectable>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.selectable
|
||||
|
|
|
@ -7,8 +7,8 @@ use assetpath::AssetPath;
|
|||
use utilities::prelude::*;
|
||||
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -60,44 +60,52 @@ pub(crate) enum InnerFillType {
|
|||
}
|
||||
|
||||
impl InnerFillType {
|
||||
pub(crate) fn new(framable: Arc<Framable>, fill_type_info: FillTypeInfo) -> Result<Self> {
|
||||
pub(crate) fn new(
|
||||
gui_handler: &mut GuiHandler,
|
||||
framable: Arc<Framable>,
|
||||
fill_type_info: FillTypeInfo,
|
||||
) -> Result<Self> {
|
||||
match fill_type_info {
|
||||
FillTypeInfo::Element(descriptor, fill_type) => Ok(InnerFillType::Image(
|
||||
Displayable::new(framable, descriptor, fill_type)?,
|
||||
Displayable::new(gui_handler, framable, descriptor, fill_type)?,
|
||||
)),
|
||||
FillTypeInfo::Image(path) => Ok(InnerFillType::Image(Displayable::new(
|
||||
gui_handler,
|
||||
framable,
|
||||
path,
|
||||
DisplayableFillType::Expand,
|
||||
)?)),
|
||||
FillTypeInfo::Color(color, fill_type) => Ok(InnerFillType::Color(Colorable::new(
|
||||
framable, color, fill_type,
|
||||
gui_handler,
|
||||
framable,
|
||||
color,
|
||||
fill_type,
|
||||
)?)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn enable(&self) -> Result<()> {
|
||||
pub(crate) fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
match self {
|
||||
Self::Image(displayable) => displayable.add()?,
|
||||
Self::Color(colorable) => colorable.add()?,
|
||||
Self::Image(displayable) => displayable.add(gui_handler)?,
|
||||
Self::Color(colorable) => colorable.add(gui_handler)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn disable(&self) -> Result<()> {
|
||||
pub(crate) fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
match self {
|
||||
Self::Image(displayable) => displayable.delete()?,
|
||||
Self::Color(colorable) => colorable.delete()?,
|
||||
Self::Image(displayable) => displayable.delete(gui_handler)?,
|
||||
Self::Color(colorable) => colorable.delete(gui_handler)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn update_frame(&self) -> Result<()> {
|
||||
pub(crate) fn update_frame(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
match self {
|
||||
Self::Image(displayable) => displayable.update_frame()?,
|
||||
Self::Color(colorable) => colorable.update_frame()?,
|
||||
Self::Image(displayable) => displayable.update_frame(gui_handler)?,
|
||||
Self::Color(colorable) => colorable.update_frame(gui_handler)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -119,9 +127,13 @@ pub(crate) struct FillType {
|
|||
}
|
||||
|
||||
impl FillType {
|
||||
pub(crate) fn new(framable: Arc<Framable>, fill_type_info: FillTypeInfo) -> Result<Self> {
|
||||
pub(crate) fn new(
|
||||
gui_handler: &mut GuiHandler,
|
||||
framable: Arc<Framable>,
|
||||
fill_type_info: FillTypeInfo,
|
||||
) -> Result<Self> {
|
||||
let me = Self {
|
||||
inner: InnerFillType::new(framable.clone(), fill_type_info)?,
|
||||
inner: InnerFillType::new(gui_handler, framable.clone(), fill_type_info)?,
|
||||
visible: AtomicBool::new(false),
|
||||
};
|
||||
|
||||
|
@ -130,26 +142,26 @@ impl FillType {
|
|||
Ok(me)
|
||||
}
|
||||
|
||||
pub(crate) fn enable(&self) -> Result<()> {
|
||||
pub(crate) fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if !self.visible.load(SeqCst) {
|
||||
self.visible.store(true, SeqCst);
|
||||
self.inner.enable()?;
|
||||
self.inner.enable(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn disable(&self) -> Result<()> {
|
||||
pub(crate) fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if self.visible.load(SeqCst) {
|
||||
self.visible.store(false, SeqCst);
|
||||
self.inner.disable()?;
|
||||
self.inner.disable(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn update_frame(&self) -> Result<()> {
|
||||
self.inner.update_frame()
|
||||
pub(crate) fn update_frame(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.inner.update_frame(gui_handler)
|
||||
}
|
||||
|
||||
pub(crate) fn set_ui_layer(&self, layer: i32) {
|
||||
|
@ -183,14 +195,3 @@ impl PartialEq<FillTypeInfo> for FillType {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for FillType {
|
||||
fn drop(&mut self) {
|
||||
if self.visible.load(SeqCst) {
|
||||
match &self.inner {
|
||||
InnerFillType::Image(displayable) => displayable.delete().unwrap(),
|
||||
InnerFillType::Color(colorable) => colorable.delete().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ use anyhow::Result;
|
|||
use crate::builder::validator::gridinfo::GridInfo;
|
||||
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, AtomicU32, Ordering::SeqCst},
|
||||
Arc, RwLock, RwLockReadGuard,
|
||||
atomic::{AtomicBool, AtomicU32, Ordering::SeqCst},
|
||||
};
|
||||
use std::{ops::Deref, sync::Weak};
|
||||
|
||||
|
@ -93,8 +93,6 @@ impl ChildState {
|
|||
}
|
||||
|
||||
pub struct Grid {
|
||||
gui_handler: Arc<GuiHandler>,
|
||||
|
||||
pub(crate) framable: Arc<Framable>,
|
||||
background: RwLock<Option<FillType>>,
|
||||
|
||||
|
@ -111,15 +109,13 @@ pub struct Grid {
|
|||
|
||||
impl Grid {
|
||||
pub fn new(
|
||||
gui_handler: Arc<GuiHandler>,
|
||||
gui_handler: &GuiHandler,
|
||||
dim_x: usize,
|
||||
dim_y: usize,
|
||||
top_level: bool,
|
||||
) -> Result<Arc<Self>> {
|
||||
let grid = Arc::new(Grid {
|
||||
gui_handler: gui_handler.clone(),
|
||||
|
||||
framable: Framable::new(gui_handler, top_level)?,
|
||||
framable: Framable::new(gui_handler.width(), gui_handler.height(), top_level)?,
|
||||
background: RwLock::new(None),
|
||||
|
||||
children: RwLock::new(vec![vec![ChildState::None; dim_y]; dim_x]),
|
||||
|
@ -133,20 +129,20 @@ impl Grid {
|
|||
visible: AtomicBool::new(false),
|
||||
});
|
||||
|
||||
if top_level {
|
||||
let weak_grid = Arc::downgrade(&grid);
|
||||
// if top_level {
|
||||
// let weak_grid = Arc::downgrade(&grid);
|
||||
|
||||
grid.framable.add_callback(
|
||||
weak_grid.clone(),
|
||||
Box::new(move || {
|
||||
if let Some(grid) = weak_grid.upgrade() {
|
||||
grid.calculate_child_positions()?;
|
||||
}
|
||||
// grid.framable.add_callback(
|
||||
// weak_grid.clone(),
|
||||
// Box::new(move |gui_handler| {
|
||||
// if let Some(grid) = weak_grid.upgrade() {
|
||||
// grid.calculate_child_positions(gui_handler)?;
|
||||
// }
|
||||
|
||||
Ok(())
|
||||
}),
|
||||
);
|
||||
}
|
||||
// Ok(())
|
||||
// }),
|
||||
// );
|
||||
// }
|
||||
|
||||
Ok(grid)
|
||||
}
|
||||
|
@ -155,8 +151,18 @@ impl Grid {
|
|||
(self.dim_x, self.dim_y)
|
||||
}
|
||||
|
||||
pub fn set_background(&self, background: impl Into<FillTypeInfo>) -> Result<()> {
|
||||
super::set_background(self.visible(), &self.framable, &self.background, background)
|
||||
pub fn set_background(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
background: impl Into<FillTypeInfo>,
|
||||
) -> Result<()> {
|
||||
super::set_background(
|
||||
gui_handler,
|
||||
self.visible(),
|
||||
&self.framable,
|
||||
&self.background,
|
||||
background,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn background(&self) -> RwLockReadGuard<'_, Option<FillType>> {
|
||||
|
@ -191,7 +197,12 @@ impl Grid {
|
|||
Ok(self.children.read().unwrap()[x][y].map(|c| c.clone()))
|
||||
}
|
||||
|
||||
pub fn detach(&self, pos_x: usize, pos_y: usize) -> Result<Option<Arc<dyn GuiElementTraits>>> {
|
||||
pub fn detach(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
pos_x: usize,
|
||||
pos_y: usize,
|
||||
) -> Result<Option<Arc<dyn GuiElementTraits>>> {
|
||||
if cfg!(debug_assertions) {
|
||||
if pos_x >= self.dim_x as usize {
|
||||
panic!(
|
||||
|
@ -220,7 +231,7 @@ impl Grid {
|
|||
Some((child, _x, _y)) => {
|
||||
if self.visible() {
|
||||
if let Some(child_visibility) = child.visibility() {
|
||||
child_visibility.set_visibility(false)?;
|
||||
child_visibility.set_visibility(gui_handler, false)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,7 +242,11 @@ impl Grid {
|
|||
}
|
||||
|
||||
/// Returns `true` if item got detached
|
||||
pub fn detach_item(&self, item: Arc<dyn GuiElementTraits>) -> Result<bool> {
|
||||
pub fn detach_item(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
item: Arc<dyn GuiElementTraits>,
|
||||
) -> Result<bool> {
|
||||
let mut grid = self.children.write().unwrap();
|
||||
let mut removed = false;
|
||||
|
||||
|
@ -250,7 +265,7 @@ impl Grid {
|
|||
|
||||
if self.visible() {
|
||||
if let Some(child_visibility) = child.visibility() {
|
||||
child_visibility.set_visibility(false)?;
|
||||
child_visibility.set_visibility(gui_handler, false)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -273,20 +288,20 @@ impl Grid {
|
|||
Ok(removed)
|
||||
}
|
||||
|
||||
pub fn set_position(&self, x: i32, y: i32) -> Result<()> {
|
||||
pub fn set_position(&self, gui_handler: &mut GuiHandler, x: i32, y: i32) -> Result<()> {
|
||||
// update own position
|
||||
self.framable.change_position(x, y)?;
|
||||
self.framable.change_position(gui_handler, x, y)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.update_frame()?;
|
||||
background.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
self.calculate_child_positions()?;
|
||||
self.calculate_child_positions(gui_handler)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn calculate_child_positions(&self) -> Result<()> {
|
||||
fn calculate_child_positions(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
// recalculate positions of the children
|
||||
let children = self.children.read().unwrap();
|
||||
|
||||
|
@ -294,7 +309,7 @@ impl Grid {
|
|||
for (y, child_opt) in row.iter().enumerate() {
|
||||
if let Some((child, dim_x, dim_y)) = child_opt.get_some() {
|
||||
if let Some(child_gridable) = child.gridable() {
|
||||
self.child_position(child_gridable, x, y, dim_x, dim_y)?;
|
||||
self.child_position(gui_handler, child_gridable, x, y, dim_x, dim_y)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -314,18 +329,18 @@ impl Grid {
|
|||
(width, height)
|
||||
}
|
||||
|
||||
pub fn disallow_position_scale(&self) -> Result<()> {
|
||||
self.framable.allow_position_scale(false)
|
||||
pub fn disallow_position_scale(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.framable.allow_position_scale(gui_handler, false)
|
||||
}
|
||||
|
||||
pub fn disallow_size_scale(&self) -> Result<()> {
|
||||
self.framable.allow_size_scale(false)
|
||||
pub fn disallow_size_scale(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.framable.allow_size_scale(gui_handler, false)
|
||||
}
|
||||
|
||||
pub fn connect<'a>(
|
||||
pub fn connect(
|
||||
&self,
|
||||
direction: ConnectDirection,
|
||||
elements: impl IntoIterator<Item = (usize, &'a Arc<Selectable>)>,
|
||||
elements: impl IntoIterator<Item = (usize, &Arc<Selectable>)>,
|
||||
) -> Result<()> {
|
||||
for (index, selectable) in elements {
|
||||
match direction {
|
||||
|
@ -393,6 +408,7 @@ impl Grid {
|
|||
|
||||
pub fn attach(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
child: Arc<dyn GuiElementTraits>,
|
||||
pos_x: usize,
|
||||
pos_y: usize,
|
||||
|
@ -431,7 +447,7 @@ impl Grid {
|
|||
}
|
||||
|
||||
if self.framable.is_framed() {
|
||||
self.child_position(child_gridable, pos_x, pos_y, dim_x, dim_y)?;
|
||||
self.child_position(gui_handler, child_gridable, pos_x, pos_y, dim_x, dim_y)?;
|
||||
}
|
||||
|
||||
child_gridable.set_layer(self.framable.ui_layer())?;
|
||||
|
@ -442,7 +458,7 @@ impl Grid {
|
|||
ChildState::Some { child, .. } => {
|
||||
if self.visible() {
|
||||
if let Some(child_visibility) = child.visibility() {
|
||||
child_visibility.set_visibility(false)?;
|
||||
child_visibility.set_visibility(gui_handler, false)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -452,7 +468,7 @@ impl Grid {
|
|||
|
||||
if self.visible() {
|
||||
if let Some(child_visibility) = child.visibility() {
|
||||
child_visibility.set_visibility(true)?;
|
||||
child_visibility.set_visibility(gui_handler, true)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -484,11 +500,11 @@ impl Grid {
|
|||
|
||||
pub fn try_from(
|
||||
grid_info: &GridInfo,
|
||||
gui_handler: &Arc<GuiHandler>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
top_level: bool,
|
||||
) -> Result<Arc<Self>> {
|
||||
let grid = Grid::new(
|
||||
gui_handler.clone(),
|
||||
gui_handler,
|
||||
grid_info.x_dimension.get()?,
|
||||
grid_info.y_dimension.get()?,
|
||||
top_level,
|
||||
|
@ -498,26 +514,32 @@ impl Grid {
|
|||
grid.set_padding(grid_info.padding);
|
||||
|
||||
if let Some(background) = &grid_info.background_type {
|
||||
grid.set_background(background.clone())?;
|
||||
grid.set_background(gui_handler, background.clone())?;
|
||||
}
|
||||
|
||||
Ok(grid)
|
||||
}
|
||||
|
||||
pub fn change_position_unscaled(&self, x: i32, y: i32) -> Result<()> {
|
||||
self.framable.change_position_unscaled(x, y)?;
|
||||
pub fn change_position_unscaled(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
) -> Result<()> {
|
||||
self.framable.change_position_unscaled(gui_handler, x, y)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.update_frame()?;
|
||||
background.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
self.calculate_child_positions()?;
|
||||
self.calculate_child_positions(gui_handler)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn child_position(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
child: &dyn Gridable,
|
||||
pos_x: usize,
|
||||
pos_y: usize,
|
||||
|
@ -546,8 +568,8 @@ impl Grid {
|
|||
single_height + (dim_y - 1) as i32 * (single_height + self.margin.load(SeqCst) as i32)
|
||||
};
|
||||
|
||||
let win_width = self.gui_handler.width();
|
||||
let win_height = self.gui_handler.height();
|
||||
let win_width = gui_handler.width();
|
||||
let win_height = gui_handler.height();
|
||||
|
||||
let y_align = match self.framable.vertical_alignment() {
|
||||
VerticalAlign::Top => 0,
|
||||
|
@ -571,6 +593,7 @@ impl Grid {
|
|||
+ pos_y as i32 * (single_height + self.margin.load(SeqCst) as i32);
|
||||
|
||||
child.set_frame(
|
||||
gui_handler,
|
||||
child_x - x_align as i32,
|
||||
child_y - y_align as i32,
|
||||
child_width as u32,
|
||||
|
@ -582,12 +605,12 @@ impl Grid {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn select(&self, x: u32, y: u32) -> Result<()> {
|
||||
pub fn select(&self, gui_handler: &mut GuiHandler, x: u32, y: u32) -> Result<()> {
|
||||
match self.children.read().unwrap()[x as usize][y as usize].get_some() {
|
||||
Some((child, ..)) => match child.gridable() {
|
||||
Some(gridable) => match gridable.selectable() {
|
||||
Some(selectable) => {
|
||||
selectable.select()?;
|
||||
selectable.select(gui_handler)?;
|
||||
Ok(())
|
||||
}
|
||||
None => panic!("gridable at position ({}, {}), is not selectable", x, y),
|
||||
|
@ -599,26 +622,26 @@ impl Grid {
|
|||
}
|
||||
}
|
||||
|
||||
fn disable_tree(&self) -> Result<()> {
|
||||
self.framable.delete()?;
|
||||
fn disable_tree(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.framable.delete(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.disable()?;
|
||||
background.disable(gui_handler)?;
|
||||
}
|
||||
|
||||
self.set_tree_visibility(false)?;
|
||||
self.set_tree_visibility(gui_handler, false)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_tree_visibility(&self, visible: bool) -> Result<()> {
|
||||
fn set_tree_visibility(&self, gui_handler: &mut GuiHandler, visible: bool) -> Result<()> {
|
||||
let tree = self.children.read().unwrap();
|
||||
|
||||
for row in tree.deref() {
|
||||
for child_state in row {
|
||||
if let Some((child, ..)) = child_state.get_some() {
|
||||
if let Some(visibility) = child.visibility() {
|
||||
visibility.set_visibility(visible)?;
|
||||
visibility.set_visibility(gui_handler, visible)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -770,20 +793,20 @@ impl Visibility for Grid {
|
|||
self.visible.load(SeqCst)
|
||||
}
|
||||
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()> {
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||
if visibility != self.visible.load(SeqCst) {
|
||||
self.visible.store(visibility, SeqCst);
|
||||
|
||||
if visibility {
|
||||
Framable::add(&self.framable)?;
|
||||
self.framable.add(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.enable()?;
|
||||
background.enable(gui_handler)?;
|
||||
}
|
||||
|
||||
self.set_tree_visibility(true)?;
|
||||
self.set_tree_visibility(gui_handler, true)?;
|
||||
} else {
|
||||
self.disable_tree()?;
|
||||
self.disable_tree(gui_handler)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -794,6 +817,7 @@ impl Visibility for Grid {
|
|||
impl Gridable for Grid {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -801,13 +825,14 @@ impl Gridable for Grid {
|
|||
vert_align: VerticalAlign,
|
||||
hori_align: HorizontalAlign,
|
||||
) -> Result<()> {
|
||||
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
|
||||
self.framable
|
||||
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.update_frame()?;
|
||||
background.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
self.calculate_child_positions()?;
|
||||
self.calculate_child_positions(gui_handler)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -844,11 +869,3 @@ impl Gridable for Grid {
|
|||
self.framable.position()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Grid {
|
||||
fn drop(&mut self) {
|
||||
if self.visible.load(SeqCst) {
|
||||
self.disable_tree().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@ use utilities::prelude::*;
|
|||
use vulkan_rs::prelude::*;
|
||||
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
Arc, RwLock,
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
};
|
||||
|
||||
use super::{
|
||||
IconBuilderType,
|
||||
fill_type::FillType,
|
||||
wrapper::{IconizableWrapper, TextableWrapper},
|
||||
IconBuilderType,
|
||||
};
|
||||
|
||||
pub struct IconBuilder {
|
||||
|
@ -65,15 +65,20 @@ impl IconBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<Icon>> {
|
||||
let framable = Framable::new(gui_handler, false)?;
|
||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<Icon>> {
|
||||
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
|
||||
|
||||
let iconizable_wrapper =
|
||||
IconizableWrapper::new(framable.clone(), self.content, None, self.margin)?;
|
||||
let iconizable_wrapper = IconizableWrapper::new(
|
||||
gui_handler,
|
||||
framable.clone(),
|
||||
self.content,
|
||||
None,
|
||||
self.margin,
|
||||
)?;
|
||||
|
||||
let background = RwLock::new(
|
||||
self.background
|
||||
.map(|info| FillType::new(framable.clone(), info))
|
||||
.map(|info| FillType::new(gui_handler, framable.clone(), info))
|
||||
.transpose()?,
|
||||
);
|
||||
|
||||
|
@ -85,10 +90,11 @@ impl IconBuilder {
|
|||
);
|
||||
|
||||
if let Some(text) = self.text {
|
||||
textable_wrapper.set_text(&text, false)?;
|
||||
textable_wrapper.set_text(gui_handler, &text, false)?;
|
||||
}
|
||||
|
||||
let info_icon = IconizableWrapper::new(
|
||||
gui_handler,
|
||||
framable.clone(),
|
||||
None,
|
||||
Some(IconizablePositioning {
|
||||
|
@ -135,51 +141,70 @@ impl Icon {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn clear_icon(&self) -> Result<()> {
|
||||
self.iconizable_wrapper.clear_icon(self.visible())
|
||||
pub fn clear_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.iconizable_wrapper
|
||||
.clear_icon(gui_handler, self.visible())
|
||||
}
|
||||
|
||||
pub fn set_icon(&self, icon: &Arc<Image>) -> Result<()> {
|
||||
self.iconizable_wrapper.set_icon(icon, self.visible())
|
||||
pub fn set_icon(&self, gui_handler: &mut GuiHandler, icon: &Arc<Image>) -> Result<()> {
|
||||
self.iconizable_wrapper
|
||||
.set_icon(gui_handler, icon, self.visible())
|
||||
}
|
||||
|
||||
pub fn set_icon_from_path(&self, asset_path: AssetPath) -> Result<()> {
|
||||
self.iconizable_wrapper.set_icon(asset_path, self.visible())
|
||||
pub fn set_icon_from_path(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
asset_path: AssetPath,
|
||||
) -> Result<()> {
|
||||
self.iconizable_wrapper
|
||||
.set_icon(gui_handler, asset_path, self.visible())
|
||||
}
|
||||
|
||||
pub fn set_margin(&self, margin: u32) -> Result<()> {
|
||||
self.iconizable_wrapper.set_margin(margin)
|
||||
pub fn set_margin(&self, gui_handler: &mut GuiHandler, margin: u32) -> Result<()> {
|
||||
self.iconizable_wrapper.set_margin(gui_handler, margin)
|
||||
}
|
||||
|
||||
pub fn set_background(&self, background: impl Into<FillTypeInfo>) -> Result<()> {
|
||||
super::set_background(self.visible(), &self.framable, &self.background, background)
|
||||
pub fn set_background(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
background: impl Into<FillTypeInfo>,
|
||||
) -> Result<()> {
|
||||
super::set_background(
|
||||
gui_handler,
|
||||
self.visible(),
|
||||
&self.framable,
|
||||
&self.background,
|
||||
background,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn clear_background(&self) {
|
||||
*self.background.write().unwrap() = None;
|
||||
}
|
||||
|
||||
pub fn set_text(&self, text: impl ToString) -> Result<()> {
|
||||
self.textable_wrapper.set_text(text, self.visible())
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
|
||||
self.textable_wrapper
|
||||
.set_text(gui_handler, text, self.visible())
|
||||
}
|
||||
|
||||
pub fn clear_text(&self) -> Result<()> {
|
||||
self.textable_wrapper.set_text("", self.visible())
|
||||
pub fn clear_text(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.textable_wrapper
|
||||
.set_text(gui_handler, "", self.visible())
|
||||
}
|
||||
|
||||
pub fn set_text_color(&self, color: Color) -> Result<()> {
|
||||
self.textable_wrapper.set_text_color(color)
|
||||
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, color: Color) -> Result<()> {
|
||||
self.textable_wrapper.set_text_color(gui_handler, color)
|
||||
}
|
||||
|
||||
pub fn set_info_icon(&self, button: &Arc<Image>) -> Result<()> {
|
||||
self.info_icon.set_icon(button, self.visible())
|
||||
pub fn set_info_icon(&self, gui_handler: &mut GuiHandler, button: &Arc<Image>) -> Result<()> {
|
||||
self.info_icon.set_icon(gui_handler, button, self.visible())
|
||||
}
|
||||
|
||||
pub fn clear_info_icon(&self) -> Result<()> {
|
||||
self.info_icon.clear_icon(self.visible())
|
||||
pub fn clear_info_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.info_icon.clear_icon(gui_handler, self.visible())
|
||||
}
|
||||
|
||||
pub fn try_from(icon_info: &IconInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
|
||||
pub fn try_from(icon_info: &IconInfo, gui_handler: &mut GuiHandler) -> Result<Arc<Self>> {
|
||||
let mut icon_builder = Icon::builder().set_text_color(icon_info.text_color);
|
||||
|
||||
if let Some(text_ratio) = icon_info.text_ratio {
|
||||
|
@ -207,7 +232,7 @@ impl Icon {
|
|||
}
|
||||
}
|
||||
|
||||
icon_builder.build(gui_handler.clone())
|
||||
icon_builder.build(gui_handler)
|
||||
}
|
||||
|
||||
pub fn icon(&self) -> Result<Option<Arc<Image>>> {
|
||||
|
@ -221,15 +246,15 @@ impl Icon {
|
|||
)
|
||||
}
|
||||
|
||||
fn disable_base(&self) -> Result<()> {
|
||||
self.framable.delete()?;
|
||||
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.framable.delete(gui_handler)?;
|
||||
|
||||
self.iconizable_wrapper.disable()?;
|
||||
self.textable_wrapper.disable()?;
|
||||
self.info_icon.disable()?;
|
||||
self.iconizable_wrapper.disable(gui_handler)?;
|
||||
self.textable_wrapper.disable(gui_handler)?;
|
||||
self.info_icon.disable(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.disable()?;
|
||||
background.disable(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -255,22 +280,22 @@ impl Visibility for Icon {
|
|||
self.visible.load(SeqCst)
|
||||
}
|
||||
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()> {
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||
if visibility != self.visible.load(SeqCst) {
|
||||
self.visible.store(visibility, SeqCst);
|
||||
|
||||
if visibility {
|
||||
self.framable.add()?;
|
||||
self.framable.add(gui_handler)?;
|
||||
|
||||
self.info_icon.enable()?;
|
||||
self.iconizable_wrapper.enable()?;
|
||||
self.textable_wrapper.enable()?;
|
||||
self.info_icon.enable(gui_handler)?;
|
||||
self.iconizable_wrapper.enable(gui_handler)?;
|
||||
self.textable_wrapper.enable(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.enable()?;
|
||||
background.enable(gui_handler)?;
|
||||
}
|
||||
} else {
|
||||
self.disable_base()?;
|
||||
self.disable_base(gui_handler)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,6 +306,7 @@ impl Visibility for Icon {
|
|||
impl Gridable for Icon {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -288,14 +314,15 @@ impl Gridable for Icon {
|
|||
vert_align: VerticalAlign,
|
||||
hori_align: HorizontalAlign,
|
||||
) -> Result<()> {
|
||||
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
|
||||
self.framable
|
||||
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
|
||||
|
||||
self.iconizable_wrapper.update_frame()?;
|
||||
self.textable_wrapper.update()?;
|
||||
self.info_icon.update_frame()?;
|
||||
self.iconizable_wrapper.update_frame(gui_handler)?;
|
||||
self.textable_wrapper.update(gui_handler)?;
|
||||
self.info_icon.update_frame(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.update_frame()?;
|
||||
background.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -326,11 +353,3 @@ impl Gridable for Icon {
|
|||
self.framable.position()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Icon {
|
||||
fn drop(&mut self) {
|
||||
if self.visible.load(SeqCst) {
|
||||
self.disable_base().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ use super::{
|
|||
use vulkan_rs::prelude::*;
|
||||
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
Arc, RwLock,
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
|
@ -57,8 +57,8 @@ impl LabelBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<Label>> {
|
||||
let framable = Framable::new(gui_handler, false)?;
|
||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<Label>> {
|
||||
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
|
||||
|
||||
let textable_wrapper = TextableWrapper::new(
|
||||
framable.clone(),
|
||||
|
@ -68,15 +68,16 @@ impl LabelBuilder {
|
|||
);
|
||||
|
||||
if let Some(text) = &self.text {
|
||||
textable_wrapper.set_text(text, false)?;
|
||||
textable_wrapper.set_text(gui_handler, text, false)?;
|
||||
}
|
||||
|
||||
let background = self
|
||||
.background
|
||||
.map(|info| FillType::new(framable.clone(), info))
|
||||
.map(|info| FillType::new(gui_handler, framable.clone(), info))
|
||||
.transpose()?;
|
||||
|
||||
let info_icon = IconizableWrapper::new(
|
||||
gui_handler,
|
||||
framable.clone(),
|
||||
None,
|
||||
Some(IconizablePositioning {
|
||||
|
@ -120,43 +121,59 @@ impl Label {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_text(&self, text: impl ToString) -> Result<()> {
|
||||
self.textable_wrapper.set_text(text, self.visible())
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
|
||||
self.textable_wrapper
|
||||
.set_text(gui_handler, text, self.visible())
|
||||
}
|
||||
|
||||
pub fn text(&self) -> Result<Option<String>> {
|
||||
self.textable_wrapper.text()
|
||||
}
|
||||
|
||||
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
|
||||
self.textable_wrapper.set_text_color(text_color)
|
||||
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
|
||||
self.textable_wrapper
|
||||
.set_text_color(gui_handler, text_color)
|
||||
}
|
||||
|
||||
pub fn set_alignment(&self, alignment: TextAlignment) -> Result<()> {
|
||||
self.textable_wrapper.set_alignment(alignment)
|
||||
pub fn set_alignment(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
alignment: TextAlignment,
|
||||
) -> Result<()> {
|
||||
self.textable_wrapper.set_alignment(gui_handler, alignment)
|
||||
}
|
||||
|
||||
pub fn set_text_ratio(&self, ratio: f32) -> Result<()> {
|
||||
self.textable_wrapper.set_height_ratio(ratio)
|
||||
pub fn set_text_ratio(&self, gui_handler: &mut GuiHandler, ratio: f32) -> Result<()> {
|
||||
self.textable_wrapper.set_height_ratio(gui_handler, ratio)
|
||||
}
|
||||
|
||||
pub fn text_ratio(&self) -> f32 {
|
||||
self.textable_wrapper.height_ratio()
|
||||
}
|
||||
|
||||
pub fn set_info_icon(&self, button: &Arc<Image>) -> Result<()> {
|
||||
self.info_icon.set_icon(button, self.visible())
|
||||
pub fn set_info_icon(&self, gui_handler: &mut GuiHandler, button: &Arc<Image>) -> Result<()> {
|
||||
self.info_icon.set_icon(gui_handler, button, self.visible())
|
||||
}
|
||||
|
||||
pub fn clear_info_icon(&self) -> Result<()> {
|
||||
self.info_icon.clear_icon(self.visible())
|
||||
pub fn clear_info_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.info_icon.clear_icon(gui_handler, self.visible())
|
||||
}
|
||||
|
||||
pub fn set_background(&self, background: impl Into<FillTypeInfo>) -> Result<()> {
|
||||
super::set_background(self.visible(), &self.framable, &self.background, background)
|
||||
pub fn set_background(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
background: impl Into<FillTypeInfo>,
|
||||
) -> Result<()> {
|
||||
super::set_background(
|
||||
gui_handler,
|
||||
self.visible(),
|
||||
&self.framable,
|
||||
&self.background,
|
||||
background,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn try_from(label_info: &LabelInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
|
||||
pub fn try_from(label_info: &LabelInfo, gui_handler: &mut GuiHandler) -> Result<Arc<Self>> {
|
||||
let text = label_info.text.read().unwrap().clone();
|
||||
let color = label_info.text_color;
|
||||
|
||||
|
@ -176,17 +193,17 @@ impl Label {
|
|||
label_builder = label_builder.set_text(text);
|
||||
}
|
||||
|
||||
label_builder.build(gui_handler.clone())
|
||||
label_builder.build(gui_handler)
|
||||
}
|
||||
|
||||
fn disable_base(&self) -> Result<()> {
|
||||
self.framable.delete()?;
|
||||
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.framable.delete(gui_handler)?;
|
||||
|
||||
self.textable_wrapper.disable()?;
|
||||
self.info_icon.disable()?;
|
||||
self.textable_wrapper.disable(gui_handler)?;
|
||||
self.info_icon.disable(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.disable()?;
|
||||
background.disable(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -212,21 +229,21 @@ impl Visibility for Label {
|
|||
self.visible.load(SeqCst)
|
||||
}
|
||||
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()> {
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||
if visibility != self.visible() {
|
||||
self.visible.store(visibility, SeqCst);
|
||||
|
||||
if visibility {
|
||||
self.framable.add()?;
|
||||
self.framable.add(gui_handler)?;
|
||||
|
||||
self.textable_wrapper.enable()?;
|
||||
self.info_icon.enable()?;
|
||||
self.textable_wrapper.enable(gui_handler)?;
|
||||
self.info_icon.enable(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.enable()?;
|
||||
background.enable(gui_handler)?;
|
||||
}
|
||||
} else {
|
||||
self.disable_base()?;
|
||||
self.disable_base(gui_handler)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,6 +254,7 @@ impl Visibility for Label {
|
|||
impl Gridable for Label {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -244,13 +262,14 @@ impl Gridable for Label {
|
|||
vert_align: VerticalAlign,
|
||||
hori_align: HorizontalAlign,
|
||||
) -> Result<()> {
|
||||
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
|
||||
self.framable
|
||||
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
|
||||
|
||||
self.textable_wrapper.update()?;
|
||||
self.info_icon.update_frame()?;
|
||||
self.textable_wrapper.update(gui_handler)?;
|
||||
self.info_icon.update_frame(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.update_frame()?;
|
||||
background.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -280,11 +299,3 @@ impl Gridable for Label {
|
|||
self.framable.position()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Label {
|
||||
fn drop(&mut self) {
|
||||
if self.visible.load(SeqCst) {
|
||||
self.disable_base().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ pub mod prelude;
|
|||
mod wrapper;
|
||||
|
||||
pub(crate) fn set_background(
|
||||
gui_handler: &mut GuiHandler,
|
||||
visible: bool,
|
||||
framable: &Arc<Framable>,
|
||||
current: &RwLock<Option<FillType>>,
|
||||
|
@ -37,14 +38,14 @@ pub(crate) fn set_background(
|
|||
};
|
||||
|
||||
if update {
|
||||
let fill_type = FillType::new(framable.clone(), fill_info)?;
|
||||
let fill_type = FillType::new(gui_handler, framable.clone(), fill_info)?;
|
||||
|
||||
if framable.is_framed() {
|
||||
fill_type.update_frame()?;
|
||||
fill_type.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
if visible {
|
||||
fill_type.enable()?;
|
||||
fill_type.enable(gui_handler)?;
|
||||
}
|
||||
|
||||
*current_background = Some(fill_type);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::{builder::validator::multi_line_labelinfo::MultiLineLabelInfo, prelude::*};
|
||||
|
||||
use std::sync::{
|
||||
atomic::{AtomicU32, Ordering::SeqCst},
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicU32, Ordering::SeqCst},
|
||||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
@ -56,13 +56,13 @@ impl MultiLineLabelBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<MultiLineLabel>> {
|
||||
let base_grid = Grid::new(gui_handler.clone(), 1, self.line_count as usize, false)?;
|
||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<MultiLineLabel>> {
|
||||
let base_grid = Grid::new(gui_handler, 1, self.line_count as usize, false)?;
|
||||
base_grid.set_margin(0);
|
||||
base_grid.set_padding(0);
|
||||
|
||||
if let Some(background) = self.background {
|
||||
base_grid.set_background(background)?;
|
||||
base_grid.set_background(gui_handler, background)?;
|
||||
}
|
||||
|
||||
for i in 0..self.line_count {
|
||||
|
@ -70,9 +70,9 @@ impl MultiLineLabelBuilder {
|
|||
.set_ratio(self.text_ratio)
|
||||
.set_text_color(self.text_color)
|
||||
.set_text_alignment(self.text_alignment)
|
||||
.build(gui_handler.clone())?;
|
||||
.build(gui_handler)?;
|
||||
|
||||
base_grid.attach(label, 0, i as usize, 1, 1)?;
|
||||
base_grid.attach(gui_handler, label, 0, i as usize, 1, 1)?;
|
||||
}
|
||||
|
||||
Ok(Arc::new(MultiLineLabel {
|
||||
|
@ -107,13 +107,13 @@ impl MultiLineLabel {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_text(&self, text: impl ToString) -> Result<()> {
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
|
||||
*self.text.lock().unwrap() = text.to_string();
|
||||
|
||||
self.update_text()
|
||||
self.update_text(gui_handler)
|
||||
}
|
||||
|
||||
fn update_text(&self) -> Result<()> {
|
||||
fn update_text(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
let text = self.text.lock().unwrap();
|
||||
let splits = text.split(' ');
|
||||
let character_count = self.characters_per_line.load(SeqCst) as usize;
|
||||
|
@ -145,9 +145,9 @@ impl MultiLineLabel {
|
|||
|
||||
self.iter_label(|label, y| {
|
||||
if y < lines.len() {
|
||||
label.set_text(&lines[y])?;
|
||||
label.set_text(gui_handler, &lines[y])?;
|
||||
} else {
|
||||
label.set_text("")?;
|
||||
label.set_text(gui_handler, "")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -158,25 +158,33 @@ impl MultiLineLabel {
|
|||
self.text.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_text_color(text_color))
|
||||
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_text_color(gui_handler, text_color))
|
||||
}
|
||||
|
||||
pub fn set_alignment(&self, alignment: TextAlignment) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_alignment(alignment))
|
||||
pub fn set_alignment(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
alignment: TextAlignment,
|
||||
) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_alignment(gui_handler, alignment))
|
||||
}
|
||||
|
||||
pub fn set_text_ratio(&self, ratio: f32) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_text_ratio(ratio))
|
||||
pub fn set_text_ratio(&self, gui_handler: &mut GuiHandler, ratio: f32) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_text_ratio(gui_handler, ratio))
|
||||
}
|
||||
|
||||
pub fn set_background(&self, background: impl Into<FillTypeInfo>) -> Result<()> {
|
||||
self.grid.set_background(background)
|
||||
pub fn set_background(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
background: impl Into<FillTypeInfo>,
|
||||
) -> Result<()> {
|
||||
self.grid.set_background(gui_handler, background)
|
||||
}
|
||||
|
||||
pub fn try_from(
|
||||
multi_line_label_info: &MultiLineLabelInfo,
|
||||
gui_handler: &Arc<GuiHandler>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
) -> Result<Arc<Self>> {
|
||||
let text = multi_line_label_info.text.read().unwrap().clone();
|
||||
let color = multi_line_label_info.text_color;
|
||||
|
@ -204,12 +212,12 @@ impl MultiLineLabel {
|
|||
multi_line_label_builder = multi_line_label_builder.set_text(text);
|
||||
}
|
||||
|
||||
multi_line_label_builder.build(gui_handler.clone())
|
||||
multi_line_label_builder.build(gui_handler)
|
||||
}
|
||||
|
||||
fn iter_label<F>(&self, f: F) -> Result<()>
|
||||
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
||||
where
|
||||
F: Fn(&Label, usize) -> Result<()>,
|
||||
F: FnMut(&Label, usize) -> Result<()>,
|
||||
{
|
||||
for y in 0..self.grid.dimensions().1 {
|
||||
let child = self.grid.child_at(0, y)?.unwrap();
|
||||
|
@ -242,14 +250,15 @@ impl Visibility for MultiLineLabel {
|
|||
self.grid.visible()
|
||||
}
|
||||
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()> {
|
||||
self.grid.set_visibility(visibility)
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||
self.grid.set_visibility(gui_handler, visibility)
|
||||
}
|
||||
}
|
||||
|
||||
impl Gridable for MultiLineLabel {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -257,7 +266,8 @@ impl Gridable for MultiLineLabel {
|
|||
vert_align: VerticalAlign,
|
||||
hori_align: HorizontalAlign,
|
||||
) -> Result<()> {
|
||||
self.grid.set_frame(x, y, w, h, vert_align, hori_align)?;
|
||||
self.grid
|
||||
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align)?;
|
||||
|
||||
if let Some(child) = self.grid.child_at(0, 0)? {
|
||||
let gui_element = child.downcast().unwrap();
|
||||
|
@ -279,7 +289,7 @@ impl Gridable for MultiLineLabel {
|
|||
self.characters_per_line
|
||||
.store(max_letter_count as u32, SeqCst);
|
||||
|
||||
self.update_text()?;
|
||||
self.update_text(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::{
|
|||
};
|
||||
|
||||
use std::sync::{
|
||||
atomic::{AtomicU32, Ordering::SeqCst},
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicU32, Ordering::SeqCst},
|
||||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
@ -62,13 +62,13 @@ impl MultiLineTextFieldBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<MultiLineTextField>> {
|
||||
let base_grid = Grid::new(gui_handler.clone(), 1, self.line_count as usize, false)?;
|
||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<MultiLineTextField>> {
|
||||
let base_grid = Grid::new(gui_handler, 1, self.line_count as usize, false)?;
|
||||
base_grid.set_margin(0);
|
||||
base_grid.set_padding(0);
|
||||
|
||||
if let Some(background) = self.background {
|
||||
base_grid.set_background(background)?;
|
||||
base_grid.set_background(gui_handler, background)?;
|
||||
}
|
||||
|
||||
for i in 0..self.line_count {
|
||||
|
@ -76,14 +76,14 @@ impl MultiLineTextFieldBuilder {
|
|||
.set_ratio(self.text_ratio)
|
||||
.set_text_color(self.text_color)
|
||||
.set_text_alignment(self.text_alignment)
|
||||
.build(gui_handler.clone())?;
|
||||
.build(gui_handler)?;
|
||||
|
||||
base_grid.attach(label, 0, i as usize, 1, 1)?;
|
||||
base_grid.attach(gui_handler, label, 0, i as usize, 1, 1)?;
|
||||
}
|
||||
|
||||
let text = Arc::new(SplittedText::new(self.text));
|
||||
let text_changed_exec = Executable::new(&gui_handler);
|
||||
let writeable = Writeable::new(gui_handler, text.clone(), text_changed_exec.clone())?;
|
||||
let text_changed_exec = Executable::new();
|
||||
let writeable = Writeable::new(text.clone(), text_changed_exec.clone())?;
|
||||
|
||||
let multi_line_text_field = Arc::new(MultiLineTextField {
|
||||
grid: base_grid,
|
||||
|
@ -96,9 +96,9 @@ impl MultiLineTextFieldBuilder {
|
|||
multi_line_text_field.text_changed_exec.set_callback({
|
||||
let weak_tf = Arc::downgrade(&multi_line_text_field);
|
||||
|
||||
move |_text| {
|
||||
move |gui_handler: &mut GuiHandler, _text| {
|
||||
if let Some(tf) = weak_tf.upgrade() {
|
||||
tf.update_text()?;
|
||||
tf.update_text(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -173,13 +173,13 @@ impl SplittedText {
|
|||
}
|
||||
|
||||
impl ModifyText for SplittedText {
|
||||
fn set_text(&self, text: String) -> Result<()> {
|
||||
fn set_text(&self, _gui_handler: &mut GuiHandler, text: String) -> Result<()> {
|
||||
*self.text.lock().unwrap() = text;
|
||||
|
||||
self.update_text()
|
||||
}
|
||||
|
||||
fn add_letter(&self, letter: char) -> Result<String> {
|
||||
fn add_letter(&self, _gui_handler: &mut GuiHandler, letter: char) -> Result<String> {
|
||||
*self.text.lock().unwrap() += &format!("{}", letter);
|
||||
|
||||
self.update_text()?;
|
||||
|
@ -187,7 +187,7 @@ impl ModifyText for SplittedText {
|
|||
Ok(self.text.lock().unwrap().clone())
|
||||
}
|
||||
|
||||
fn remove_last(&self) -> Result<Option<String>> {
|
||||
fn remove_last(&self, _gui_handler: &mut GuiHandler) -> Result<Option<String>> {
|
||||
self.text.lock().unwrap().pop();
|
||||
|
||||
self.update_text()?;
|
||||
|
@ -219,25 +219,25 @@ impl MultiLineTextField {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_text(&self, text: impl ToString) -> Result<()> {
|
||||
self.text.set_text(text.to_string())
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
|
||||
self.text.set_text(gui_handler, text.to_string())
|
||||
}
|
||||
|
||||
fn update_text(&self) -> Result<()> {
|
||||
fn update_text(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
let lines = self.text.lines();
|
||||
|
||||
self.iter_label(|label, y| {
|
||||
if y < lines.len() {
|
||||
label.set_text(&lines[y])?;
|
||||
label.set_text(gui_handler, &lines[y])?;
|
||||
} else {
|
||||
label.set_text("")?;
|
||||
label.set_text(gui_handler, "")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn update_color_change(self: &Arc<Self>) {
|
||||
fn update_color_change(self: &Arc<MultiLineTextField>) {
|
||||
if let Some(background) = &*self.grid.background() {
|
||||
if let InnerFillType::Color(colorable) = &background.inner {
|
||||
let normal_color = colorable.color();
|
||||
|
@ -245,19 +245,24 @@ impl MultiLineTextField {
|
|||
|
||||
let weak_self = Arc::downgrade(self);
|
||||
|
||||
self.writeable.set_activation_changed(move |active| {
|
||||
if let Some(me) = weak_self.upgrade() {
|
||||
if active {
|
||||
me.grid
|
||||
.set_background((focus_color, DisplayableFillType::Expand))?;
|
||||
} else {
|
||||
me.grid
|
||||
.set_background((normal_color, DisplayableFillType::Expand))?;
|
||||
self.writeable
|
||||
.set_activation_changed(move |gui_handler, active| {
|
||||
if let Some(me) = weak_self.upgrade() {
|
||||
if active {
|
||||
me.grid.set_background(
|
||||
gui_handler,
|
||||
(focus_color, DisplayableFillType::Expand),
|
||||
)?;
|
||||
} else {
|
||||
me.grid.set_background(
|
||||
gui_handler,
|
||||
(normal_color, DisplayableFillType::Expand),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
});
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -266,32 +271,40 @@ impl MultiLineTextField {
|
|||
self.text.text()
|
||||
}
|
||||
|
||||
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_text_color(text_color))
|
||||
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_text_color(gui_handler, text_color))
|
||||
}
|
||||
|
||||
pub fn set_alignment(&self, alignment: TextAlignment) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_alignment(alignment))
|
||||
pub fn set_alignment(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
alignment: TextAlignment,
|
||||
) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_alignment(gui_handler, alignment))
|
||||
}
|
||||
|
||||
pub fn set_text_ratio(&self, ratio: f32) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_text_ratio(ratio))
|
||||
pub fn set_text_ratio(&self, gui_handler: &mut GuiHandler, ratio: f32) -> Result<()> {
|
||||
self.iter_label(|label, _| label.set_text_ratio(gui_handler, ratio))
|
||||
}
|
||||
|
||||
pub fn set_background(self: &Arc<Self>, background: impl Into<FillTypeInfo>) -> Result<()> {
|
||||
self.grid.set_background(background)?;
|
||||
pub fn set_background(
|
||||
self: &Arc<Self>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
background: impl Into<FillTypeInfo>,
|
||||
) -> Result<()> {
|
||||
self.grid.set_background(gui_handler, background)?;
|
||||
self.update_color_change();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn focus_input(&self) -> Result<()> {
|
||||
self.writeable.set_active()
|
||||
pub fn focus_input(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.writeable.set_active(gui_handler)
|
||||
}
|
||||
|
||||
pub fn try_from(
|
||||
multi_line_text_field_info: &MultiLineTextFieldInfo,
|
||||
gui_handler: &Arc<GuiHandler>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
) -> Result<Arc<Self>> {
|
||||
let text = multi_line_text_field_info.text.read().unwrap().clone();
|
||||
let color = multi_line_text_field_info.text_color;
|
||||
|
@ -319,12 +332,12 @@ impl MultiLineTextField {
|
|||
multi_line_text_field_builder = multi_line_text_field_builder.set_text(text);
|
||||
}
|
||||
|
||||
multi_line_text_field_builder.build(gui_handler.clone())
|
||||
multi_line_text_field_builder.build(gui_handler)
|
||||
}
|
||||
|
||||
fn iter_label<F>(&self, f: F) -> Result<()>
|
||||
fn iter_label<F>(&self, mut f: F) -> Result<()>
|
||||
where
|
||||
F: Fn(&Label, usize) -> Result<()>,
|
||||
F: FnMut(&Label, usize) -> Result<()>,
|
||||
{
|
||||
for y in 0..self.grid.dimensions().1 {
|
||||
let child = self.grid.child_at(0, y)?.unwrap();
|
||||
|
@ -357,22 +370,23 @@ impl Visibility for MultiLineTextField {
|
|||
self.grid.visible()
|
||||
}
|
||||
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()> {
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||
if visibility != self.visible() {
|
||||
if visibility {
|
||||
self.writeable.add()?;
|
||||
self.writeable.add(gui_handler)?;
|
||||
} else {
|
||||
self.writeable.delete()?;
|
||||
self.writeable.delete(gui_handler)?;
|
||||
}
|
||||
}
|
||||
|
||||
self.grid.set_visibility(visibility)
|
||||
self.grid.set_visibility(gui_handler, visibility)
|
||||
}
|
||||
}
|
||||
|
||||
impl Gridable for MultiLineTextField {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -380,7 +394,8 @@ impl Gridable for MultiLineTextField {
|
|||
vert_align: VerticalAlign,
|
||||
hori_align: HorizontalAlign,
|
||||
) -> Result<()> {
|
||||
self.grid.set_frame(x, y, w, h, vert_align, hori_align)?;
|
||||
self.grid
|
||||
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align)?;
|
||||
|
||||
if let Some(child) = self.grid.child_at(0, 0)? {
|
||||
let gui_element = child.downcast().unwrap();
|
||||
|
@ -401,7 +416,7 @@ impl Gridable for MultiLineTextField {
|
|||
|
||||
self.text.set_characters_per_line(max_letter_count as u32);
|
||||
|
||||
self.update_text()?;
|
||||
self.update_text(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -424,11 +439,3 @@ impl Gridable for MultiLineTextField {
|
|||
self.grid.position_extent()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for MultiLineTextField {
|
||||
fn drop(&mut self) {
|
||||
if self.visible() {
|
||||
self.writeable.delete().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::{builder::validator::progressbar_info::ProgressBarInfo, prelude::*};
|
|||
|
||||
use anyhow::Result;
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
};
|
||||
use utilities::prelude::*;
|
||||
|
||||
|
@ -74,17 +74,17 @@ impl ProgressBarBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<ProgressBar>> {
|
||||
let framable = Framable::new(gui_handler, false)?;
|
||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<ProgressBar>> {
|
||||
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
|
||||
|
||||
let background = self
|
||||
.background
|
||||
.map(|r#type| FillType::new(framable.clone(), r#type))
|
||||
.map(|r#type| FillType::new(gui_handler, framable.clone(), r#type))
|
||||
.transpose()?;
|
||||
|
||||
let foreground = self
|
||||
.foreground
|
||||
.map(|r#type| FillType::new(framable.clone(), r#type))
|
||||
.map(|r#type| FillType::new(gui_handler, framable.clone(), r#type))
|
||||
.transpose()?;
|
||||
|
||||
let textable_wrapper = TextableWrapper::new(
|
||||
|
@ -95,7 +95,7 @@ impl ProgressBarBuilder {
|
|||
);
|
||||
|
||||
if let Some(text) = self.text {
|
||||
textable_wrapper.set_text(&text, false)?;
|
||||
textable_wrapper.set_text(gui_handler, &text, false)?;
|
||||
}
|
||||
|
||||
Ok(Arc::new(ProgressBar {
|
||||
|
@ -140,7 +140,7 @@ impl ProgressBar {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_progress(&self, mut progress: f32) -> Result<()> {
|
||||
pub fn set_progress(&self, gui_handler: &mut GuiHandler, mut progress: f32) -> Result<()> {
|
||||
if progress < 0.0 {
|
||||
progress = 0.0;
|
||||
} else if progress > 1.0 {
|
||||
|
@ -156,22 +156,22 @@ impl ProgressBar {
|
|||
InnerFillType::Image(displayable) => {
|
||||
displayable.set_right_factor(progress);
|
||||
displayable.set_right_uv_factor(progress);
|
||||
displayable.update_frame()?;
|
||||
displayable.update_frame(gui_handler)?;
|
||||
}
|
||||
InnerFillType::Color(colorable) => {
|
||||
colorable.set_right_factor(progress);
|
||||
colorable.update_frame()?;
|
||||
colorable.update_frame(gui_handler)?;
|
||||
}
|
||||
},
|
||||
GrowDirection::BottomToTop => match &foreground.inner {
|
||||
InnerFillType::Image(displayable) => {
|
||||
displayable.set_top_factor(progress);
|
||||
displayable.set_top_uv_factor(progress);
|
||||
displayable.update_frame()?;
|
||||
displayable.update_frame(gui_handler)?;
|
||||
}
|
||||
InnerFillType::Color(colorable) => {
|
||||
colorable.set_top_factor(progress);
|
||||
colorable.update_frame()?;
|
||||
colorable.update_frame(gui_handler)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -181,25 +181,32 @@ impl ProgressBar {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_text(&self, text: impl ToString) -> Result<()> {
|
||||
self.textable_wrapper.set_text(text, self.visible())
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
|
||||
self.textable_wrapper
|
||||
.set_text(gui_handler, text, self.visible())
|
||||
}
|
||||
|
||||
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
|
||||
self.textable_wrapper.set_text_color(text_color)
|
||||
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
|
||||
self.textable_wrapper
|
||||
.set_text_color(gui_handler, text_color)
|
||||
}
|
||||
|
||||
pub fn set_text_ratio(&self, ratio: f32) -> Result<()> {
|
||||
self.textable_wrapper.set_height_ratio(ratio)
|
||||
pub fn set_text_ratio(&self, gui_handler: &mut GuiHandler, ratio: f32) -> Result<()> {
|
||||
self.textable_wrapper.set_height_ratio(gui_handler, ratio)
|
||||
}
|
||||
|
||||
pub fn set_text_alignment(&self, text_alignment: TextAlignment) -> Result<()> {
|
||||
self.textable_wrapper.set_alignment(text_alignment)
|
||||
pub fn set_text_alignment(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
text_alignment: TextAlignment,
|
||||
) -> Result<()> {
|
||||
self.textable_wrapper
|
||||
.set_alignment(gui_handler, text_alignment)
|
||||
}
|
||||
|
||||
pub fn try_from(
|
||||
progress_bar_info: &ProgressBarInfo,
|
||||
gui_handler: &Arc<GuiHandler>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
) -> Result<Arc<Self>> {
|
||||
let mut progress_bar_builder = ProgressBar::builder()
|
||||
.set_text_alignment(progress_bar_info.text_alignment)
|
||||
|
@ -227,7 +234,7 @@ impl ProgressBar {
|
|||
progress_bar_builder = progress_bar_builder.set_grow_direction(dir);
|
||||
}
|
||||
|
||||
progress_bar_builder.build(gui_handler.clone())
|
||||
progress_bar_builder.build(gui_handler)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -235,18 +242,18 @@ impl ProgressBar {
|
|||
*self.progress.lock().unwrap()
|
||||
}
|
||||
|
||||
fn disable_base(&self) -> Result<()> {
|
||||
Framable::delete(&self.framable)?;
|
||||
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.framable.delete(gui_handler)?;
|
||||
|
||||
if let Some(background) = &self.background {
|
||||
background.disable()?;
|
||||
background.disable(gui_handler)?;
|
||||
}
|
||||
|
||||
if let Some(foreground) = &self.foreground {
|
||||
foreground.disable()?;
|
||||
foreground.disable(gui_handler)?;
|
||||
}
|
||||
|
||||
self.textable_wrapper.disable()?;
|
||||
self.textable_wrapper.disable(gui_handler)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -271,24 +278,24 @@ impl Visibility for ProgressBar {
|
|||
self.visible.load(SeqCst)
|
||||
}
|
||||
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()> {
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||
if visibility != self.visible() {
|
||||
self.visible.store(visibility, SeqCst);
|
||||
|
||||
if visibility {
|
||||
Framable::add(&self.framable)?;
|
||||
self.framable.add(gui_handler)?;
|
||||
|
||||
if let Some(background) = &self.background {
|
||||
background.enable()?;
|
||||
background.enable(gui_handler)?;
|
||||
}
|
||||
|
||||
if let Some(foreground) = &self.foreground {
|
||||
foreground.enable()?;
|
||||
foreground.enable(gui_handler)?;
|
||||
}
|
||||
|
||||
self.textable_wrapper.enable()?;
|
||||
self.textable_wrapper.enable(gui_handler)?;
|
||||
} else {
|
||||
self.disable_base()?;
|
||||
self.disable_base(gui_handler)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,6 +306,7 @@ impl Visibility for ProgressBar {
|
|||
impl Gridable for ProgressBar {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -306,17 +314,18 @@ impl Gridable for ProgressBar {
|
|||
vert_align: VerticalAlign,
|
||||
hori_align: HorizontalAlign,
|
||||
) -> Result<()> {
|
||||
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
|
||||
self.framable
|
||||
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
|
||||
|
||||
if let Some(background) = &self.background {
|
||||
background.update_frame()?;
|
||||
background.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
if let Some(foreground) = &self.foreground {
|
||||
foreground.update_frame()?;
|
||||
foreground.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
self.textable_wrapper.update()?;
|
||||
self.textable_wrapper.update(gui_handler)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -348,11 +357,3 @@ impl Gridable for ProgressBar {
|
|||
self.framable.position()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ProgressBar {
|
||||
fn drop(&mut self) {
|
||||
if self.visible.load(SeqCst) {
|
||||
self.disable_base().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ use anyhow::Result;
|
|||
use utilities::prelude::*;
|
||||
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
Arc, RwLock,
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
};
|
||||
|
||||
use super::fill_type::{FillType, InnerFillType};
|
||||
|
@ -48,17 +48,18 @@ impl TextFieldBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn build(self, gui_handler: Arc<GuiHandler>) -> Result<Arc<TextField>> {
|
||||
let framable = Framable::new(gui_handler.clone(), false)?;
|
||||
pub fn build(self, gui_handler: &mut GuiHandler) -> Result<Arc<TextField>> {
|
||||
let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?;
|
||||
|
||||
let background = RwLock::new(
|
||||
self.background
|
||||
.clone()
|
||||
.map(|info| FillType::new(framable.clone(), info))
|
||||
.map(|info| FillType::new(gui_handler, framable.clone(), info))
|
||||
.transpose()?,
|
||||
);
|
||||
|
||||
let textable = Textable::new(
|
||||
gui_handler,
|
||||
framable.clone(),
|
||||
match self.text {
|
||||
Some(text) => text,
|
||||
|
@ -69,13 +70,9 @@ impl TextFieldBuilder {
|
|||
self.text_color,
|
||||
)?;
|
||||
|
||||
let text_changed_executable = Executable::new(&gui_handler);
|
||||
let text_changed_executable = Executable::new();
|
||||
|
||||
let writeable = Writeable::new(
|
||||
gui_handler,
|
||||
textable.clone(),
|
||||
text_changed_executable.clone(),
|
||||
)?;
|
||||
let writeable = Writeable::new(textable.clone(), text_changed_executable.clone())?;
|
||||
|
||||
let text_field = Arc::new(TextField {
|
||||
framable,
|
||||
|
@ -117,7 +114,7 @@ impl TextField {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn try_from(info: &TextFieldInfo, gui_handler: &Arc<GuiHandler>) -> Result<Arc<Self>> {
|
||||
pub fn try_from(info: &TextFieldInfo, gui_handler: &mut GuiHandler) -> Result<Arc<Self>> {
|
||||
let text = info.text.read().unwrap().clone();
|
||||
let color = info.text_color;
|
||||
|
||||
|
@ -137,7 +134,7 @@ impl TextField {
|
|||
text_field_builder = text_field_builder.set_text(text);
|
||||
}
|
||||
|
||||
text_field_builder.build(gui_handler.clone())
|
||||
text_field_builder.build(gui_handler)
|
||||
}
|
||||
|
||||
fn update_color_change(self: &Arc<Self>) {
|
||||
|
@ -148,54 +145,61 @@ impl TextField {
|
|||
|
||||
let weak_self = Arc::downgrade(self);
|
||||
|
||||
self.writeable.set_activation_changed(move |active| {
|
||||
if let Some(me) = weak_self.upgrade() {
|
||||
if active {
|
||||
if let Some(background) = &*me.background.read().unwrap() {
|
||||
self.writeable
|
||||
.set_activation_changed(move |gui_handler, active| {
|
||||
if let Some(me) = weak_self.upgrade() {
|
||||
if active {
|
||||
if let Some(background) = &*me.background.read().unwrap() {
|
||||
if let InnerFillType::Color(colorable) = &background.inner {
|
||||
colorable.set_color(gui_handler, focus_color)?;
|
||||
}
|
||||
}
|
||||
} else if let Some(background) = &*me.background.read().unwrap() {
|
||||
if let InnerFillType::Color(colorable) = &background.inner {
|
||||
colorable.set_color(focus_color)?;
|
||||
colorable.set_color(gui_handler, normal_color)?;
|
||||
}
|
||||
}
|
||||
} else if let Some(background) = &*me.background.read().unwrap() {
|
||||
if let InnerFillType::Color(colorable) = &background.inner {
|
||||
colorable.set_color(normal_color)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
});
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_text_changed_callback<F>(&self, f: F)
|
||||
where
|
||||
F: Fn(Option<String>) -> Result<()> + Send + Sync + 'static,
|
||||
F: Fn(&mut GuiHandler, Option<String>) -> Result<()> + Send + Sync + 'static,
|
||||
{
|
||||
self.text_changed_executable.set_callback(f);
|
||||
}
|
||||
|
||||
pub fn set_text_color(&self, text_color: Color) -> Result<()> {
|
||||
self.textable.set_text_color(text_color)
|
||||
pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> {
|
||||
self.textable.set_text_color(gui_handler, text_color)
|
||||
}
|
||||
|
||||
pub fn set_text(&self, text: impl ToString) -> Result<()> {
|
||||
self.textable.set_text(text)
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
|
||||
self.textable.set_text(gui_handler, text)
|
||||
}
|
||||
|
||||
pub fn text(&self) -> Option<String> {
|
||||
let t = self.textable.text();
|
||||
|
||||
if t.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(t)
|
||||
}
|
||||
if t.is_empty() { None } else { Some(t) }
|
||||
}
|
||||
|
||||
pub fn set_background(self: &Arc<Self>, background: impl Into<FillTypeInfo>) -> Result<()> {
|
||||
super::set_background(self.visible(), &self.framable, &self.background, background)?;
|
||||
pub fn set_background(
|
||||
self: &Arc<Self>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
background: impl Into<FillTypeInfo>,
|
||||
) -> Result<()> {
|
||||
super::set_background(
|
||||
gui_handler,
|
||||
self.visible(),
|
||||
&self.framable,
|
||||
&self.background,
|
||||
background,
|
||||
)?;
|
||||
|
||||
self.update_color_change();
|
||||
|
||||
|
@ -212,25 +216,25 @@ impl TextField {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn add_letter(&self, letter: char) -> Result<()> {
|
||||
self.writeable.add_letter(letter)
|
||||
pub fn add_letter(&self, gui_handler: &mut GuiHandler, letter: char) -> Result<()> {
|
||||
self.writeable.add_letter(gui_handler, letter)
|
||||
}
|
||||
|
||||
pub fn remove_last(&self) -> Result<()> {
|
||||
self.writeable.remove_last()
|
||||
pub fn remove_last(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.writeable.remove_last(gui_handler)
|
||||
}
|
||||
|
||||
pub fn focus_input(&self) -> Result<()> {
|
||||
self.writeable.set_active()
|
||||
pub fn focus_input(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.writeable.set_active(gui_handler)
|
||||
}
|
||||
|
||||
fn disable_base(&self) -> Result<()> {
|
||||
self.framable.delete()?;
|
||||
self.textable.delete()?;
|
||||
self.writeable.delete()?;
|
||||
fn disable_base(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.framable.delete(gui_handler)?;
|
||||
self.textable.delete(gui_handler)?;
|
||||
self.writeable.delete(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.disable()?;
|
||||
background.disable(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -254,6 +258,7 @@ impl GuiElementTraits for TextField {
|
|||
impl Gridable for TextField {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -261,12 +266,13 @@ impl Gridable for TextField {
|
|||
vert_align: VerticalAlign,
|
||||
hori_align: HorizontalAlign,
|
||||
) -> Result<()> {
|
||||
self.framable.set_frame(x, y, w, h, vert_align, hori_align);
|
||||
self.framable
|
||||
.set_frame(gui_handler, x, y, w, h, vert_align, hori_align);
|
||||
|
||||
self.textable.update_text()?;
|
||||
self.textable.update_text(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.update_frame()?;
|
||||
background.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -304,33 +310,23 @@ impl Visibility for TextField {
|
|||
self.visible.load(SeqCst)
|
||||
}
|
||||
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()> {
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> {
|
||||
if visibility != self.visible() {
|
||||
self.visible.store(visibility, SeqCst);
|
||||
|
||||
if visibility {
|
||||
self.framable.add()?;
|
||||
self.textable.add()?;
|
||||
self.writeable.add()?;
|
||||
self.framable.add(gui_handler)?;
|
||||
self.textable.add(gui_handler)?;
|
||||
self.writeable.add(gui_handler)?;
|
||||
|
||||
if let Some(background) = self.background.read().unwrap().as_ref() {
|
||||
background.enable()?;
|
||||
background.enable(gui_handler)?;
|
||||
}
|
||||
} else {
|
||||
self.disable_base()?;
|
||||
self.disable_base(gui_handler)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TextField {
|
||||
fn drop(&mut self) {
|
||||
if self.visible() {
|
||||
self.disable_base().unwrap();
|
||||
}
|
||||
|
||||
self.textable.clear_callback();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ pub trait GuiElementTraits: Send + Sync {
|
|||
pub trait Gridable {
|
||||
fn set_frame(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: u32,
|
||||
|
@ -73,7 +74,7 @@ pub trait Gridable {
|
|||
|
||||
pub trait Visibility {
|
||||
fn visible(&self) -> bool;
|
||||
fn set_visibility(&self, visibility: bool) -> Result<()>;
|
||||
fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()>;
|
||||
}
|
||||
|
||||
pub enum GuiElement<'a> {
|
||||
|
|
|
@ -35,7 +35,7 @@ impl Debug for UiElement {
|
|||
|
||||
macro_rules! impl_from {
|
||||
($data_type:ident $(< $($lt:lifetime),+ >)? ) => {
|
||||
impl From<&Arc<$data_type$(<$($lt,)+>)?>> for UiElement {
|
||||
impl<'a> From<&Arc<$data_type$(<$($lt,)+>)?>> for UiElement {
|
||||
fn from(v: &Arc<$data_type$(<$($lt,)+>)?>) -> Self {
|
||||
UiElement::$data_type(Arc::downgrade(v))
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ pub trait GetElement<T> {
|
|||
|
||||
macro_rules! impl_element {
|
||||
($data_type:ident $(< $($lt:lifetime),+ >)? ) => {
|
||||
impl GetElement<$data_type$(<$($lt,)+>)?> for HashMap<String, UiElement> {
|
||||
impl<'a> GetElement<$data_type$(<$($lt,)+>)?> for HashMap<String, UiElement> {
|
||||
fn element(&self, id: &str) -> Result<Arc<$data_type$(<$($lt,)+>)?>> {
|
||||
match self.get(id) {
|
||||
Some(element) => match element {
|
||||
|
|
|
@ -4,8 +4,8 @@ use crate::{
|
|||
};
|
||||
use anyhow::Result;
|
||||
use std::sync::{
|
||||
atomic::{AtomicU32, Ordering::SeqCst},
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicU32, Ordering::SeqCst},
|
||||
};
|
||||
use utilities::prelude::*;
|
||||
use vulkan_rs::prelude::*;
|
||||
|
@ -48,17 +48,26 @@ impl TextableWrapper {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn set_text_color(&self, text_color: Color) -> Result<()> {
|
||||
pub(crate) fn set_text_color(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
text_color: Color,
|
||||
) -> Result<()> {
|
||||
*self.color.lock().unwrap() = text_color;
|
||||
|
||||
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
|
||||
textable.set_text_color(text_color)?;
|
||||
textable.set_text_color(gui_handler, text_color)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn set_text(&self, text: impl ToString, is_visible: bool) -> Result<()> {
|
||||
pub(crate) fn set_text(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
text: impl ToString,
|
||||
is_visible: bool,
|
||||
) -> Result<()> {
|
||||
let text = text.to_string();
|
||||
let mut textable = self.textable.lock().unwrap();
|
||||
|
||||
|
@ -68,17 +77,18 @@ impl TextableWrapper {
|
|||
current_textable.clear_callback();
|
||||
|
||||
if is_visible {
|
||||
current_textable.delete()?;
|
||||
current_textable.delete(gui_handler)?;
|
||||
}
|
||||
|
||||
*textable = None;
|
||||
} else {
|
||||
current_textable.set_text(text)?;
|
||||
current_textable.set_text(gui_handler, text)?;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
if !text.is_empty() {
|
||||
let new_textable = Textable::new(
|
||||
gui_handler,
|
||||
self.framable.clone(),
|
||||
text,
|
||||
*self.ratio.lock().unwrap(),
|
||||
|
@ -87,13 +97,13 @@ impl TextableWrapper {
|
|||
)?;
|
||||
|
||||
if self.framable.is_framed() {
|
||||
new_textable.update_text()?;
|
||||
new_textable.update_text(gui_handler)?;
|
||||
}
|
||||
|
||||
new_textable.set_ui_layer(self.framable.ui_layer());
|
||||
|
||||
if is_visible {
|
||||
new_textable.add()?;
|
||||
new_textable.add(gui_handler)?;
|
||||
}
|
||||
|
||||
*textable = Some(new_textable);
|
||||
|
@ -113,11 +123,15 @@ impl TextableWrapper {
|
|||
.map(|textable| textable.text()))
|
||||
}
|
||||
|
||||
pub(crate) fn set_height_ratio(&self, height_ratio: f32) -> Result<()> {
|
||||
pub(crate) fn set_height_ratio(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
height_ratio: f32,
|
||||
) -> Result<()> {
|
||||
*self.ratio.lock().unwrap() = height_ratio;
|
||||
|
||||
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
|
||||
textable.set_size(height_ratio)?;
|
||||
textable.set_size(gui_handler, height_ratio)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -127,35 +141,39 @@ impl TextableWrapper {
|
|||
*self.ratio.lock().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn set_alignment(&self, alignment: TextAlignment) -> Result<()> {
|
||||
pub(crate) fn set_alignment(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
alignment: TextAlignment,
|
||||
) -> Result<()> {
|
||||
*self.alignment.lock().unwrap() = alignment;
|
||||
|
||||
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
|
||||
textable.set_text_alignment(alignment)?;
|
||||
textable.set_text_alignment(gui_handler, alignment)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn update(&self) -> Result<()> {
|
||||
pub(crate) fn update(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
|
||||
textable.update_text()?;
|
||||
textable.update_text(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn enable(&self) -> Result<()> {
|
||||
pub(crate) fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
|
||||
textable.add()?;
|
||||
textable.add(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn disable(&self) -> Result<()> {
|
||||
pub(crate) fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if let Some(textable) = self.textable.lock().unwrap().as_ref() {
|
||||
textable.delete()?;
|
||||
textable.delete(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -180,13 +198,15 @@ pub(crate) struct IconizableWrapper {
|
|||
|
||||
impl IconizableWrapper {
|
||||
pub(crate) fn new(
|
||||
gui_handler: &mut GuiHandler,
|
||||
framable: Arc<Framable>,
|
||||
builder: Option<IconBuilderType>,
|
||||
positioning: Option<IconizablePositioning>,
|
||||
margin: u32,
|
||||
) -> Result<Self> {
|
||||
let iconizable: Option<Result<Arc<Iconizable>>> = builder.map(|content| {
|
||||
let iconizable = Iconizable::new(framable.clone(), content, positioning.clone())?;
|
||||
let iconizable =
|
||||
Iconizable::new(gui_handler, framable.clone(), content, positioning.clone())?;
|
||||
|
||||
iconizable.set_margin(margin)?;
|
||||
|
||||
|
@ -214,12 +234,16 @@ impl IconizableWrapper {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn clear_icon(&self, is_visible: bool) -> Result<()> {
|
||||
pub(crate) fn clear_icon(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
is_visible: bool,
|
||||
) -> Result<()> {
|
||||
let mut iconizable = self.iconizable.lock().unwrap();
|
||||
|
||||
if let Some(iconizable) = iconizable.as_ref() {
|
||||
if is_visible {
|
||||
iconizable.delete()?;
|
||||
iconizable.delete(gui_handler)?;
|
||||
}
|
||||
|
||||
iconizable.clear_callback();
|
||||
|
@ -232,15 +256,17 @@ impl IconizableWrapper {
|
|||
|
||||
pub(crate) fn set_icon(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler,
|
||||
icon_builder: impl Into<IconBuilderType>,
|
||||
is_visible: bool,
|
||||
) -> Result<()> {
|
||||
let mut iconizable = self.iconizable.lock().unwrap();
|
||||
|
||||
match iconizable.as_ref() {
|
||||
Some(iconizable) => iconizable.set_icon(icon_builder)?,
|
||||
Some(iconizable) => iconizable.set_icon(gui_handler, icon_builder)?,
|
||||
None => {
|
||||
let new_iconizable = Iconizable::new(
|
||||
gui_handler,
|
||||
self.framable.clone(),
|
||||
icon_builder,
|
||||
self.positioning.clone(),
|
||||
|
@ -249,13 +275,13 @@ impl IconizableWrapper {
|
|||
new_iconizable.set_margin(self.margin.load(SeqCst))?;
|
||||
|
||||
if self.framable.is_framed() {
|
||||
new_iconizable.update_frame()?;
|
||||
new_iconizable.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
new_iconizable.set_ui_layer(self.framable.ui_layer());
|
||||
|
||||
if is_visible {
|
||||
new_iconizable.add()?;
|
||||
new_iconizable.add(gui_handler)?;
|
||||
}
|
||||
|
||||
*iconizable = Some(new_iconizable);
|
||||
|
@ -265,11 +291,11 @@ impl IconizableWrapper {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn set_margin(&self, margin: u32) -> Result<()> {
|
||||
pub(crate) fn set_margin(&self, gui_handler: &mut GuiHandler, margin: u32) -> Result<()> {
|
||||
if self.framable.is_framed() {
|
||||
if let Some(iconizable) = self.iconizable.lock().unwrap().as_ref() {
|
||||
iconizable.set_margin(margin)?;
|
||||
iconizable.update_frame()?;
|
||||
iconizable.update_frame(gui_handler)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,25 +311,25 @@ impl IconizableWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn enable(&self) -> Result<()> {
|
||||
pub(crate) fn enable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if let Some(iconizable) = self.iconizable.lock().unwrap().as_ref() {
|
||||
iconizable.add()?;
|
||||
iconizable.add(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn disable(&self) -> Result<()> {
|
||||
pub(crate) fn disable(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if let Some(iconizable) = self.iconizable.lock().unwrap().as_ref() {
|
||||
iconizable.delete()?;
|
||||
iconizable.delete(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn update_frame(&self) -> Result<()> {
|
||||
pub(crate) fn update_frame(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if let Some(iconizable) = self.iconizable.lock().unwrap().as_ref() {
|
||||
iconizable.update_frame()?;
|
||||
iconizable.update_frame(gui_handler)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -25,7 +25,8 @@ pub struct Clickable {
|
|||
ui_layer: AtomicI32,
|
||||
|
||||
executable: Arc<Executable<()>>,
|
||||
clicked_changed_callback: RwLock<Option<Box<dyn Fn() -> Result<()> + Send + Sync>>>,
|
||||
clicked_changed_callback:
|
||||
RwLock<Option<Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>>>,
|
||||
}
|
||||
|
||||
impl Clickable {
|
||||
|
@ -55,7 +56,7 @@ impl Clickable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `clickable` is a `&Arc<Clickable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.add_clickable(self.ui_layer.load(SeqCst), self.clone())
|
||||
}
|
||||
|
||||
|
@ -64,7 +65,7 @@ impl Clickable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `clickable` is a `&Arc<Clickable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.delete_clickable(self.ui_layer.load(SeqCst), self)?;
|
||||
self.set_clicked(gui_handler, false)?;
|
||||
|
||||
|
@ -89,7 +90,7 @@ impl Clickable {
|
|||
/// * `clicked_changed_callback` is a `Option<Box<Callback>>`
|
||||
pub fn set_clicked_changed_callback(
|
||||
&self,
|
||||
clicked_changed_callback: Option<Box<dyn Fn() -> Result<()> + Send + Sync>>,
|
||||
clicked_changed_callback: Option<Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>>,
|
||||
) {
|
||||
*self.clicked_changed_callback.write().unwrap() = clicked_changed_callback;
|
||||
}
|
||||
|
@ -99,14 +100,14 @@ impl Clickable {
|
|||
*self.audible.write().unwrap() = audible;
|
||||
}
|
||||
|
||||
pub fn set_clicked(&self, gui_handler: &mut GuiHandler<'_>, clicked: bool) -> Result<bool> {
|
||||
pub fn set_clicked(&self, gui_handler: &mut GuiHandler, clicked: bool) -> Result<bool> {
|
||||
if self.clicked() != clicked {
|
||||
self.clicked.store(clicked, SeqCst);
|
||||
|
||||
if let Some(clicked_changed_callback) =
|
||||
self.clicked_changed_callback.read().unwrap().as_ref()
|
||||
{
|
||||
clicked_changed_callback()?;
|
||||
clicked_changed_callback(gui_handler)?;
|
||||
}
|
||||
|
||||
if self.clicked() {
|
||||
|
|
|
@ -34,7 +34,7 @@ pub struct Colorable {
|
|||
impl Colorable {
|
||||
/// Factory method for `Colorable`, returns `Arc<Colorable>`.
|
||||
pub fn new(
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
framable: Arc<Framable>,
|
||||
color: Color,
|
||||
fill_type: DisplayableFillType,
|
||||
|
@ -80,7 +80,7 @@ impl Colorable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `colorable` is a `&Arc<Colorable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.add_colorable(self.ui_layer.load(SeqCst), self.clone())
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl Colorable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `colorable` is a `&Arc<Colorable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.delete_colorable(self.ui_layer.load(SeqCst), self)
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ impl Colorable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `color` defines the color
|
||||
pub fn set_color(&self, color: Color, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn set_color(&self, gui_handler: &mut GuiHandler, color: Color) -> Result<()> {
|
||||
let set = gui_handler.color_descriptor(color)?;
|
||||
|
||||
*self.color.write().unwrap() = color;
|
||||
|
@ -147,7 +147,7 @@ impl Colorable {
|
|||
}
|
||||
|
||||
/// Update frame method if the original frame is invalidated
|
||||
pub fn update_frame(&self, gui_handler: &GuiHandler<'_>) -> Result<()> {
|
||||
pub fn update_frame(&self, gui_handler: &GuiHandler) -> Result<()> {
|
||||
let mut frame = self.buffer.map_complete()?;
|
||||
|
||||
let mut x_start = self.framable.left() as f32;
|
||||
|
|
|
@ -71,7 +71,7 @@ impl Displayable {
|
|||
/// * `framable` is a `Arc<Framable>` instance
|
||||
/// * `name` is the name for a png
|
||||
pub fn new(
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
framable: Arc<Framable>,
|
||||
displayable_type: impl Into<DisplayableType>,
|
||||
fill_type: DisplayableFillType,
|
||||
|
@ -128,7 +128,7 @@ impl Displayable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `displayable` is a `&Arc<Displayable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.add_displayable(self.ui_layer.load(SeqCst), self.clone())
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ impl Displayable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `displayable` is a `&Arc<Displayable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.delete_displayable(self.ui_layer.load(SeqCst), self)
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ impl Displayable {
|
|||
/// * `name` is the name of the texture in `gui/` without `.png` suffix
|
||||
pub fn set_image(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
displayable_type: impl Into<DisplayableType>,
|
||||
) -> Result<()> {
|
||||
let displayable_type = displayable_type.into();
|
||||
|
@ -233,7 +233,7 @@ impl Displayable {
|
|||
}
|
||||
|
||||
/// Update frame method if the original frame is invalidated
|
||||
pub fn update_frame(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn update_frame(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
let mut frame = self.buffer.map_complete()?;
|
||||
|
||||
let mut x_start = self.framable.left() as f32;
|
||||
|
|
|
@ -7,8 +7,8 @@ use std::sync::{Arc, RwLock};
|
|||
use crate::prelude::*;
|
||||
|
||||
/// `Executable` holds a closure which can be executed
|
||||
pub struct Executable<I: Send + Sync + 'static> {
|
||||
callback: RwLock<Option<Arc<dyn Fn(I) -> Result<()> + Send + Sync>>>,
|
||||
pub struct Executable<I: Send + Sync> {
|
||||
callback: RwLock<Option<Arc<dyn Fn(&mut GuiHandler, I) -> Result<()> + Send + Sync>>>,
|
||||
}
|
||||
|
||||
impl<I: Send + Sync + 'static> Executable<I> {
|
||||
|
@ -26,7 +26,7 @@ impl<I: Send + Sync + 'static> Executable<I> {
|
|||
/// * `callback` is a `Option<Callback>` closure
|
||||
pub fn set_callback<F>(&self, callback: impl Into<Option<F>>)
|
||||
where
|
||||
F: Fn(I) -> Result<()> + Send + Sync + 'static,
|
||||
F: Fn(&mut GuiHandler, I) -> Result<()> + Send + Sync + 'static,
|
||||
{
|
||||
let mut function = self.callback.write().unwrap();
|
||||
|
||||
|
@ -37,11 +37,11 @@ impl<I: Send + Sync + 'static> Executable<I> {
|
|||
}
|
||||
|
||||
/// Execute the callback closure if possible
|
||||
pub fn execute(&self, gui_handler: &mut GuiHandler<'_>, input: I) -> Result<()> {
|
||||
pub fn execute(&self, gui_handler: &mut GuiHandler, input: I) -> Result<()> {
|
||||
if let Some(callback) = self.callback.read().unwrap().as_ref() {
|
||||
let callback = callback.clone();
|
||||
|
||||
gui_handler.add_callback(move || (callback)(input));
|
||||
gui_handler.add_callback(move |gui_handler| (callback)(gui_handler, input));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -86,7 +86,7 @@ pub struct Framable {
|
|||
resize_callbacks: RwLock<
|
||||
Vec<(
|
||||
Handle,
|
||||
Box<dyn Fn(&mut GuiHandler<'_>) -> Result<()> + Send + Sync>,
|
||||
Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>,
|
||||
)>,
|
||||
>,
|
||||
|
||||
|
@ -149,7 +149,7 @@ impl Framable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `framable` - is a `&Arc<Framable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
// check if window size is the same as last time
|
||||
if gui_handler.width() != self.window_width.load(SeqCst)
|
||||
|| gui_handler.height() != self.window_height.load(SeqCst)
|
||||
|
@ -174,7 +174,7 @@ impl Framable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `framable` - is a `&Arc<Framable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if self.resize_allowed() {
|
||||
gui_handler.delete_framable(self.ui_layer.load(SeqCst), self)?;
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ impl Framable {
|
|||
|
||||
pub(crate) fn set_reference_size(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<()> {
|
||||
|
@ -209,7 +209,7 @@ impl Framable {
|
|||
|
||||
pub(crate) fn allow_position_scale(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
allowed: bool,
|
||||
) -> Result<()> {
|
||||
if allowed != self.reference_scale_position.load(SeqCst) {
|
||||
|
@ -225,7 +225,7 @@ impl Framable {
|
|||
|
||||
pub(crate) fn allow_size_scale(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
allowed: bool,
|
||||
) -> Result<()> {
|
||||
if allowed != self.reference_scale_size.load(SeqCst) {
|
||||
|
@ -247,7 +247,7 @@ impl Framable {
|
|||
/// width and a certain alignment
|
||||
pub fn set_frame(
|
||||
&self,
|
||||
gui_handler: &GuiHandler<'_>,
|
||||
gui_handler: &GuiHandler,
|
||||
x_off: i32,
|
||||
y_off: i32,
|
||||
w: u32,
|
||||
|
@ -311,7 +311,7 @@ impl Framable {
|
|||
pub fn add_callback(
|
||||
&self,
|
||||
handle: impl Into<Handle>,
|
||||
callback: Box<dyn Fn(&mut GuiHandler<'_>) -> Result<()> + Send + Sync>,
|
||||
callback: Box<dyn Fn(&mut GuiHandler) -> Result<()> + Send + Sync>,
|
||||
) {
|
||||
let handle = handle.into();
|
||||
|
||||
|
@ -354,7 +354,7 @@ impl Framable {
|
|||
*self.horizontal_alignment.read().unwrap()
|
||||
}
|
||||
|
||||
fn calculate_frame(&self, gui_handler: &GuiHandler<'_>) {
|
||||
fn calculate_frame(&self, gui_handler: &GuiHandler) {
|
||||
let width = gui_handler.width();
|
||||
let height = gui_handler.height();
|
||||
|
||||
|
@ -428,7 +428,7 @@ impl Framable {
|
|||
|
||||
pub fn change_position(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x_offset: i32,
|
||||
y_offset: i32,
|
||||
) -> Result<()> {
|
||||
|
@ -443,7 +443,7 @@ impl Framable {
|
|||
}
|
||||
pub fn change_position_unscaled(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
x: i32,
|
||||
y: i32,
|
||||
) -> Result<()> {
|
||||
|
@ -469,7 +469,7 @@ impl Framable {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resize(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn resize(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.calculate_frame(gui_handler);
|
||||
|
||||
for (_, callback) in self.resize_callbacks.read().unwrap().iter() {
|
||||
|
|
|
@ -56,7 +56,7 @@ impl Hoverable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `hoverable` is a `&Arc<Hoverable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.add_hoverable(self.ui_layer.load(SeqCst), self.clone())?;
|
||||
|
||||
Ok(())
|
||||
|
@ -67,7 +67,7 @@ impl Hoverable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `hoverable` is a `&Arc<Hoverable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.delete_hoverable(self.ui_layer.load(SeqCst), self)?;
|
||||
self.set_hovered(gui_handler, false)?;
|
||||
|
||||
|
@ -103,7 +103,7 @@ impl Hoverable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `hovered` is the new hovered state
|
||||
pub fn set_hovered(&self, gui_handler: &mut GuiHandler<'_>, hovered: bool) -> Result<()> {
|
||||
pub fn set_hovered(&self, gui_handler: &mut GuiHandler, hovered: bool) -> Result<()> {
|
||||
if self.hovered() != hovered {
|
||||
self.hovered.store(hovered, SeqCst);
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ impl Iconizable {
|
|||
/// * `framable` is a `Arc<Framable>` instance
|
||||
/// * `icon` is a reference to an `Arc<Image>`
|
||||
pub fn new(
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
framable: Arc<Framable>,
|
||||
icon_builder: impl Into<IconBuilderType>,
|
||||
positioning: impl Into<Option<IconizablePositioning>>,
|
||||
|
@ -137,7 +137,7 @@ impl Iconizable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `iconizable` is a `&Arc<Iconizable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.add_iconizable(self.ui_layer.load(SeqCst), self.clone())
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ impl Iconizable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `iconizable` is a `&Arc<Iconizable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.delete_iconizable(self.ui_layer.load(SeqCst), self)
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ impl Iconizable {
|
|||
}
|
||||
|
||||
/// Updates the frame
|
||||
pub fn update_frame(&self, gui_handler: &GuiHandler<'_>) -> Result<()> {
|
||||
pub fn update_frame(&self, gui_handler: &GuiHandler) -> Result<()> {
|
||||
assert!(self.framable.is_framed(), "framable is not framed yet");
|
||||
|
||||
// frame parameter
|
||||
|
@ -269,7 +269,7 @@ impl Iconizable {
|
|||
/// * `icon` the new icon
|
||||
pub fn set_icon(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
icon_builder: impl Into<IconBuilderType>,
|
||||
) -> Result<()> {
|
||||
let icon = gui_handler.request_icon(icon_builder)?;
|
||||
|
|
|
@ -12,13 +12,13 @@ use std::sync::{
|
|||
/// `Selectable` gives the ability to navigate per button or controller to
|
||||
/// optionally adjacent neighbour Selectables and to execute a closure
|
||||
/// when the current Selectable is pressed
|
||||
pub struct Selectable<'a> {
|
||||
pub struct Selectable {
|
||||
selected: AtomicBool,
|
||||
|
||||
east_neighbour: RwLock<Option<Weak<Selectable<'a>>>>,
|
||||
west_neighbour: RwLock<Option<Weak<Selectable<'a>>>>,
|
||||
north_neighbour: RwLock<Option<Weak<Selectable<'a>>>>,
|
||||
south_neighbour: RwLock<Option<Weak<Selectable<'a>>>>,
|
||||
east_neighbour: RwLock<Option<Weak<Selectable>>>,
|
||||
west_neighbour: RwLock<Option<Weak<Selectable>>>,
|
||||
north_neighbour: RwLock<Option<Weak<Selectable>>>,
|
||||
south_neighbour: RwLock<Option<Weak<Selectable>>>,
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
select_audible: RwLock<Option<Arc<Audible>>>,
|
||||
|
@ -30,29 +30,28 @@ pub struct Selectable<'a> {
|
|||
isolate: bool,
|
||||
|
||||
// used when clicked
|
||||
executable: Arc<Executable<&'a mut World>>,
|
||||
executable: Arc<Executable<()>>,
|
||||
|
||||
// used internally by button
|
||||
selected_changed_executable: Arc<Executable<(&'a mut World, bool)>>,
|
||||
selected_changed_executable: Arc<Executable<bool>>,
|
||||
|
||||
// exposed externally for event
|
||||
on_select_executable: Arc<Executable<(&'a mut World, bool)>>,
|
||||
on_select_executable: Arc<Executable<bool>>,
|
||||
|
||||
// used for custom buttons
|
||||
custom_callback:
|
||||
RwLock<Option<Box<dyn Fn(&mut World, ControllerButton) -> Result<bool> + Send + Sync>>>,
|
||||
custom_callback: RwLock<Option<Box<dyn Fn(ControllerButton) -> Result<bool> + Send + Sync>>>,
|
||||
}
|
||||
|
||||
impl<'a> Selectable<'a> {
|
||||
impl Selectable {
|
||||
/// Factory method for `Selectable`, returns `Arc<Selectable>`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `executable` is a `Arc<Executable>` instance
|
||||
pub fn new(
|
||||
executable: Arc<Executable<&'a mut World>>,
|
||||
selected_changed_executable: Arc<Executable<(&'a mut World, bool)>>,
|
||||
on_select_executable: Arc<Executable<(&'a mut World, bool)>>,
|
||||
executable: Arc<Executable<()>>,
|
||||
selected_changed_executable: Arc<Executable<bool>>,
|
||||
on_select_executable: Arc<Executable<bool>>,
|
||||
isolate: bool,
|
||||
) -> Arc<Self> {
|
||||
Arc::new(Selectable {
|
||||
|
@ -85,7 +84,7 @@ impl<'a> Selectable<'a> {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `selectable` is a `&Arc<Selectable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.add_selectable(self.ui_layer.load(SeqCst), self.clone())
|
||||
}
|
||||
|
||||
|
@ -94,7 +93,7 @@ impl<'a> Selectable<'a> {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `selectable` is a `&Arc<Selectable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.delete_selectable(self.ui_layer.load(SeqCst), self)?;
|
||||
self.set_selected(gui_handler, false)?;
|
||||
|
||||
|
@ -110,7 +109,7 @@ impl<'a> Selectable<'a> {
|
|||
/// # Argument
|
||||
///
|
||||
/// * `selectable` is a `Arc<Selectable>` instance
|
||||
pub fn select(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn select(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.set_selectable(Some(self.clone()))
|
||||
}
|
||||
|
||||
|
@ -137,7 +136,7 @@ impl<'a> Selectable<'a> {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `selected` is the new selected state
|
||||
pub fn set_selected(&self, gui_handler: &mut GuiHandler<'_>, selected: bool) -> Result<()> {
|
||||
pub fn set_selected(&self, gui_handler: &mut GuiHandler, selected: bool) -> Result<()> {
|
||||
if self.selected() != selected {
|
||||
self.selected.store(selected, SeqCst);
|
||||
|
||||
|
@ -164,7 +163,7 @@ impl<'a> Selectable<'a> {
|
|||
}
|
||||
|
||||
/// Executes the `Executable`'s callback
|
||||
pub(crate) fn click_event(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub(crate) fn click_event(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
#[cfg(feature = "audio")]
|
||||
{
|
||||
if let Some(audible) = self.click_audible.read().unwrap().as_ref() {
|
||||
|
@ -195,7 +194,7 @@ impl<'a> Selectable<'a> {
|
|||
}
|
||||
|
||||
/// Returns the current east neighbour, if possible
|
||||
pub fn east_neighbour(&self) -> Option<Arc<Selectable<'a>>> {
|
||||
pub fn east_neighbour(&self) -> Option<Arc<Selectable>> {
|
||||
if let Some(weak_neighbour) = self.east_neighbour.read().unwrap().as_ref() {
|
||||
if let Some(neighbour) = weak_neighbour.upgrade() {
|
||||
return Some(neighbour);
|
||||
|
@ -210,7 +209,7 @@ impl<'a> Selectable<'a> {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `selectable` the new east neighbour
|
||||
pub fn set_east_neighbour(&self, selectable: Option<&Arc<Selectable<'a>>>) {
|
||||
pub fn set_east_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
||||
if self.isolate {
|
||||
return;
|
||||
}
|
||||
|
@ -224,7 +223,7 @@ impl<'a> Selectable<'a> {
|
|||
}
|
||||
|
||||
/// Returns the current west neighbour, if possible
|
||||
pub fn west_neighbour(&self) -> Option<Arc<Selectable<'a>>> {
|
||||
pub fn west_neighbour(&self) -> Option<Arc<Selectable>> {
|
||||
if let Some(weak_neighbour) = self.west_neighbour.read().unwrap().as_ref() {
|
||||
if let Some(neighbour) = weak_neighbour.upgrade() {
|
||||
return Some(neighbour);
|
||||
|
@ -239,7 +238,7 @@ impl<'a> Selectable<'a> {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `selectable` the new west neighbour
|
||||
pub fn set_west_neighbour(&self, selectable: Option<&Arc<Selectable<'a>>>) {
|
||||
pub fn set_west_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
||||
if self.isolate {
|
||||
return;
|
||||
}
|
||||
|
@ -253,7 +252,7 @@ impl<'a> Selectable<'a> {
|
|||
}
|
||||
|
||||
/// Returns the current north neighbour, if possible
|
||||
pub fn north_neighbour(&self) -> Option<Arc<Selectable<'a>>> {
|
||||
pub fn north_neighbour(&self) -> Option<Arc<Selectable>> {
|
||||
if let Some(weak_neighbour) = self.north_neighbour.read().unwrap().as_ref() {
|
||||
if let Some(neighbour) = weak_neighbour.upgrade() {
|
||||
return Some(neighbour);
|
||||
|
@ -268,7 +267,7 @@ impl<'a> Selectable<'a> {
|
|||
/// # Argumnents
|
||||
///
|
||||
/// * `selectable` the new north neighbour
|
||||
pub fn set_north_neighbour(&self, selectable: Option<&Arc<Selectable<'a>>>) {
|
||||
pub fn set_north_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
||||
if self.isolate {
|
||||
return;
|
||||
}
|
||||
|
@ -282,7 +281,7 @@ impl<'a> Selectable<'a> {
|
|||
}
|
||||
|
||||
/// Returns the current south neighbour, if possible
|
||||
pub fn south_neighbour(&self) -> Option<Arc<Selectable<'a>>> {
|
||||
pub fn south_neighbour(&self) -> Option<Arc<Selectable>> {
|
||||
if let Some(weak_neighbour) = self.south_neighbour.read().unwrap().as_ref() {
|
||||
if let Some(neighbour) = weak_neighbour.upgrade() {
|
||||
return Some(neighbour);
|
||||
|
@ -297,7 +296,7 @@ impl<'a> Selectable<'a> {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `selectable` the new south neighbour
|
||||
pub fn set_south_neighbour(&self, selectable: Option<&Arc<Selectable<'a>>>) {
|
||||
pub fn set_south_neighbour(&self, selectable: Option<&Arc<Selectable>>) {
|
||||
if self.isolate {
|
||||
return;
|
||||
}
|
||||
|
@ -310,7 +309,7 @@ impl<'a> Selectable<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn connect_vertically<'c>(upper: &Arc<Selectable<'c>>, lower: &Arc<Selectable<'c>>) {
|
||||
pub fn connect_vertically<'c>(upper: &Arc<Selectable>, lower: &Arc<Selectable>) {
|
||||
if upper.isolate || lower.isolate {
|
||||
return;
|
||||
}
|
||||
|
@ -319,7 +318,7 @@ impl<'a> Selectable<'a> {
|
|||
*lower.north_neighbour.write().unwrap() = Some(Arc::downgrade(upper));
|
||||
}
|
||||
|
||||
pub fn connect_horizontally<'c>(left: &Arc<Selectable<'c>>, right: &Arc<Selectable<'c>>) {
|
||||
pub fn connect_horizontally<'c>(left: &Arc<Selectable>, right: &Arc<Selectable>) {
|
||||
if left.isolate || right.isolate {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ impl Textable {
|
|||
/// * `height_ratio` the ratio of the height in respect to the framable height
|
||||
/// * `text_alignment` where the text is aligned to
|
||||
pub fn new(
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
framable: Arc<Framable>,
|
||||
text: String,
|
||||
height_ratio: f32,
|
||||
|
@ -143,7 +143,7 @@ impl Textable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `textable` is a `&Arc<Textable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.add_textable(self.ui_layer.load(SeqCst), self.clone())
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ impl Textable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `textable` is a `&Arc<Textable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.delete_textable(self.ui_layer.load(SeqCst), self)
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ impl Textable {
|
|||
/// * `text_color` defines the color of the text
|
||||
pub fn set_text_color(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
text_color: Color,
|
||||
) -> Result<()> {
|
||||
let set = gui_handler.color_descriptor(text_color)?;
|
||||
|
@ -189,7 +189,7 @@ impl Textable {
|
|||
/// * `text_alignment` where the text is aligned to
|
||||
pub fn set_text_alignment(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
text_alignment: TextAlignment,
|
||||
) -> Result<()> {
|
||||
*self.text_alignment.write().unwrap() = text_alignment;
|
||||
|
@ -219,7 +219,7 @@ impl Textable {
|
|||
///
|
||||
/// * `text` the text to be displayed
|
||||
/// * `height_ratio` the ratio of the height in respect to the framable height
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: impl ToString) -> Result<()> {
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> {
|
||||
let text = text.to_string();
|
||||
|
||||
if text.is_empty() {
|
||||
|
@ -250,7 +250,7 @@ impl Textable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `height_ratio` the ratio of the height in respect to the framable height
|
||||
pub fn set_size(&self, gui_handler: &mut GuiHandler<'_>, height_ratio: f32) -> Result<()> {
|
||||
pub fn set_size(&self, gui_handler: &mut GuiHandler, height_ratio: f32) -> Result<()> {
|
||||
*self.height_ratio.write().unwrap() = height_ratio;
|
||||
self.update_text(gui_handler)?;
|
||||
|
||||
|
@ -284,7 +284,7 @@ impl Textable {
|
|||
}
|
||||
|
||||
/// Updates the texts buffer
|
||||
pub fn update_text(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn update_text(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.calculate_text_size();
|
||||
|
||||
let (x, y) = self.calc_pos_from_alignment();
|
||||
|
@ -327,7 +327,7 @@ impl Textable {
|
|||
|
||||
fn create_buffer(
|
||||
&self,
|
||||
gui_handler: &mut GuiHandler<'_>,
|
||||
gui_handler: &mut GuiHandler,
|
||||
win_x: f32,
|
||||
win_y: f32,
|
||||
) -> Result<()> {
|
||||
|
@ -499,7 +499,7 @@ impl Textable {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn text_changed_through_write(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
fn text_changed_through_write(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
self.vertex_count
|
||||
.store(self.text.read().unwrap().len() as u32 * 6, SeqCst);
|
||||
self.character_size.store(
|
||||
|
@ -515,19 +515,19 @@ impl Textable {
|
|||
}
|
||||
|
||||
impl ModifyText for Textable {
|
||||
fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: String) -> Result<()> {
|
||||
fn set_text(&self, gui_handler: &mut GuiHandler, text: String) -> Result<()> {
|
||||
*self.text.write().unwrap() = text;
|
||||
self.text_changed_through_write(gui_handler)
|
||||
}
|
||||
|
||||
fn add_letter(&self, gui_handler: &mut GuiHandler<'_>, letter: char) -> Result<String> {
|
||||
fn add_letter(&self, gui_handler: &mut GuiHandler, letter: char) -> Result<String> {
|
||||
self.text.write().unwrap().push(letter);
|
||||
self.text_changed_through_write(gui_handler)?;
|
||||
|
||||
Ok(self.text.read().unwrap().clone())
|
||||
}
|
||||
|
||||
fn remove_last(&self, gui_handler: &mut GuiHandler<'_>) -> Result<Option<String>> {
|
||||
fn remove_last(&self, gui_handler: &mut GuiHandler) -> Result<Option<String>> {
|
||||
self.text.write().unwrap().pop();
|
||||
self.text_changed_through_write(gui_handler)?;
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ use std::sync::{
|
|||
};
|
||||
|
||||
pub trait ModifyText: Send + Sync {
|
||||
fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: String) -> Result<()>;
|
||||
fn add_letter(&self, gui_handler: &mut GuiHandler<'_>, letter: char) -> Result<String>;
|
||||
fn remove_last(&self, gui_handler: &mut GuiHandler<'_>) -> Result<Option<String>>;
|
||||
fn set_text(&self, gui_handler: &mut GuiHandler, text: String) -> Result<()>;
|
||||
fn add_letter(&self, gui_handler: &mut GuiHandler, letter: char) -> Result<String>;
|
||||
fn remove_last(&self, gui_handler: &mut GuiHandler) -> Result<Option<String>>;
|
||||
}
|
||||
|
||||
/// `Writeable` gives the ability to modify the text inside an `Textable`
|
||||
|
@ -19,7 +19,8 @@ pub struct Writeable {
|
|||
modifyable: Arc<dyn ModifyText>,
|
||||
text_change_executable: Arc<Executable<Option<String>>>,
|
||||
|
||||
activation_changed_executable: RwLock<Option<Box<dyn Fn(bool) -> Result<()> + Send + Sync>>>,
|
||||
activation_changed_executable:
|
||||
RwLock<Option<Box<dyn Fn(&mut GuiHandler, bool) -> Result<()> + Send + Sync>>>,
|
||||
|
||||
ui_layer: AtomicI32,
|
||||
}
|
||||
|
@ -40,19 +41,19 @@ impl Writeable {
|
|||
}))
|
||||
}
|
||||
|
||||
pub fn set_active(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn set_active(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if gui_handler.set_active_writeable(self.clone())? {
|
||||
if let Some(exec) = &*self.activation_changed_executable.read().unwrap() {
|
||||
exec(true)?;
|
||||
exec(gui_handler, true)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn inactivation_event(&self) -> Result<()> {
|
||||
pub(crate) fn inactivation_event(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
if let Some(exec) = &*self.activation_changed_executable.read().unwrap() {
|
||||
exec(false)?;
|
||||
exec(gui_handler, false)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -60,7 +61,7 @@ impl Writeable {
|
|||
|
||||
pub fn set_activation_changed<F>(&self, f: F)
|
||||
where
|
||||
F: Fn(bool) -> Result<()> + Send + Sync + 'static,
|
||||
F: Fn(&mut GuiHandler, bool) -> Result<()> + Send + Sync + 'static,
|
||||
{
|
||||
*self.activation_changed_executable.write().unwrap() = Some(Box::new(f));
|
||||
}
|
||||
|
@ -70,7 +71,7 @@ impl Writeable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `writeable` is a `&Arc<Writeable>` instance that is going to be added
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn add(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.add_writeable(self.ui_layer.load(SeqCst), self.clone())
|
||||
}
|
||||
|
||||
|
@ -79,7 +80,7 @@ impl Writeable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `writeable` is a `&Arc<Writeable>` instance that is going to be deleted
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
pub fn delete(self: &Arc<Self>, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
gui_handler.delete_writeable(self.ui_layer.load(SeqCst), self)
|
||||
}
|
||||
|
||||
|
@ -92,7 +93,7 @@ impl Writeable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `text` that replaces the current text
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: String) -> Result<()> {
|
||||
pub fn set_text(&self, gui_handler: &mut GuiHandler, text: String) -> Result<()> {
|
||||
self.modifyable.set_text(gui_handler, text.clone())?;
|
||||
|
||||
self.text_change_executable
|
||||
|
@ -106,19 +107,17 @@ impl Writeable {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `letter` the letter thats going to be added
|
||||
pub fn add_letter(&self, gui_handler: &mut GuiHandler<'_>, letter: char) -> Result<()> {
|
||||
self.text_change_executable.execute(
|
||||
gui_handler,
|
||||
Some(self.modifyable.add_letter(gui_handler, letter)?),
|
||||
)?;
|
||||
pub fn add_letter(&self, gui_handler: &mut GuiHandler, letter: char) -> Result<()> {
|
||||
let s = self.modifyable.add_letter(gui_handler, letter)?;
|
||||
self.text_change_executable.execute(gui_handler, Some(s))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes the last letter
|
||||
pub fn remove_last(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> {
|
||||
self.text_change_executable
|
||||
.execute(gui_handler, self.modifyable.remove_last(gui_handler)?)?;
|
||||
pub fn remove_last(&self, gui_handler: &mut GuiHandler) -> Result<()> {
|
||||
let s = self.modifyable.remove_last(gui_handler)?;
|
||||
self.text_change_executable.execute(gui_handler, s)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ impl TextToScreen {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct GuiHandler<'a> {
|
||||
pub struct GuiHandler {
|
||||
device: Arc<Device>,
|
||||
queue: Arc<Mutex<Queue>>,
|
||||
|
||||
|
@ -239,14 +239,14 @@ pub struct GuiHandler<'a> {
|
|||
current_writeable: Option<Arc<Writeable>>,
|
||||
current_hoverable: Option<Arc<Hoverable>>,
|
||||
current_clickable: Option<Arc<Clickable>>,
|
||||
current_selectable: Option<Arc<Selectable<'a>>>,
|
||||
current_selectable: Option<Arc<Selectable>>,
|
||||
|
||||
text_sample_count: VkSampleCountFlags,
|
||||
|
||||
callback_list: Vec<Box<dyn FnOnce() -> Result<()> + Send + Sync>>,
|
||||
callback_list: Vec<Box<dyn FnOnce(&mut Self) -> Result<()> + Send + Sync>>,
|
||||
}
|
||||
|
||||
impl<'a> GuiHandler<'a> {
|
||||
impl GuiHandler {
|
||||
pub fn new(
|
||||
gui_handler_create_info: GuiHandlerCreateInfo<'_>,
|
||||
context: &impl ContextInterface,
|
||||
|
@ -710,7 +710,7 @@ impl<'a> GuiHandler<'a> {
|
|||
Ok(false)
|
||||
}
|
||||
|
||||
pub fn current_selectable(&self) -> Option<Arc<Selectable<'a>>> {
|
||||
pub fn current_selectable(&self) -> Option<Arc<Selectable>> {
|
||||
self.current_selectable.clone()
|
||||
}
|
||||
|
||||
|
@ -860,14 +860,19 @@ impl<'a> GuiHandler<'a> {
|
|||
self.tooltip_ui = tooltip.into();
|
||||
}
|
||||
|
||||
pub(crate) fn add_callback<F: FnOnce() -> Result<()> + Send + Sync + 'static>(&mut self, f: F) {
|
||||
pub(crate) fn add_callback<F: FnOnce(&mut Self) -> Result<()> + Send + Sync + 'static>(
|
||||
&mut self,
|
||||
f: F,
|
||||
) {
|
||||
self.callback_list.push(Box::new(f));
|
||||
}
|
||||
|
||||
pub fn process_callbacks(&mut self) -> Result<()> {
|
||||
let callbacks = mem::take(&mut self.callback_list);
|
||||
|
||||
callbacks.into_iter().try_for_each(|callback| callback())
|
||||
callbacks
|
||||
.into_iter()
|
||||
.try_for_each(|callback| callback(self))
|
||||
}
|
||||
|
||||
fn render(
|
||||
|
@ -1045,7 +1050,7 @@ macro_rules! remove_element {
|
|||
}
|
||||
|
||||
// object handling
|
||||
impl<'a> GuiHandler<'a> {
|
||||
impl<'a> GuiHandler {
|
||||
// framable
|
||||
pub(crate) fn add_framable(&mut self, layer: i32, framable: Arc<Framable>) -> Result<()> {
|
||||
add_element!(self.layers, layer, framable);
|
||||
|
@ -1084,11 +1089,7 @@ impl<'a> GuiHandler<'a> {
|
|||
}
|
||||
|
||||
// selectable
|
||||
pub(crate) fn add_selectable(
|
||||
&mut self,
|
||||
layer: i32,
|
||||
selectable: Arc<Selectable<'_>>,
|
||||
) -> Result<()> {
|
||||
pub(crate) fn add_selectable(&mut self, layer: i32, selectable: Arc<Selectable>) -> Result<()> {
|
||||
add_element!(self.layers, layer, selectable);
|
||||
|
||||
Ok(())
|
||||
|
@ -1097,7 +1098,7 @@ impl<'a> GuiHandler<'a> {
|
|||
pub(crate) fn delete_selectable(
|
||||
&mut self,
|
||||
layer: i32,
|
||||
selectable: &Arc<Selectable<'a>>,
|
||||
selectable: &Arc<Selectable>,
|
||||
) -> Result<()> {
|
||||
if self.current_selectable.is_some() {
|
||||
// unwrap is safe, just tested for `is_some`
|
||||
|
@ -1181,13 +1182,15 @@ impl<'a> GuiHandler<'a> {
|
|||
}
|
||||
|
||||
pub(crate) fn set_active_writeable(&mut self, writeable: Arc<Writeable>) -> Result<bool> {
|
||||
let callback_self = unsafe { remove_life_time_mut(self) };
|
||||
|
||||
if let Some(current) = self.current_writeable.as_ref() {
|
||||
// change nothing if both are the same
|
||||
if Arc::ptr_eq(current, &writeable) {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
current.inactivation_event()?;
|
||||
current.inactivation_event(callback_self)?;
|
||||
}
|
||||
|
||||
self.current_writeable = Some(writeable);
|
||||
|
@ -1200,12 +1203,12 @@ impl<'a> GuiHandler<'a> {
|
|||
layer: i32,
|
||||
writeable: &Arc<Writeable>,
|
||||
) -> Result<()> {
|
||||
{
|
||||
if let Some(w) = &self.current_writeable {
|
||||
if Arc::ptr_eq(w, writeable) {
|
||||
w.inactivation_event()?;
|
||||
self.current_writeable = None;
|
||||
}
|
||||
let callback_self = unsafe { remove_life_time_mut(self) };
|
||||
|
||||
if let Some(w) = &self.current_writeable {
|
||||
if Arc::ptr_eq(w, writeable) {
|
||||
w.inactivation_event(callback_self)?;
|
||||
self.current_writeable = None;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1233,7 +1236,7 @@ impl<'a> GuiHandler<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn set_selectable(&mut self, selectable: Option<Arc<Selectable<'a>>>) -> Result<()> {
|
||||
pub(crate) fn set_selectable(&mut self, selectable: Option<Arc<Selectable>>) -> Result<()> {
|
||||
let callback_self = unsafe { remove_life_time_mut(self) };
|
||||
|
||||
if let Some(selectable) = &self.current_selectable {
|
||||
|
@ -1273,7 +1276,7 @@ impl<'a> GuiHandler<'a> {
|
|||
}
|
||||
|
||||
// private - create rendering stuff
|
||||
impl<'a> GuiHandler<'a> {
|
||||
impl<'a> GuiHandler {
|
||||
fn create_render_targets(
|
||||
device: &Arc<Device>,
|
||||
target_images: &TargetMode<Vec<Arc<Image>>>,
|
||||
|
@ -1587,7 +1590,7 @@ impl<'a> GuiHandler<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> GuiHandler<'a> {
|
||||
impl<'a> GuiHandler {
|
||||
pub fn process(
|
||||
&mut self,
|
||||
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
||||
|
@ -1691,8 +1694,8 @@ impl<'a> GuiHandler<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ecs::World> for &'a GuiHandler<'_> {
|
||||
fn from(world: &'a ecs::World) -> Self {
|
||||
world.resources.get::<GuiHandler<'_>>()
|
||||
impl<'a> From<&'a ecs::World> for &'a GuiHandler {
|
||||
fn from(world: &'a ecs::World) -> &'a GuiHandler {
|
||||
world.resources.get::<GuiHandler>()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct Keyboard {
|
|||
}
|
||||
|
||||
impl Keyboard {
|
||||
pub fn new(gui_handler: &Arc<GuiHandler<'a>>) -> Result<Arc<Self>> {
|
||||
pub fn new(gui_handler: &GuiHandler) -> Result<Arc<Self>> {
|
||||
let text_field_gui: Arc<GuiBuilder> =
|
||||
GuiBuilder::from_str(gui_handler, include_str!("text_field.xml"))?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue