Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 780db56

Browse files
committed
Add a fake channel list
1 parent ff5de29 commit 780db56

File tree

5 files changed

+91
-11
lines changed

5 files changed

+91
-11
lines changed

stella2/meta/lib.tcwdl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ use tcw3::{
1010
pal,
1111
};
1212

13-
use crate::{model, stylesheet::elem_id, view::toolbar::ToolbarView};
13+
use crate::{
14+
model,
15+
stylesheet::elem_id,
16+
view::{
17+
channellist::ChannelListView,
18+
toolbar::ToolbarView,
19+
},
20+
};
1421

22+
import!("view/channellist.tcwdl");
1523
import!("view/toolbar.tcwdl");
1624

1725
#[widget]
@@ -50,11 +58,7 @@ comp crate::view::MainView {
5058
class_set = elem_id::SIDEBAR,
5159
subview_generic = get!(sidebar_view.view),
5260
};
53-
const sidebar_view = PlaceholderView::new! {
54-
wm,
55-
style_manager,
56-
text = "sidebar: todo!".to_string(),
57-
};
61+
const sidebar_view = ChannelListView::new! { wm, style_manager };
5862

5963
// The main area
6064
// -----------------------------------------------------------------------

stella2/meta/view/channellist.tcwdl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use tcw3::{
2+
ui::theming::{self, Manager},
3+
uicore::HView,
4+
pal,
5+
};
6+
7+
use crate::{model, stylesheet::elem_id};
8+
9+
#[widget]
10+
#[prototype_only]
11+
#[builder(simple)]
12+
pub(crate) comp crate::view::channellist::ChannelListView {
13+
const wm: pal::Wm { pub set; }
14+
const style_manager: &Manager { pub set; }
15+
16+
const view: HView { pub get borrow; } = unreachable!();
17+
}

stella2/src/stylesheet.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ fn new_custom_stylesheet() -> impl Stylesheet {
7373
([#SIDEBAR]) (priority = 10000) {
7474
num_layers: 1,
7575
layer_bg_color[0]: [0.93, 0.93, 0.93, 0.8].into(),
76-
77-
subview_metrics[Role::Generic]: Metrics {
78-
margin: [5.0; 4],
79-
..Default::default()
80-
},
8176
},
8277
([#LOG_VIEW]) (priority = 10000) {
8378
num_layers: 1,

stella2/src/view.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tcw3::{
1616

1717
use crate::{model, stylesheet::elem_id};
1818

19+
mod channellist;
1920
mod toolbar;
2021

2122
pub struct AppView {

stella2/src/view/channellist.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use std::ops::Range;
2+
use tcw3::{
3+
pal,
4+
ui::{
5+
prelude::*,
6+
theming,
7+
views::{table, table::LineTy, Label, ScrollableTable},
8+
},
9+
uicore::{HView, SizeTraits},
10+
};
11+
12+
pub struct ChannelListView {
13+
table: ScrollableTable,
14+
}
15+
16+
impl ChannelListView {
17+
pub fn new(_: pal::Wm, style_manager: &'static theming::Manager) -> Self {
18+
let table = ScrollableTable::new(style_manager);
19+
20+
// This minimum size is kind of arbitrary
21+
table.table().set_size_traits(SizeTraits {
22+
preferred: [150.0, 200.0].into(),
23+
min: [40.0, 40.0].into(),
24+
..Default::default()
25+
});
26+
27+
// Set up the table model
28+
{
29+
let mut edit = table.table().edit().unwrap();
30+
edit.set_model(TableModelQuery { style_manager });
31+
edit.insert(LineTy::Row, 0..30);
32+
edit.insert(LineTy::Col, 0..1);
33+
edit.set_scroll_pos([0.0, edit.scroll_pos()[1]]);
34+
}
35+
36+
Self { table }
37+
}
38+
39+
pub fn view(&self) -> &HView {
40+
self.table.view()
41+
}
42+
}
43+
44+
struct TableModelQuery {
45+
style_manager: &'static theming::Manager,
46+
}
47+
48+
impl table::TableModelQuery for TableModelQuery {
49+
fn new_view(&mut self, cell: table::CellIdx) -> (HView, Box<dyn table::CellCtrler>) {
50+
let label = Label::new(self.style_manager);
51+
label.set_text(format!("Item {}", cell[1]));
52+
53+
(label.view().clone(), Box::new(()))
54+
}
55+
56+
fn range_size(&mut self, line_ty: LineTy, range: Range<u64>, _approx: bool) -> f64 {
57+
(range.end - range.start) as f64
58+
* match line_ty {
59+
LineTy::Row => 20.0,
60+
LineTy::Col => 50.0, // TODO: find a better way to fill the width
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)