Skip to content

Commit

Permalink
Merge pull request #191 from Guocork/main
Browse files Browse the repository at this point in the history
fix issue 132
  • Loading branch information
jmbejar authored Aug 6, 2024
2 parents ca37d07 + 7ad0c9d commit f906fac
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 29 deletions.
Binary file added resources/images/drop_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/tick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/chat/model_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ live_design! {

import crate::shared::styles::*;

ICON_TICK = dep("crate://self/resources/images/tick.png")


ModelAttributeTag = <RoundedView> {
width: Fit,
height: Fit,
Expand Down Expand Up @@ -74,6 +77,16 @@ live_design! {
border_width: 1.0,
}
}

icon_tick_tag = <RoundedView> {
align: {x: 1.0, y: 0.5},
visible: false,
icon_tick = <Image> {
width: 14,
height: 14,
source: (ICON_TICK),
}
}
}
}

89 changes: 63 additions & 26 deletions src/chat/model_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ live_design! {
import crate::chat::model_selector_list::ModelSelectorList;
import crate::chat::model_selector_loading::ModelSelectorLoading;

ICON_DROP = dep("crate://self/resources/images/drop_icon.png")


ModelSelectorButton = <RoundedView> {
width: Fill,
height: 54,
flow: Overlay,
flow: Right,

align: {x: 0.0, y: 0.5},
padding: 0,
padding: {left: 16, right: 16, top: 0, bottom: 0},

draw_bg: {
instance radius: 3.0,
Expand All @@ -34,37 +37,62 @@ live_design! {

cursor: Hand,

loading = <ModelSelectorLoading> {
width: Fill,
height: Fill,
}

choose = <View> {
content = <View> {
width: Fill,
height: Fit,
flow: Overlay,
padding: {left: 16, top: 0, bottom: 0, right: 0},

loading = <ModelSelectorLoading> {
width: Fill,
height: Fill,
}

choose = <View> {
width: Fill,
height: Fit,

align: {x: 0.5, y: 0.5},
padding: 16,
align: {x: 0.0, y: 0.5},
padding: 16,

label = <Label> {
draw_text:{
text_style: <BOLD_FONT>{font_size: 11},
color: #000
label = <Label> {
draw_text:{
text_style: <BOLD_FONT>{font_size: 11},
color: #000
}
text: "Choose a model"
}
}

selected = <ModelInfo> {
width: Fit,
height: Fit,
show_bg: false,
visible: false,

padding: 0,

label = {
draw_text: {
text_style: <BOLD_FONT>{font_size: 11},
}
}
text: "Choose a model"
}
}
selected = <ModelInfo> {

icon_drop = <RoundedView> {
width: Fit,
height: Fit,
show_bg: false,
visible: false,

padding: 16,

label = {
draw_text: {
text_style: <BOLD_FONT>{font_size: 11},
align: {x: 1.0, y: 0.5},
margin: {left: 10, right: 6},
visible: true,

icon = <RotatedImage> {
height: 14,
width: 14,
source: (ICON_DROP),
draw_bg: {
rotation: 0.0
}
}
}
Expand Down Expand Up @@ -106,20 +134,21 @@ live_design! {
options = <ModelSelectorOptions> {}

open_animation_progress: 0.0,
rotate_animation_progress: 0.0
animator: {
open = {
default: hide,
show = {
redraw: true,
from: {all: Forward {duration: 0.3}}
ease: ExpDecay {d1: 0.80, d2: 0.97}
apply: {open_animation_progress: 1.0}
apply: {open_animation_progress: 1.0, rotate_animation_progress: 1.0}
}
hide = {
redraw: true,
from: {all: Forward {duration: 0.3}}
ease: ExpDecay {d1: 0.80, d2: 0.97}
apply: {open_animation_progress: 0.0}
apply: {open_animation_progress: 0.0, rotate_animation_progress: 0.0}
}
}
}
Expand All @@ -140,6 +169,9 @@ pub struct ModelSelector {
#[live]
open_animation_progress: f64,

#[live]
rotate_animation_progress: f64,

#[rust]
hide_animation_timer: Timer,

Expand Down Expand Up @@ -198,6 +230,10 @@ impl Widget for ModelSelector {
let height = self.open_animation_progress * total_height;
self.view(id!(options.list_container))
.apply_over(cx, live! {height: (height)});

let rotate_angle = self.rotate_animation_progress * std::f64::consts::PI;
self.view(id!(icon_drop.icon)).apply_over(cx, live! {draw_bg: {rotation: (rotate_angle)}});

self.redraw(cx);
}
}
Expand Down Expand Up @@ -306,6 +342,7 @@ impl ModelSelector {
fn hide_options(&mut self, cx: &mut Cx) {
self.open = false;
self.view(id!(options)).apply_over(cx, live! { height: 0 });
self.view(id!(icon_drop.icon)).apply_over(cx, live! {draw_bg: {rotation: (0.0)}});
self.animator_cut(cx, id!(open.hide));
self.redraw(cx);
}
Expand Down
13 changes: 10 additions & 3 deletions src/chat/model_selector_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Widget for ModelSelectorList {
cx.begin_turtle(walk, self.layout);

if self.visible {
self.draw_items(cx, &store.downloads.downloaded_files);
self.draw_items(cx, store);
}

cx.end_turtle_with_area(&mut self.area);
Expand All @@ -144,8 +144,9 @@ impl Widget for ModelSelectorList {
}

impl ModelSelectorList {
fn draw_items(&mut self, cx: &mut Cx2d, items: &Vec<DownloadedFile>) {
let mut items = items.clone();
fn draw_items(&mut self, cx: &mut Cx2d, store: &Store) {

let mut items = store.downloads.downloaded_files.clone();
items.sort_by(|a, b| b.downloaded_at.cmp(&a.downloaded_at));

if items.is_empty() {
Expand Down Expand Up @@ -175,13 +176,19 @@ impl ModelSelectorList {
let size = format_model_size(&items[i].file.size).unwrap_or("".to_string());
let size_visible = !size.trim().is_empty();

let mut icon_tick_visible = false;
if let Some(loaded_model) = store.get_loaded_downloaded_file() {
icon_tick_visible = self.map_to_downloaded_files.get(&item_id).unwrap().file.id == loaded_model.file.id;
}

item_widget.apply_over(
cx,
live! {
label = { text: (caption) }
architecture_tag = { visible: (architecture_visible), caption = { text: (architecture) } }
params_size_tag = { visible: (param_size_visible), caption = { text: (param_size) } }
file_size_tag = { visible: (size_visible), caption = { text: (size) } }
icon_tick_tag = { visible: (icon_tick_visible) }
},
);

Expand Down

0 comments on commit f906fac

Please sign in to comment.