Skip to content

Commit

Permalink
Progress towards reworking the ui layout and having a no-stretch imag…
Browse files Browse the repository at this point in the history
…e fitting mode. #88
  • Loading branch information
ArturKovacs committed Jun 7, 2020
1 parent 5f78ec3 commit fc4adcc
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 63 deletions.
14 changes: 1 addition & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ copyright = "Copyright (c) 2020 The Emulsion Contributors"
winres = "0.1"

[dependencies]
#gelatin = { path = "./subcrates/gelatin" }
gelatin = "0.3"
gelatin = { path = "./subcrates/gelatin" }
#gelatin = "0.3"
ureq = { version = "1", features = ["json"], optional = true }
lazy_static = "1.4.0"
directories = "2.0.2"
Expand Down
Binary file added resource/1-light.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 resource/1.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 resource/fit-min-light.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 resource/fit-min.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 resource/fit-stretch-light.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 resource/fit-stretch.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 resource_dev/FiraSans-Regular.ttf
Binary file not shown.
Binary file modified resource_dev/ui-elements.blend
Binary file not shown.
Binary file modified resource_dev/ui-elements.blend1
Binary file not shown.
110 changes: 100 additions & 10 deletions src/bottom_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ static QUESTION_BUTTON: &[u8] = include_bytes!("../resource/question_button.png"
static QUESTION_BUTTON_LIGHT: &[u8] = include_bytes!("../resource/question_button_light.png");
static QUESTION_NOTI: &[u8] = include_bytes!("../resource/question-noti.png");
static QUESTION_LIGHT_NOTI: &[u8] = include_bytes!("../resource/question-light-noti.png");
static ONE: &[u8] = include_bytes!("../resource/1.png");
static ONE_LIGHT: &[u8] = include_bytes!("../resource/1-light.png");
static FIT_STRETCH: &[u8] = include_bytes!("../resource/fit-stretch.png");
static FIT_STRETCH_LIGHT: &[u8] = include_bytes!("../resource/fit-stretch-light.png");
static FIT_MIN: &[u8] = include_bytes!("../resource/fit-min.png");
static FIT_MIN_LIGHT: &[u8] = include_bytes!("../resource/fit-min-light.png");

pub struct BottomBar {
widget: Rc<HorizontalLayoutContainer>,
theme_button: Rc<Button>,
orig_scale_button: Rc<Button>,
fit_stretch_button: Rc<Button>,
fit_min_button: Rc<Button>,
slider: Rc<Slider>,
theme_button: Rc<Button>,
help_button: Rc<Button>,

question: Rc<Picture>,
Expand All @@ -29,6 +38,12 @@ pub struct BottomBar {
question_light_noti: Rc<Picture>,
moon_img: Rc<Picture>,
light_img: Rc<Picture>,
one: Rc<Picture>,
one_light: Rc<Picture>,
fit_stretch: Rc<Picture>,
fit_stretch_light: Rc<Picture>,
fit_min: Rc<Picture>,
fit_min_light: Rc<Picture>,
}

impl BottomBar {
Expand All @@ -39,6 +54,12 @@ impl BottomBar {
let question_light_noti = Rc::new(Picture::from_encoded_bytes(QUESTION_LIGHT_NOTI));
let moon_img = Rc::new(Picture::from_encoded_bytes(MOON));
let light_img = Rc::new(Picture::from_encoded_bytes(LIGHT));
let one = Rc::new(Picture::from_encoded_bytes(ONE));
let one_light = Rc::new(Picture::from_encoded_bytes(ONE_LIGHT));
let fit_stretch = Rc::new(Picture::from_encoded_bytes(FIT_STRETCH));
let fit_stretch_light = Rc::new(Picture::from_encoded_bytes(FIT_STRETCH_LIGHT));
let fit_min = Rc::new(Picture::from_encoded_bytes(FIT_MIN));
let fit_min_light = Rc::new(Picture::from_encoded_bytes(FIT_MIN_LIGHT));

let theme_button = make_theme_button();
let help_button = make_help_button();
Expand All @@ -52,14 +73,25 @@ impl BottomBar {
widget.set_height(Length::Fixed(32.0));
widget.set_width(Length::Stretch { min: 0.0, max: f32::INFINITY });

widget.add_child(theme_button.clone());
let orig_scale_button = make_orig_scale_button();
let fit_min_button = make_fit_min_button();
let fit_stretch_button = make_fit_stretch_button();

widget.add_child(orig_scale_button.clone());
widget.add_child(fit_min_button.clone());
widget.add_child(fit_stretch_button.clone());

widget.add_child(slider.clone());
widget.add_child(theme_button.clone());
widget.add_child(help_button.clone());

Self {
widget,
theme_button,
orig_scale_button,
fit_stretch_button,
fit_min_button,
slider,
theme_button,
help_button,

question,
Expand All @@ -68,6 +100,12 @@ impl BottomBar {
question_light_noti,
moon_img,
light_img,
one,
one_light,
fit_stretch,
fit_stretch_light,
fit_min,
fit_min_light,
}
}

Expand All @@ -91,9 +129,24 @@ impl BottomBar {
self.theme_button.set_on_click(callback);
}

pub fn set_on_orig_scale_click<T: Fn() + 'static>(&self, callback: T) {
self.orig_scale_button.set_on_click(callback);
}

pub fn set_on_fit_min_click<T: Fn() + 'static>(&self, callback: T) {
self.fit_min_button.set_on_click(callback);
}

pub fn set_on_fit_stretch_click<T: Fn() + 'static>(&self, callback: T) {
self.fit_stretch_button.set_on_click(callback);
}

pub fn set_theme(&self, theme: Theme, update_available: bool) {
match theme {
Theme::Light => {
self.orig_scale_button.set_icon(Some(self.one.clone()));
self.fit_min_button.set_icon(Some(self.fit_min.clone()));
self.fit_stretch_button.set_icon(Some(self.fit_stretch.clone()));
self.theme_button.set_icon(Some(self.moon_img.clone()));
self.widget.set_bg_color([1.0, 1.0, 1.0, 1.0]);
self.slider.set_shadow_color([0.0, 0.0, 0.0]);
Expand All @@ -105,6 +158,9 @@ impl BottomBar {
}
}
Theme::Dark => {
self.orig_scale_button.set_icon(Some(self.one_light.clone()));
self.fit_min_button.set_icon(Some(self.fit_min_light.clone()));
self.fit_stretch_button.set_icon(Some(self.fit_stretch_light.clone()));
self.theme_button.set_icon(Some(self.light_img.clone()));
self.widget.set_bg_color([0.08, 0.08, 0.08, 1.0]);
self.slider.set_shadow_color([0.0, 0.0, 0.0]);
Expand All @@ -119,31 +175,65 @@ impl BottomBar {
}
}

fn make_orig_scale_button() -> Rc<Button> {
let button = Rc::new(Button::new());
button.set_margin_top(4.0);
button.set_margin_left(4.0);
button.set_margin_right(0.0);
button.set_height(Length::Fixed(24.0));
button.set_width(Length::Fixed(24.0));
button.set_horizontal_align(Alignment::Start);
button
}

fn make_fit_min_button() -> Rc<Button> {
let button = Rc::new(Button::new());
button.set_margin_top(4.0);
button.set_margin_left(0.0);
button.set_margin_right(0.0);
button.set_height(Length::Fixed(24.0));
button.set_width(Length::Fixed(24.0));
button.set_horizontal_align(Alignment::Start);
button
}

fn make_fit_stretch_button() -> Rc<Button> {
let button = Rc::new(Button::new());
button.set_margin_top(4.0);
button.set_margin_left(0.0);
button.set_margin_right(32.0);
button.set_height(Length::Fixed(24.0));
button.set_width(Length::Fixed(24.0));
button.set_bg_color([0.4, 0.4, 0.4, 0.5]);
button.set_horizontal_align(Alignment::Start);
button
}

fn make_theme_button() -> Rc<Button> {
let button = Rc::new(Button::new());
button.set_margin_top(5.0);
button.set_margin_left(28.0);
button.set_margin_top(4.0);
button.set_margin_left(32.0);
button.set_margin_right(4.0);
button.set_height(Length::Fixed(24.0));
button.set_width(Length::Fixed(24.0));
button.set_horizontal_align(Alignment::Center);
button.set_horizontal_align(Alignment::End);
button
}

fn make_help_button() -> Rc<Button> {
let button = Rc::new(Button::new());
button.set_margin_top(5.0);
button.set_margin_top(4.0);
button.set_margin_left(4.0);
button.set_margin_right(28.0);
button.set_margin_right(4.0);
button.set_height(Length::Fixed(24.0));
button.set_width(Length::Fixed(24.0));
button.set_horizontal_align(Alignment::Center);
button.set_horizontal_align(Alignment::End);
button
}

fn make_slider() -> Rc<Slider> {
let slider = Rc::new(Slider::new());
slider.set_margin_top(5.0);
slider.set_margin_top(4.0);
slider.set_margin_left(4.0);
slider.set_margin_right(4.0);
slider.set_height(Length::Fixed(24.0));
Expand Down
21 changes: 21 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ impl Theme {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub enum ScalingMode {
Fixed,
FitStretch,
FitMin,
}

impl Default for ScalingMode {
fn default() -> ScalingMode {
ScalingMode::FitMin
}
}

#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
pub struct CacheImageSection {
scaling: ScalingMode,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct WindowSection {
pub dark: bool,
Expand Down Expand Up @@ -79,6 +97,7 @@ impl CacheUpdateSection {
pub struct Cache {
pub window: WindowSection,
pub updates: CacheUpdateSection,
pub image: CacheImageSection,
}

impl Cache {
Expand All @@ -98,13 +117,15 @@ impl Cache {
struct IncompleteCache {
pub window: Option<WindowSection>,
pub updates: Option<CacheUpdateSection>,
pub image: Option<CacheImageSection>,
}

impl From<IncompleteCache> for Cache {
fn from(cache: IncompleteCache) -> Self {
Self {
window: cache.window.unwrap_or_default(),
updates: cache.updates.unwrap_or_default(),
image: cache.image.unwrap_or_default(),
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ fn main() {
{
let cache = cache.clone();
let set_theme = set_theme.clone();

bottom_bar.set_on_theme_click(move || {
let new_theme = theme.get().switch_theme();
theme.set(new_theme);
Expand All @@ -170,11 +169,29 @@ fn main() {
}
{
let slider = bottom_bar.slider();

let picture_widget = picture_widget.clone();
bottom_bar.set_on_slider_value_change(move || {
picture_widget.jump_to_index(slider.value());
});
}
{
let picture_widget = picture_widget.clone();
bottom_bar.set_on_orig_scale_click(move || {
picture_widget.set_img_size_to_orig();
});
}
{
let picture_widget = picture_widget.clone();
bottom_bar.set_on_fit_min_click(move || {
picture_widget.set_img_size_to_fit(false);
});
}
{
let picture_widget = picture_widget.clone();
bottom_bar.set_on_fit_stretch_click(move || {
picture_widget.set_img_size_to_fit(true);
});
}
let help_visible = Cell::new(first_launch);
help_screen.set_visible(help_visible.get());
update_notification.set_visible(help_visible.get() && update_available.load(Ordering::SeqCst));
Expand Down
Loading

0 comments on commit fc4adcc

Please sign in to comment.