-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Room list search bar #232
base: main
Are you sure you want to change the base?
Room list search bar #232
Changes from all commits
5a0cc61
4a89626
bccd539
55b3b20
369e0ed
a26bcdd
9de3ec5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
use makepad_widgets::*; | ||
|
||
use crate::shared::search_bar::SearchBarAction; | ||
|
||
live_design! { | ||
import makepad_widgets::base::*; | ||
import makepad_widgets::theme_desktop_dark::*; | ||
|
@@ -10,6 +12,85 @@ live_design! { | |
import crate::shared::adaptive_view::AdaptiveView; | ||
|
||
import crate::home::rooms_list::RoomsList; | ||
import crate::shared::cached_widget::CachedWidget; | ||
|
||
ICON_COLLAPSE = dep("crate://self/resources/icons/collapse.svg") | ||
ICON_ADD = dep("crate://self/resources/icons/add.svg") | ||
|
||
CollapsableTitle = <View> { | ||
width: Fill, height: Fit | ||
flow: Right, spacing: 10. | ||
align: {x: 0.0, y: 0.5} | ||
collapse_icon = <Icon> { | ||
draw_icon: { | ||
svg_file: (ICON_COLLAPSE), | ||
uniform rotation_angle: -90.0, | ||
fn get_color(self) -> vec4 { | ||
// return #666; | ||
return (COLOR_TEXT_IDLE); | ||
} | ||
|
||
// Support rotation of the icon | ||
fn clip_and_transform_vertex(self, rect_pos: vec2, rect_size: vec2) -> vec4 { | ||
let clipped: vec2 = clamp( | ||
self.geom_pos * rect_size + rect_pos, | ||
self.draw_clip.xy, | ||
self.draw_clip.zw | ||
) | ||
self.pos = (clipped - rect_pos) / rect_size | ||
|
||
// Calculate the texture coordinates based on the rotation angle | ||
let angle_rad = self.rotation_angle * 3.14159265359 / 180.0; | ||
let cos_angle = cos(angle_rad); | ||
let sin_angle = sin(angle_rad); | ||
let rot_matrix = mat2( | ||
cos_angle, -sin_angle, | ||
sin_angle, cos_angle | ||
); | ||
self.tex_coord1 = mix( | ||
self.icon_t1.xy, | ||
self.icon_t2.xy, | ||
(rot_matrix * (self.pos.xy - vec2(0.5))) + vec2(0.5) | ||
); | ||
|
||
return self.camera_projection * (self.camera_view * (self.view_transform * vec4( | ||
clipped.x, | ||
clipped.y, | ||
self.draw_depth + self.draw_zbias, | ||
1. | ||
))) | ||
} | ||
} | ||
icon_walk: {width: 12, height: 12} | ||
} | ||
|
||
title = <Label> { | ||
draw_text: { | ||
color: #x0, | ||
text_style: <TITLE_TEXT>{ font_size: 11} | ||
} | ||
} | ||
|
||
<View> { | ||
width: Fill | ||
} | ||
|
||
add_icon = <View> { | ||
width: Fit | ||
visible: false | ||
padding: {right: 10} | ||
align: {x: 0.5, y: 0.5} | ||
<Icon> { | ||
icon_walk: {width: 10, height: 10} | ||
draw_icon: { | ||
svg_file: (ICON_ADD), | ||
fn get_color(self) -> vec4 { | ||
return (COLOR_TEXT_IDLE); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
RoomsView = {{RoomsView}} { | ||
show_bg: true, | ||
|
@@ -34,6 +115,11 @@ live_design! { | |
text_style: <TITLE_TEXT>{} | ||
} | ||
} | ||
<SearchBar> { | ||
input = { | ||
empty_message: "Search for rooms..." | ||
} | ||
} | ||
<CachedWidget> { | ||
rooms_list = <RoomsList> {} | ||
} | ||
|
@@ -53,6 +139,25 @@ live_design! { | |
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum RoomsSideBarFilter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're conflating filter kinds with room categories.... these are two separate things. The filter categories would be things like:
You could also have additional filter kinds for "is_direct" or "is_room" (not direct), but those wouldn't be expressible as enum variants because you'd only be able to select one. They would have to be bitflags/bitsets such that you could select multiple filter criteria at once. Or, alternatively, you could add a series of booleans to a "filter type" struct. The design is up to you, but try to think deeply about the possible valid combinations of filter kinds and search terms. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other possible filter dimensions include whether a room is marked as a favorite, whether a user has left a room, joined a room, or is just invited to a room, etc. The list of built-in filter functions are here; perhaps you could just re-use most of them. But note that we do not want to use them with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep. I got it. So i will do that and then change this issue's label. Thanks |
||
/// Filter all | ||
All, | ||
/// Filter people | ||
People, | ||
/// Filter rooms | ||
Rooms, | ||
} | ||
|
||
#[derive(Debug, Clone, DefaultNone)] | ||
pub enum RoomsSideBarAction { | ||
/// Filter | ||
Filter { | ||
keywords: String, | ||
filter: RoomsSideBarFilter, | ||
}, | ||
None | ||
} | ||
#[derive(Widget, Live, LiveHook)] | ||
pub struct RoomsView { | ||
#[deref] | ||
|
@@ -62,9 +167,42 @@ pub struct RoomsView { | |
impl Widget for RoomsView { | ||
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) { | ||
self.view.handle_event(cx, event, scope); | ||
self.widget_match_event(cx, event, scope); | ||
} | ||
|
||
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep { | ||
self.view.draw_walk(cx, scope, walk) | ||
} | ||
} | ||
|
||
impl WidgetMatchEvent for RoomsView { | ||
fn handle_actions(&mut self, cx: &mut Cx, actions:&Actions, scope: &mut Scope) { | ||
let widget_uid = self.widget_uid(); | ||
|
||
for action in actions.iter() { | ||
match action.as_widget_action().cast() { | ||
SearchBarAction::Search(keywords) => { | ||
cx.widget_action( | ||
widget_uid, | ||
&scope.path, | ||
RoomsSideBarAction::Filter { | ||
keywords: keywords.clone(), | ||
filter: RoomsSideBarFilter::Rooms, | ||
} | ||
); | ||
}, | ||
SearchBarAction::ResetSearch => { | ||
cx.widget_action( | ||
widget_uid, | ||
&scope.path, | ||
RoomsSideBarAction::Filter { | ||
keywords: "".to_string(), | ||
filter: RoomsSideBarFilter::Rooms, | ||
} | ||
); | ||
} | ||
_ => {} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is okay for now as a rudimentary search, but in the future we'd want to fuzzy match the room name, room ID, room members, etc against one or more of the keywords (rather than just a straight-up "contains keywords" conditional)