Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@
- Reduce latency & redraws with vertex operations especially smaller ones.
- `Bin` `on_update` & `on_update_once` methods are now called at the end of a worker cycle.
- This improves consistency when checking the `BinPostUpdate` of other `Bin` updates.

## Changes to Interface

- **BREAKING**: Removed legacy/obsolete widgets `CheckBox`, `OnOffButton`, `ScrollBar` and `Slider`.

## Changes to `Bin`
- **BREAKING** Remove method `toggle_hidden` and `set_hidden`.

- **BREAKING**: Remove method `toggle_hidden` and `set_hidden`.
- Use `style_modify` instead.
- **BREAKING**: Removed methods `add_drag_events`, `fade_in` and `fade_out`.
- **BEHAVIOR**: Rewrote radius code to be more circular.
- Added method `style_modify` & `style_modify_then`.
- Added method `is_visible`.
Expand Down
175 changes: 3 additions & 172 deletions src/interface/bin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ use self::text_state::TextState;
use crate::Basalt;
use crate::image::{ImageCacheLifetime, ImageInfo, ImageKey, ImageMap};
use crate::input::{
Char, InputHookCtrl, InputHookID, InputHookTarget, KeyCombo, LocalCursorState, LocalKeyState,
MouseButton, WindowState,
Char, InputHookCtrl, InputHookID, InputHookTarget, KeyCombo, LocalCursorState, LocalKeyState, WindowState,
};
use crate::interface::{
BinStyle, BinStyleValidation, Color, DefaultFont, FloatWeight, Flow, ItfVertInfo, Opacity,
Position, TextBodyGuard, UnitValue, Visibility, ZIndex, scale_verts,
Position, TextBodyGuard, Visibility, ZIndex, scale_verts,
};
use crate::interval::{IntvlHookCtrl, IntvlHookID};
use crate::interval::IntvlHookID;
use crate::render::RendererMetricsLevel;
use crate::window::Window;

Expand Down Expand Up @@ -968,174 +967,6 @@ impl Bin {
}
}

pub fn add_drag_events(self: &Arc<Self>, target_op: Option<Arc<Bin>>) {
let window = match self.window() {
Some(some) => some,
None => return,
};

#[derive(Default)]
struct Data {
target: Weak<Bin>,
mouse_x: f32,
mouse_y: f32,
pos_from_t: UnitValue,
pos_from_b: UnitValue,
pos_from_l: UnitValue,
pos_from_r: UnitValue,
}

let data = Arc::new(Mutex::new(None));
let target_wk = target_op
.map(|v| Arc::downgrade(&v))
.unwrap_or_else(|| Arc::downgrade(self));
let data_cp = data.clone();

self.on_press(MouseButton::Middle, move |_, window, _| {
let [mouse_x, mouse_y] = window.cursor_pos();

let style = match target_wk.upgrade() {
Some(bin) => bin.style_copy(),
None => return InputHookCtrl::Remove,
};

*data_cp.lock() = Some(Data {
target: target_wk.clone(),
mouse_x,
mouse_y,
pos_from_t: style.pos_from_t,
pos_from_b: style.pos_from_b,
pos_from_l: style.pos_from_l,
pos_from_r: style.pos_from_r,
});

Default::default()
});

let data_cp = data.clone();

self.attach_input_hook(
self.basalt
.input_ref()
.hook()
.window(&window)
.on_cursor()
.call(move |_, window, _| {
let [mouse_x, mouse_y] = window.cursor_pos();
let mut data_op = data_cp.lock();

let data = match &mut *data_op {
Some(some) => some,
None => return Default::default(),
};

let target = match data.target.upgrade() {
Some(some) => some,
None => return InputHookCtrl::Remove,
};

let dx = mouse_x - data.mouse_x;
let dy = mouse_y - data.mouse_y;

target
.style_update(BinStyle {
pos_from_t: data.pos_from_t.offset_pixels(dy),
pos_from_b: data.pos_from_b.offset_pixels(-dy),
pos_from_l: data.pos_from_l.offset_pixels(dx),
pos_from_r: data.pos_from_r.offset_pixels(-dx),
..target.style_copy()
})
.expect_valid();

target.trigger_children_update();
Default::default()
})
.finish()
.unwrap(),
);

self.on_release(MouseButton::Middle, move |_, _, _| {
*data.lock() = None;
Default::default()
});
}

pub fn fade_out(self: &Arc<Self>, millis: u64) {
let bin_wk = Arc::downgrade(self);

let start_opacity = match self.style_inspect(|style| style.opacity) {
Opacity::Inheirt => 1.0,
Opacity::Fixed(opacity) => opacity,
Opacity::Multiply(mult) => mult,
};

let steps = (millis / 8) as i64;
let step_size = start_opacity / steps as f32;
let mut step_i = 0;

self.basalt
.interval_ref()
.do_every(Duration::from_millis(8), None, move |_| {
if step_i > steps {
return IntvlHookCtrl::Remove;
}

let bin = match bin_wk.upgrade() {
Some(some) => some,
None => return IntvlHookCtrl::Remove,
};

let opacity = start_opacity - (step_i as f32 * step_size);
let mut copy = bin.style_copy();
copy.opacity = Opacity::Fixed(opacity);

if step_i == steps {
copy.visibility = Visibility::Hide;
}

bin.style_update(copy).expect_valid();
bin.trigger_children_update();
step_i += 1;
Default::default()
});
}

pub fn fade_in(self: &Arc<Self>, millis: u64, target: f32) {
let bin_wk = Arc::downgrade(self);

let start_opacity = match self.style_inspect(|style| style.opacity) {
Opacity::Inheirt => 1.0,
Opacity::Fixed(opacity) => opacity,
Opacity::Multiply(mult) => mult,
};

let steps = (millis / 8) as i64;
let step_size = (target - start_opacity) / steps as f32;
let mut step_i = 0;

self.basalt
.interval_ref()
.do_every(Duration::from_millis(8), None, move |_| {
if step_i > steps {
return IntvlHookCtrl::Remove;
}

let bin = match bin_wk.upgrade() {
Some(some) => some,
None => return IntvlHookCtrl::Remove,
};

let opacity = (step_i as f32 * step_size) + start_opacity;
let mut copy = bin.style_copy();
copy.opacity = Opacity::Fixed(opacity);
copy.visibility = Visibility::Show;
bin.style_update(copy).expect_valid();
bin.trigger_children_update();
step_i += 1;
Default::default()
});
}

/// Attach an `InputHookID` to this `Bin`. When this `Bin` drops the hook will be removed.
pub fn attach_input_hook(&self, hook_id: InputHookID) {
self.input_hook_ids.lock().push(hook_id);
Expand Down
105 changes: 0 additions & 105 deletions src/interface/checkbox.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/interface/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
//! System for storing interface related objects.

mod bin;
pub mod checkbox;
mod color;
pub mod on_off_button;
pub mod scroll_bar;
pub mod slider;
mod style;

use std::cmp::Reverse;
Expand Down
Loading