From: Alexis Laferrière Date: Sun, 25 Sep 2016 23:11:07 +0000 (-0400) Subject: benitlux: classify views in simple classes as variation points X-Git-Url: http://nitlanguage.org benitlux: classify views in simple classes as variation points Signed-off-by: Alexis Laferrière --- diff --git a/contrib/benitlux/src/client/base.nit b/contrib/benitlux/src/client/base.nit index 28b4c88..5be26b2 100644 --- a/contrib/benitlux/src/client/base.nit +++ b/contrib/benitlux/src/client/base.nit @@ -78,9 +78,16 @@ fun notify(title, content: Text, uniqueness_id: Int) do print "Notification {uniqueness_id}: {title}; {content}" # View for an item in a list, like a beer or a person -abstract class ItemView - super View -end +abstract class ItemView super View end + +# Descriptive label providing extra information +class DescLabel super Label end + +# `HorizontalLayout` header to a section +class SectionHeader super HorizontalLayout end + +# `Label` used in section headers +class SectionTitle super Label end # Basic async HTTP request for this app # diff --git a/contrib/benitlux/src/client/features/checkins.nit b/contrib/benitlux/src/client/features/checkins.nit index 6131d98..d353a0a 100644 --- a/contrib/benitlux/src/client/features/checkins.nit +++ b/contrib/benitlux/src/client/features/checkins.nit @@ -153,7 +153,8 @@ end redef class UserWindow - private var lbl_checkins_options_title = new Label(parent=layout, + private var header = new SectionHeader(parent=layout) + private var lbl_checkins_options_title = new SectionTitle(parent=header, text="Share options".t) private var chk_share_checkins = new CheckBox(parent=layout, @@ -162,7 +163,6 @@ redef class UserWindow init do chk_share_checkins.is_checked = app.share_checkins - lbl_checkins_options_title.size = 1.5 end redef fun on_event(event) diff --git a/contrib/benitlux/src/client/features/push.nit b/contrib/benitlux/src/client/features/push.nit index 62b8fc2..b5db81b 100644 --- a/contrib/benitlux/src/client/features/push.nit +++ b/contrib/benitlux/src/client/features/push.nit @@ -177,10 +177,12 @@ end redef class UserWindow - private var layout_push_options = new VerticalLayout(parent=layout) + private var header = new SectionHeader(parent=layout) + + private var lbl_push_options_title = new SectionTitle(parent=header, + text="Notifications options".t) - private var lbl_push_options_title = new Label(parent=layout_push_options, - text="Notifications options".t, size=1.5) + private var layout_push_options = new VerticalLayout(parent=layout) private var chk_notify_on_new_beers = new CheckBox(parent=layout_push_options, text="Notify when there are new beers".t) diff --git a/contrib/benitlux/src/client/views/beer_views.nit b/contrib/benitlux/src/client/views/beer_views.nit index 5b90bdc..95d2cf6 100644 --- a/contrib/benitlux/src/client/views/beer_views.nit +++ b/contrib/benitlux/src/client/views/beer_views.nit @@ -34,7 +34,7 @@ class BeerView var top_line_layout = new HorizontalLayout(parent=self) var lbl_name = new Label(parent=top_line_layout, text=beer_info.beer.name, size = 1.25) is lazy - var lbl_stats = new Label(parent=self, text=beer_info.rating_text, align=0.0, size=0.5) is lazy + var lbl_stats = new DescLabel(parent=self, text=beer_info.rating_text, size=0.5) is lazy var lbl_desc: Label is noinit var lbl_comment: nullable Label = null @@ -44,13 +44,13 @@ class BeerView var desc = beer_info.beer.desc if beer_info.is_new then desc += " (New)".t - lbl_desc = new Label(parent=self, text=desc, align=0.0) + lbl_desc = new DescLabel(parent=self, text=desc) lbl_stats var badges = beer_info.badges if badges != null then - var lbl_comment = new Label(parent=self, text=badges.join(" ")) + var lbl_comment = new DescLabel(parent=self, text=badges.join(" ")) lbl_comment.size = 0.5 self.lbl_comment = lbl_comment end diff --git a/contrib/benitlux/src/client/views/home_views.nit b/contrib/benitlux/src/client/views/home_views.nit index bd3f851..402c173 100644 --- a/contrib/benitlux/src/client/views/home_views.nit +++ b/contrib/benitlux/src/client/views/home_views.nit @@ -54,29 +54,29 @@ class HomeWindow # Cut-point for the iOS adaptation var layout_user = new VerticalLayout(parent=layout) - private var layout_login = new HorizontalLayout(parent=layout_user) + private var layout_login = new SectionHeader(parent=layout_user) private var but_preferences: nullable Button = null private var but_login: nullable Button = null private var layout_beers = new VerticalLayout(parent=layout) - var layout_beers_title = new HorizontalLayout(parent=layout_beers) + var layout_beers_title = new SectionHeader(parent=layout_beers) var title_beers = new SectionTitle(parent=layout_beers_title, text="Beer Menu".t, size=1.5) private var beer_button = new Button(parent=layout_beers_title, text="View all".t) private var beer_list = new VerticalLayout(parent=layout_beers) private var beer_temp_lbl = new Label(parent=beer_list, text="Loading...".t) private var layout_social = new VerticalLayout(parent=layout) - private var social_header = new HorizontalLayout(parent=layout_social) + private var social_header = new SectionHeader(parent=layout_social) private var social_title = new SectionTitle(parent=social_header, text="Friends".t, size=1.5) private var social_button = new Button(parent=social_header, text="Manage".t) private var social_list = new VerticalLayout(parent=layout_social) private var social_temp_lbl = new Label(parent=social_list, text="Loading...".t) private var layout_news = new VerticalLayout(parent=layout) - private var news_header = new HorizontalLayout(parent=layout_news) + var news_header = new SectionHeader(parent=layout_news) private var news_title = new SectionTitle(parent=news_header, text="Events".t, size=1.5) #private var news_button = new Button(parent=news_header, text="Open website") # TODO - private var news_label = new Label(parent=layout_news, text="Bière en cask le jeudi!") + private var news_cask = new EventView(parent=layout_news, text="Bière en cask le jeudi!") redef fun on_resume do refresh @@ -88,7 +88,7 @@ class HomeWindow layout_login.clear if app.user != null then # Logged in - var lbl_login_status = new Label(parent=layout_login, text="Welcome".t, size=1.5) + var lbl_login_status = new SectionTitle(parent=layout_login, text="Welcome".t, size=1.5) lbl_login_status.set_welcome else self.but_login = new Button(parent=layout_login, text="Login or signup".t) @@ -132,8 +132,15 @@ class HomeWindow end end -# `Label` used in section headers -class SectionTitle super Label end +private class EventView + super VerticalLayout + super ItemView + + var text: Text + + var lbl = new Label(parent=self, text=text) is lazy + init do lbl +end # Async request to update the beer list on the home screen class ListDiffAction diff --git a/contrib/benitlux/src/client/views/social_views.nit b/contrib/benitlux/src/client/views/social_views.nit index 1d4fa54..c95a806 100644 --- a/contrib/benitlux/src/client/views/social_views.nit +++ b/contrib/benitlux/src/client/views/social_views.nit @@ -27,7 +27,7 @@ class SocialWindow private var layout_header = new VerticalLayout(parent=list_search) private var layout_search = new HorizontalLayout(parent=layout_header) - private var txt_query = new TextInput(parent=layout_search) + var txt_query = new TextInput(parent=layout_search) private var but_search = new Button(parent=layout_search, text="Search".t) private var layout_list = new HorizontalLayout(parent=layout_header) @@ -110,7 +110,7 @@ class PeopleView var favs = if not user_and_following.favs.is_empty then "Favorites: %0".t.format(user_and_following.favs) else "No favorites yet".t - var lbl_desc = new Label(parent=self, text=favs, size=0.5) + var lbl_desc = new DescLabel(parent=self, text=favs, size=0.5) end end diff --git a/contrib/benitlux/src/client/views/user_views.nit b/contrib/benitlux/src/client/views/user_views.nit index ff5f31c..348243a 100644 --- a/contrib/benitlux/src/client/views/user_views.nit +++ b/contrib/benitlux/src/client/views/user_views.nit @@ -46,16 +46,16 @@ class UserWindow private var layout_user_options = new VerticalLayout(parent=layout) - private var lbl_user_options_title = new Label(parent=layout_user_options, + private var user_options_header = new SectionHeader(parent=layout_user_options) + private var lbl_user_options_title = new SectionTitle(parent=user_options_header, text="Account options".t) - private var lbl_welcome = new Label(parent=layout_user_options) + var lbl_welcome = new DescLabel(parent=layout_user_options) private var but_logout = new Button(parent=layout_user_options, text="Logout".t) # Refesh displayed text fun refresh do - lbl_user_options_title.size = 1.5 lbl_welcome.set_user_name but_logout.enabled = app.user != null end @@ -83,7 +83,7 @@ class SignupWindow super Window private var list = new ListLayout(parent=self) - private var lbl_feedback = new Label(parent=list, text="Welcome") + private var lbl_feedback = new DescLabel(parent=list, text="Welcome") private var layout_login = new VerticalLayout(parent=list) @@ -99,7 +99,7 @@ class SignupWindow private var pass_line = new HorizontalLayout(parent=layout_login) private var lbl_pass = new Label(parent=pass_line, text="Password".t) private var txt_pass = new TextInput(parent=pass_line, is_password=true) - private var lbl_pass_desc = new Label(parent=layout_login, size = 0.5, + private var lbl_pass_desc = new DescLabel(parent=layout_login, size = 0.5, text="Passwords must be composed of at least 6 characters.".t) private var but_login = new Button(parent=layout_login, text="Login".t) @@ -109,7 +109,7 @@ class SignupWindow private var layout_register = new VerticalLayout(parent=list) - private var lbl_signup_desc = new Label(parent=layout_register, size = 0.5, + private var lbl_signup_desc = new DescLabel(parent=layout_register, size = 0.5, text="Fill the following fields to sign up.".t) # Repeat password