Skip to content

Commit

Permalink
fixed #428 (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikwilkowski authored Apr 27, 2024
1 parent 0c6b130 commit d87a6a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
11 changes: 7 additions & 4 deletions examples/layout/src/holy_grail.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use floem::{
event::EventListener,
peniko::Color,
reactive::create_signal,
reactive::create_rw_signal,
style::Position,
view::View,
views::{
Expand All @@ -12,18 +12,19 @@ use floem::{

const SIDEBAR_WIDTH: f64 = 140.0;
const TOPBAR_HEIGHT: f64 = 30.0;
const SIDEBAR_ITEM_HEIGHT: f64 = 21.0;

pub fn holy_grail_view() -> impl View {
let long_list: im::Vector<i32> = (0..100).collect();
let (long_list, _set_long_list) = create_signal(long_list);
let long_list = create_rw_signal(long_list);

let top_bar = label(|| String::from("Top bar"))
.style(|s| s.padding(10.0).width_full().height(TOPBAR_HEIGHT));

let side_bar_right = scroll({
virtual_stack(
VirtualDirection::Vertical,
VirtualItemSize::Fixed(Box::new(|| 22.0)),
VirtualItemSize::Fixed(Box::new(|| SIDEBAR_ITEM_HEIGHT)),
move || long_list.get(),
move |item| *item,
move |item| {
Expand All @@ -32,6 +33,7 @@ pub fn holy_grail_view() -> impl View {
.padding_top(3.0)
.padding_bottom(3.0)
.width(SIDEBAR_WIDTH)
.height(SIDEBAR_ITEM_HEIGHT)
.items_start()
.border_bottom(1.0)
.border_color(Color::rgb8(205, 205, 205))
Expand All @@ -50,7 +52,7 @@ pub fn holy_grail_view() -> impl View {
let side_bar_left = scroll({
virtual_stack(
VirtualDirection::Vertical,
VirtualItemSize::Fixed(Box::new(|| 22.0)),
VirtualItemSize::Fixed(Box::new(|| SIDEBAR_ITEM_HEIGHT)),
move || long_list.get(),
move |item| *item,
move |item| {
Expand All @@ -59,6 +61,7 @@ pub fn holy_grail_view() -> impl View {
.padding_top(3.0)
.padding_bottom(3.0)
.width(SIDEBAR_WIDTH)
.height(SIDEBAR_ITEM_HEIGHT)
.items_start()
.border_bottom(1.0)
.border_color(Color::rgb8(205, 205, 205))
Expand Down
10 changes: 6 additions & 4 deletions examples/layout/src/left_sidebar.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use floem::{
event::EventListener,
peniko::Color,
reactive::create_signal,
reactive::create_rw_signal,
style::Position,
view::View,
views::{
Expand All @@ -12,18 +12,19 @@ use floem::{

const SIDEBAR_WIDTH: f64 = 140.0;
const TOPBAR_HEIGHT: f64 = 30.0;
const SIDEBAR_ITEM_HEIGHT: f64 = 21.0;

pub fn left_sidebar_view() -> impl View {
let long_list: im::Vector<i32> = (0..100).collect();
let (long_list, _set_long_list) = create_signal(long_list);
let long_list: im::Vector<u8> = (0..100).collect();
let long_list = create_rw_signal(long_list);

let top_bar = label(|| String::from("Top bar"))
.style(|s| s.padding(10.0).width_full().height(TOPBAR_HEIGHT));

let side_bar = scroll({
virtual_stack(
VirtualDirection::Vertical,
VirtualItemSize::Fixed(Box::new(|| 22.0)),
VirtualItemSize::Fixed(Box::new(|| SIDEBAR_ITEM_HEIGHT)),
move || long_list.get(),
move |item| *item,
move |item| {
Expand All @@ -32,6 +33,7 @@ pub fn left_sidebar_view() -> impl View {
.padding_top(3.0)
.padding_bottom(3.0)
.width(SIDEBAR_WIDTH)
.height(SIDEBAR_ITEM_HEIGHT)
.items_start()
.border_bottom(1.0)
.border_color(Color::rgb8(205, 205, 205))
Expand Down
8 changes: 5 additions & 3 deletions examples/layout/src/right_sidebar.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use floem::{
event::EventListener,
peniko::Color,
reactive::create_signal,
reactive::create_rw_signal,
style::Position,
view::View,
views::{
Expand All @@ -12,18 +12,19 @@ use floem::{

const SIDEBAR_WIDTH: f64 = 140.0;
const TOPBAR_HEIGHT: f64 = 30.0;
const SIDEBAR_ITEM_HEIGHT: f64 = 21.0;

pub fn right_sidebar_view() -> impl View {
let long_list: im::Vector<i32> = (0..100).collect();
let (long_list, _set_long_list) = create_signal(long_list);
let long_list = create_rw_signal(long_list);

let top_bar = label(|| String::from("Top bar"))
.style(|s| s.padding(10.0).width_full().height(TOPBAR_HEIGHT));

let side_bar = scroll({
virtual_stack(
VirtualDirection::Vertical,
VirtualItemSize::Fixed(Box::new(|| 22.0)),
VirtualItemSize::Fixed(Box::new(|| SIDEBAR_ITEM_HEIGHT)),
move || long_list.get(),
move |item| *item,
move |item| {
Expand All @@ -32,6 +33,7 @@ pub fn right_sidebar_view() -> impl View {
.padding_top(3.0)
.padding_bottom(3.0)
.width(SIDEBAR_WIDTH)
.height(SIDEBAR_ITEM_HEIGHT)
.items_start()
.border_bottom(1.0)
.border_color(Color::rgb8(205, 205, 205))
Expand Down

2 comments on commit d87a6a1

@15artis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

draggable_sidebar Drag the window to the right. If you go beyond the window, you cannot drag it back. You need to limit the scope of the right drag

@dominikwilkowski
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah true. These examples really only should give you a starting point and you can go from there. Maybe sometime I'll create a co,ponent lib and then this would be important to address.

Please sign in to comment.